Add NPC and Power-Up features with associated prefabs and effects

This commit is contained in:
2025-12-12 23:05:40 +01:00
parent 1cfcd09928
commit ee7a2fb4cb
24 changed files with 1051 additions and 5 deletions

View File

@@ -7,6 +7,8 @@ namespace Core.Domain
public class GameSession
{
private const string HighScoreKey = "HighScore";
private const float NpcSpawnTime = 4f;
private const float PowerUpSpawnInterval = 25f;
public int Score { get; private set; }
public int HighScore { get; private set; }
@@ -16,11 +18,16 @@ namespace Core.Domain
public event Action<string> OnOrbSpawned;
public event Action OnOrbReset;
public event Action OnGameOver;
public event Action OnSpawnNpc;
public event Action<PowerUpType, string> OnSpawnPowerUp;
private readonly List<Tile> _tiles;
private readonly IPersistenceService _persistenceService;
private readonly Random _rng = new();
private int _playerFloorIndex = 0;
private float _timeSinceStart;
private bool _npcSpawned;
private float _powerUpTimer;
public GameSession(List<Tile> tiles, IPersistenceService persistenceService)
{
@@ -35,9 +42,32 @@ namespace Core.Domain
public void StartGame()
{
_timeSinceStart = 0f;
_powerUpTimer = 0f;
_npcSpawned = false;
SpawnNextOrb();
}
public void Tick(float deltaTime)
{
if (IsGameOver) return;
_timeSinceStart += deltaTime;
if (!_npcSpawned && _timeSinceStart >= NpcSpawnTime)
{
_npcSpawned = true;
OnSpawnNpc?.Invoke();
}
_powerUpTimer += deltaTime;
if (_powerUpTimer >= PowerUpSpawnInterval)
{
_powerUpTimer = 0f;
SpawnRandomPowerUp();
}
}
public void OrbCollected()
{
if (IsGameOver) return;
@@ -95,5 +125,17 @@ namespace Core.Domain
OnOrbReset?.Invoke();
SpawnNextOrb();
}
private void SpawnRandomPowerUp()
{
var validTiles = _tiles.FindAll(t => t.CurrentState == TileState.Stable);
if (validTiles.Count == 0) return;
var tile = validTiles[_rng.Next(validTiles.Count)];
var type = _rng.Next(0, 2) == 0 ? PowerUpType.LightFooted : PowerUpType.SpeedBoost;
OnSpawnPowerUp?.Invoke(type, tile.Id);
}
}
}