Explosions

This commit is contained in:
MaddoScientisto 2024-06-09 11:45:22 +02:00
commit e1d6afa512
21 changed files with 323 additions and 24 deletions

View file

@ -4,12 +4,13 @@ using System.Diagnostics;
public partial class Barrel : Area2D, IDestructible
{
[Export] public float Health = 1f;
[Export]
public float Health = 1f;
[Export] public float ExplosionRadius = 1;
[Export]
public float ExplosionRadius = 1;
[Export] public float ExplosionDamage = 1;
[Export] public PackedScene DebrisScene { get; set; }
private float _currentHealth;
@ -26,23 +27,34 @@ public partial class Barrel : Area2D, IDestructible
{
}
public void Explode() {
private void Explode()
{
Debug.WriteLine("Boom");
CreateDebris();
QueueFree();
}
private void CreateDebris()
{
if (DebrisScene == null) return;
var debris = DebrisScene.Instantiate<Barrel>();
Owner.AddChild(debris);
debris.Transform = this.GlobalTransform;
debris.Position = this.Position;
}
public void Hit(float damage)
{
if (_isDestroyed) return;
_currentHealth -= damage;
if (!(_currentHealth <= 0)) return;
_isDestroyed = true;
Explode();
// TODO: Change sprite
}
public bool IsDestroyed()
{
return _isDestroyed;
}
}