Add NPC and Power-Up features with associated prefabs and effects
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user