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

View File

@@ -0,0 +1,8 @@
namespace Core.Domain
{
public enum PowerUpType
{
LightFooted,
SpeedBoost,
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bafe72a0931b403fbd668163287d60a3
timeCreated: 1765576209

View File

@@ -0,0 +1,10 @@
using UnityEngine;
namespace Core.Domain.Status.Effects
{
public struct EffectColors
{
public static readonly Color LightFootedColor = new Color(0.8f, 0.8f, 0.8f);
public static readonly Color SpeedBoostColor = new Color(1f, 0.5f, 0f);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ca5a45bf5f154f009511ace70bfc78aa
timeCreated: 1765576663

View File

@@ -0,0 +1,29 @@
namespace Core.Domain.Status.Effects
{
public class SpeedBoostEffect : IStatusEffect
{
private float _duration;
private readonly float _multiplier;
public bool IsExpired => _duration <= 0;
public SpeedBoostEffect(float duration, float multiplier = 1.5f)
{
_duration = duration;
_multiplier = multiplier;
}
public void Tick(float deltaTime)
{
_duration -= deltaTime;
}
public void ModifyCapabilities(ref PlayerCapabilities caps)
{
caps.SpeedMultiplier = _multiplier;
}
public void OnApply() { }
public void OnRemove() { }
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8fdc1e67835247f6a2afc26cc4ed27a8
timeCreated: 1765576232