Enemy and nest

This commit is contained in:
2025-08-30 02:06:58 +08:00
parent 630dbf0800
commit 32f96d488d
12 changed files with 327 additions and 10 deletions

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