Spawn timer for bad ending
This commit is contained in:
@@ -14,6 +14,7 @@ public partial class BadEnd : SpecialFloor
|
||||
[Dependency] protected IGame _game => this.DependOn<IGame>();
|
||||
|
||||
[Export] public float ShakeAmount = 50;
|
||||
[Export] public int SpawnTimer = 5;
|
||||
|
||||
[Node] public Node3D EnemySpawnPoints { get; set; } = default!;
|
||||
|
||||
@@ -21,9 +22,18 @@ public partial class BadEnd : SpecialFloor
|
||||
|
||||
[Node] public ShakeCamera Camera3D { get; set; } = default!;
|
||||
|
||||
private Timer _spawnTimer;
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
SpawnEnemies();
|
||||
SpawnEnemies(10);
|
||||
_spawnTimer = new Timer
|
||||
{
|
||||
WaitTime = SpawnTimer
|
||||
};
|
||||
_spawnTimer.Timeout += SpawnTimer_Timeout;
|
||||
AddChild(_spawnTimer);
|
||||
_spawnTimer.Start();
|
||||
var tweener = GetTree().CreateTween();
|
||||
tweener.TweenMethod(Callable.From((float x) => SetShakeValue(x)), ShakeAmount, 1f, 700f).SetDelay(30);
|
||||
}
|
||||
@@ -31,6 +41,7 @@ public partial class BadEnd : SpecialFloor
|
||||
public async void StartEndGameCutscene()
|
||||
{
|
||||
_player.Deactivate();
|
||||
_spawnTimer.Stop();
|
||||
_player.ShowCamera(false);
|
||||
Camera3D.Current = true;
|
||||
await _game.OnReachBadEnd();
|
||||
@@ -47,11 +58,13 @@ public partial class BadEnd : SpecialFloor
|
||||
_player.ShakePlayerCamera(shakeAmount, 1f);
|
||||
}
|
||||
|
||||
public void SpawnEnemies()
|
||||
public void SpawnEnemies(int numberOfEnemies)
|
||||
{
|
||||
var enemySpawnPoints = EnemySpawnPoints.GetChildren().OfType<Marker3D>();
|
||||
foreach (var spawnPoint in enemySpawnPoints)
|
||||
Godot.Collections.Array<Marker3D> enemySpawnPoints = [.. EnemySpawnPoints.GetChildren().OfType<Marker3D>()];
|
||||
for (var i = 0; i < numberOfEnemies; i++)
|
||||
{
|
||||
var spawnPoint = enemySpawnPoints.PickRandom();
|
||||
enemySpawnPoints.Remove(spawnPoint);
|
||||
var instantiatedEnemy = EnemyTypeToEnemyConverter.Convert(EnemyType.Michael);
|
||||
AddChild(instantiatedEnemy);
|
||||
instantiatedEnemy.GlobalPosition = new Vector3(spawnPoint.GlobalPosition.X, 2.4f, spawnPoint.GlobalPosition.Z);
|
||||
@@ -61,5 +74,12 @@ public partial class BadEnd : SpecialFloor
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnTimer_Timeout() => SpawnEnemies(3);
|
||||
|
||||
public override (Vector3 Rotation, Vector3 Position) GetPlayerSpawnPoint() { return (PlayerSpawnPoint.Rotation, new Vector3(PlayerSpawnPoint.GlobalPosition.X, 2.4f, PlayerSpawnPoint.GlobalPosition.Z)); }
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
_spawnTimer.Timeout -= SpawnTimer_Timeout;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user