Explosion sprites and lifetime

This commit is contained in:
Marco 2025-02-20 12:17:21 +01:00
commit a0b5cedff9
10 changed files with 102 additions and 18 deletions

View file

@ -34,14 +34,15 @@ public partial class Bullet : Area2D
_gameManager = gameManager;
_elapsedTime = 0f;
// Need to clone them here
// _modifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone()).ToList();
// var clonedModifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone());
// _modifiers = clonedModifiers.ToList();
// Ugly hack to make instances unique
_modifiers = _bulletInfo.TimeModifiers.Select(x => x.Wrap()).ToList();
}
@ -136,6 +137,11 @@ public partial class Bullet : Area2D
public override void _Process(double delta)
{
_elapsedTime += delta;
if (_elapsedTime >= _bulletInfo.LifeTime)
{
Destroy();
}
}
public override void _PhysicsProcess(double delta)
@ -159,7 +165,7 @@ public partial class Bullet : Area2D
if (body.IsInGroup("Solid"))
{
//Debug.WriteLine("Collision");
Destroy();
RequestCollisionDestruction();
}
//// Do not Collide with body for purpose of destroying bullets
// else if (body.IsInGroup("Destroyable"))
@ -173,7 +179,7 @@ public partial class Bullet : Area2D
{
if (area.IsInGroup("Solid"))
{
Destroy();
RequestCollisionDestruction();
return;
}
@ -183,7 +189,7 @@ public partial class Bullet : Area2D
// hit
destructible.Hit(Damage, DamageType);
Destroy();
RequestCollisionDestruction();
}
}
@ -199,8 +205,15 @@ public partial class Bullet : Area2D
return bulletOwner != targetGroup;
}
public void RequestCollisionDestruction()
{
if (_bulletInfo.DestroyOnCollision)
{
Destroy();
}
}
public void Destroy()
private void Destroy()
{
if (_bulletInfo?.DestructionParticlesScene != null)
{