✨ Enemy and nest
This commit is contained in:
35
Scripts/Tiles/EnemyNestTile.cs
Normal file
35
Scripts/Tiles/EnemyNestTile.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Godot;
|
||||
|
||||
namespace AceFieldNewHorizon.Scripts.Tiles;
|
||||
|
||||
public partial class EnemyNestTile : BaseTile
|
||||
{
|
||||
[Export] public PackedScene EnemyScene;
|
||||
private Timer _spawnTimer;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
|
||||
// Create and configure the timer
|
||||
_spawnTimer = new Timer();
|
||||
AddChild(_spawnTimer);
|
||||
_spawnTimer.Timeout += OnSpawnTimerTimeout;
|
||||
_spawnTimer.Start(1.0f); // Start with 1 second interval
|
||||
}
|
||||
|
||||
private void OnSpawnTimerTimeout()
|
||||
{
|
||||
if (EnemyScene != null)
|
||||
{
|
||||
var enemy = EnemyScene.Instantiate();
|
||||
GetParent().AddChild(enemy);
|
||||
|
||||
// Position the enemy at the nest's position
|
||||
if (enemy is Node2D enemy2D)
|
||||
{
|
||||
enemy2D.GlobalPosition = GlobalPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user