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)
{

View file

@ -88,6 +88,7 @@ public class BulletInfo
public Vector2 Direction { get; set; }
public float Speed { get; set; }
public float LifeTime { get; set; }
public bool DestroyOnCollision { get; set; }
public BulletOwner Owner { get; set; }
public DamageType DamageType { get; set; }
public float Damage { get; set; }

View file

@ -251,7 +251,7 @@ public partial class Enemy : CharacterBody2D
if (bullet.BulletInfo.Owner == BulletOwner.Enemy) return;
this.Hit(bullet.Damage);
bullet.QueueFree();
bullet.RequestCollisionDestruction();
}
// Bullets collision

View file

@ -442,7 +442,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
if (area is Bullet bullet && bullet.BulletOwner != BulletGroup)
{
this.Hit(bullet.Damage, bullet.DamageType);
bullet.QueueFree();
bullet.RequestCollisionDestruction();
}
}

View file

@ -15,6 +15,7 @@ public partial class BulletResource : Resource
[Export] public float BulletSpeed = 100f;
[Export] public float BulletDamage = 1;
[Export] public float LifeTime = 10f;
[Export] public bool DestroyOnCollision = true;
[Export] public BulletOwner Owner = BulletOwner.None;
[Export] public DamageType DamageType = DamageType.Neutral;
@ -38,6 +39,7 @@ public partial class BulletResource : Resource
RotationOffset = rotationOffset,
Modifier = Modifier,
LifeTime = LifeTime,
DestroyOnCollision = DestroyOnCollision,
DestructionParticlesScene = DestructionParticlesScene,
TimeModifiers = TimeModifiers.Select(x => x).ToList()
// TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().Select(m => new ModifierWrapper()