Add initial game systems and input handling for player interactions

This commit is contained in:
2025-12-09 22:20:38 +01:00
commit 5e0db113aa
182 changed files with 70557 additions and 0 deletions

View 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;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 694c3777489643ee843bf35f734ac060
timeCreated: 1765312961

View 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;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 99a4c19937ce4a97881d2796dead20d4
timeCreated: 1765313464

View 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;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9724125bb1674f2e9f8150c290b71d1a
timeCreated: 1765312906

View 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;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 81bda016e43341779a714e971304d37d
timeCreated: 1765313331