Add initial game systems and input handling for player interactions
This commit is contained in:
35
Assets/Scripts/Core/Systems/LivesSystem.cs
Normal file
35
Assets/Scripts/Core/Systems/LivesSystem.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
|
||||
namespace Core.Systems
|
||||
{
|
||||
public class LivesSystem : IDisposable
|
||||
{
|
||||
private int _currentLives;
|
||||
|
||||
public LivesSystem(int initialLives)
|
||||
{
|
||||
_currentLives = initialLives;
|
||||
GameEvents.PresentDropped += OnPresentDropped;
|
||||
|
||||
GameEvents.ReportLivesUpdated(_currentLives);
|
||||
}
|
||||
|
||||
private void OnPresentDropped()
|
||||
{
|
||||
if (_currentLives <= 0) return;
|
||||
|
||||
_currentLives--;
|
||||
GameEvents.ReportLivesUpdated(_currentLives);
|
||||
|
||||
if (_currentLives <= 0)
|
||||
{
|
||||
GameEvents.ReportGameOver();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GameEvents.PresentDropped -= OnPresentDropped;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Core/Systems/LivesSystem.cs.meta
Normal file
3
Assets/Scripts/Core/Systems/LivesSystem.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 694c3777489643ee843bf35f734ac060
|
||||
timeCreated: 1765312961
|
||||
46
Assets/Scripts/Core/Systems/PersistenceSystem.cs
Normal file
46
Assets/Scripts/Core/Systems/PersistenceSystem.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using Infrastructure;
|
||||
|
||||
namespace Core.Systems
|
||||
{
|
||||
public class PersistenceSystem : IDisposable
|
||||
{
|
||||
private readonly IPersistenceService _service;
|
||||
private readonly string _saveKey;
|
||||
private int _currentRunScore;
|
||||
|
||||
public PersistenceSystem(IPersistenceService service, string saveKey)
|
||||
{
|
||||
_service = service;
|
||||
_saveKey = saveKey;
|
||||
|
||||
GameEvents.ScoreUpdated += OnScoreUpdated;
|
||||
GameEvents.GameOver += OnGameOver;
|
||||
}
|
||||
|
||||
public int GetHighScore()
|
||||
{
|
||||
return _service.LoadHighScore(_saveKey);
|
||||
}
|
||||
|
||||
private void OnGameOver()
|
||||
{
|
||||
var existingHighScore = _service.LoadHighScore(_saveKey);
|
||||
if (_currentRunScore > existingHighScore)
|
||||
{
|
||||
_service.SaveHighScore(_saveKey, _currentRunScore);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnScoreUpdated(int newScore)
|
||||
{
|
||||
_currentRunScore = newScore;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GameEvents.ScoreUpdated -= OnScoreUpdated;
|
||||
GameEvents.GameOver -= OnGameOver;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Core/Systems/PersistenceSystem.cs.meta
Normal file
3
Assets/Scripts/Core/Systems/PersistenceSystem.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99a4c19937ce4a97881d2796dead20d4
|
||||
timeCreated: 1765313464
|
||||
26
Assets/Scripts/Core/Systems/ScoreSystem.cs
Normal file
26
Assets/Scripts/Core/Systems/ScoreSystem.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace Core.Systems
|
||||
{
|
||||
public class ScoreSystem : IDisposable
|
||||
{
|
||||
private int _currentScore;
|
||||
|
||||
public ScoreSystem()
|
||||
{
|
||||
_currentScore = 0;
|
||||
GameEvents.PresentCaught += OnPresentCaught;
|
||||
}
|
||||
|
||||
private void OnPresentCaught(int value)
|
||||
{
|
||||
_currentScore += value;
|
||||
GameEvents.ReportScoreUpdated(_currentScore);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GameEvents.PresentCaught -= OnPresentCaught;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Core/Systems/ScoreSystem.cs.meta
Normal file
3
Assets/Scripts/Core/Systems/ScoreSystem.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9724125bb1674f2e9f8150c290b71d1a
|
||||
timeCreated: 1765312906
|
||||
51
Assets/Scripts/Core/Systems/TimeAttackSystem.cs
Normal file
51
Assets/Scripts/Core/Systems/TimeAttackSystem.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
|
||||
namespace Core.Systems
|
||||
{
|
||||
public class TimeAttackSystem : IDisposable
|
||||
{
|
||||
private float _timeRemaining;
|
||||
private readonly float _penaltyPerDrop;
|
||||
|
||||
public TimeAttackSystem(float initialTime, float penaltyPerDrop = 5f)
|
||||
{
|
||||
_timeRemaining = initialTime;
|
||||
_penaltyPerDrop = penaltyPerDrop;
|
||||
|
||||
GameEvents.ReportTimeUpdated(_timeRemaining);
|
||||
|
||||
GameEvents.PresentDropped += OnPresentDropped;
|
||||
}
|
||||
|
||||
public void Tick(float deltaTime)
|
||||
{
|
||||
if (_timeRemaining <= 0) return;
|
||||
|
||||
_timeRemaining -= deltaTime;
|
||||
|
||||
if (_timeRemaining <= 0)
|
||||
{
|
||||
_timeRemaining = 0;
|
||||
GameEvents.ReportTimeUpdated(0f);
|
||||
GameEvents.ReportGameOver();
|
||||
}
|
||||
else
|
||||
{
|
||||
GameEvents.ReportTimeUpdated(_timeRemaining);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPresentDropped()
|
||||
{
|
||||
if (_timeRemaining > 0)
|
||||
{
|
||||
_timeRemaining -= _penaltyPerDrop;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GameEvents.PresentDropped -= OnPresentDropped;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Core/Systems/TimeAttackSystem.cs.meta
Normal file
3
Assets/Scripts/Core/Systems/TimeAttackSystem.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81bda016e43341779a714e971304d37d
|
||||
timeCreated: 1765313331
|
||||
Reference in New Issue
Block a user