First builds and stuff done yipewaho

This commit is contained in:
2026-02-01 05:32:22 +02:00
parent 12c1360ae7
commit d910018b7b
62 changed files with 1886 additions and 37 deletions
+13 -1
View File
@@ -5,14 +5,21 @@ public partial class Enemy : PathFollow2D
{
[Export] public EnemyType Type;
[Export] public Health Health;
[Export] private AudioStreamPlayer2D _audio;
public event Action<Enemy> Died;
public event Action<Enemy> ReachedShrine;
public override void _Ready()
{
Health.Death += _ => Died?.Invoke(this);
Health.Damaged += () =>
{
_audio?.SetPitchScale(RandomHelper.Float(0.8f, 1.2f));
_audio?.Play();
};
}
public void ResetEnemy()
{
GlobalPosition = Vector2.Zero;
@@ -23,4 +30,9 @@ public partial class Enemy : PathFollow2D
Health.Reset();
// reset velocity, animation, AI, etc here
}
public void Despawn()
{
ReachedShrine?.Invoke(this);
}
}
+9 -1
View File
@@ -3,9 +3,12 @@ using System;
public partial class EnemyMovement : Node
{
[Export] private Enemy _enemy;
[Export] private PathFollow2D _pathFollow2D;
[Export] private float _speed;
private float _finalSpeed => _speed + 0.15f * (float)Math.Log(GameController.Instance.Wave + 1);
private double _time = 0;
public override void _EnterTree()
@@ -15,6 +18,11 @@ public partial class EnemyMovement : Node
public override void _Process(double delta)
{
_pathFollow2D.ProgressRatio += (float)delta * (_speed / 1000f);
_pathFollow2D.ProgressRatio += (float)delta * (_finalSpeed / 1000f);
if (_pathFollow2D.ProgressRatio >= 1.0)
{
_enemy.Despawn();
}
}
}
+19 -1
View File
@@ -30,7 +30,8 @@ public partial class EnemyPool : Node
private Enemy CreateEnemy(EnemyType type)
{
var e = _scenes[type].Instantiate<Enemy>();
e.Died += ReturnToPool;
e.Died += Died;
e.ReachedShrine += DamageShrine;
return e;
}
@@ -44,8 +45,25 @@ public partial class EnemyPool : Node
return e;
}
private void DamageShrine(Enemy e)
{
GameController.Instance.DamageShrine(5);
ReturnToPool(e);
}
private void Died(Enemy e)
{
GameController.Instance.AddCurrency(25);
ReturnToPool(e);
}
private void ReturnToPool(Enemy e)
{
EnemySpawner.Instance.EnemiesSpawned--;
if (EnemySpawner.Instance.EnemiesSpawned <= 0)
{
GameController.Instance.WaveComplete();
}
e.GetParent()?.RemoveChild(e);
e.ProcessMode = ProcessModeEnum.Disabled;
_pool[e.Type].Enqueue(e);
+9 -3
View File
@@ -3,22 +3,28 @@ using System.Collections.Generic;
public partial class EnemySpawner : Node
{
public static EnemySpawner Instance;
[Export] private Node _pathParent;
[Export] private EnemyPool _pool;
private readonly List<Path2D> _paths = new();
public int EnemiesSpawned = 0;
public override void _Ready()
{
Instance = this;
foreach (var c in _pathParent.GetChildren())
if (c is Path2D p)
_paths.Add(p);
for (int i = 0; i < 10; i++)
SpawnWithDelay(i * 0.33f);
// for (int i = 0; i < 10; i++)
// SpawnWithDelay(i * 0.33f);
}
private async void SpawnWithDelay(float t)
public async void SpawnWithDelay(float t)
{
await ToSignal(GetTree().CreateTimer(t), SceneTreeTimer.SignalName.Timeout);
Spawn();