mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-10 18:45:53 +00:00
Death animations and spawner
This commit is contained in:
parent
4fd31d7988
commit
16b7d936c9
13 changed files with 286 additions and 11 deletions
|
|
@ -15,6 +15,9 @@ public partial class Actor : CharacterBody2D
|
|||
private GameManager _gameManager;
|
||||
|
||||
private List<ActorModule> _modules = new();
|
||||
|
||||
[Signal]
|
||||
public delegate void OnDeathEventHandler();
|
||||
|
||||
public bool IsDestroyed { get; set; }
|
||||
|
||||
|
|
@ -47,4 +50,9 @@ public partial class Actor : CharacterBody2D
|
|||
}
|
||||
}
|
||||
|
||||
public void TriggerDeath()
|
||||
{
|
||||
EmitSignal(SignalName.OnDeath);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ public partial class AnimationHandler : ActorModule
|
|||
public override void Init(Actor parent)
|
||||
{
|
||||
_parent = parent;
|
||||
|
||||
_parent.OnDeath += ParentOnOnDeath;
|
||||
// var children = GetChildren();
|
||||
// foreach (var child in children) {
|
||||
// if (child is InputProvider inputProvider)
|
||||
|
|
@ -25,6 +25,12 @@ public partial class AnimationHandler : ActorModule
|
|||
// }
|
||||
}
|
||||
|
||||
protected virtual void ParentOnOnDeath()
|
||||
{
|
||||
_animatedSprite.SpeedScale = 0;
|
||||
_animatedSprite.Hide();
|
||||
}
|
||||
|
||||
public override void Update(double delta)
|
||||
{
|
||||
if (IsDestroyed) return;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ public partial class DamageReceiverActorModule : ActorModule
|
|||
{
|
||||
_actor = actor;
|
||||
|
||||
HealthProvider.FillResource();
|
||||
HealthProvider.ResourceDepleted += OnDeath;
|
||||
}
|
||||
|
||||
|
|
@ -61,6 +62,6 @@ public partial class DamageReceiverActorModule : ActorModule
|
|||
protected void OnDeath()
|
||||
{
|
||||
_actor.IsDestroyed = true;
|
||||
GD.Print("Actor dead");
|
||||
_actor.TriggerDeath();
|
||||
}
|
||||
}
|
||||
65
Scripts/Components/Actors/DeathAnimationHandler.cs
Normal file
65
Scripts/Components/Actors/DeathAnimationHandler.cs
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class DeathAnimationHandler : ActorModule
|
||||
{
|
||||
protected Actor _actor;
|
||||
|
||||
[Export] public BulletResource ExplosionData { get; set; }
|
||||
[Export] public PackedScene ExplosionParticles { get; set; }
|
||||
[Export] public PackedScene DebrisScene { get; set; }
|
||||
|
||||
public override void Init(Actor actor)
|
||||
{
|
||||
_actor = actor;
|
||||
_actor.OnDeath += ParentOnOnDeath;
|
||||
}
|
||||
|
||||
protected virtual void ParentOnOnDeath()
|
||||
{
|
||||
CreateExplosion();
|
||||
CreateParticles();
|
||||
CreateDebris();
|
||||
|
||||
_actor.QueueFree();
|
||||
}
|
||||
|
||||
public override void Update(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsUpdate(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void CreateExplosion()
|
||||
{
|
||||
if (ExplosionData == null) return;
|
||||
|
||||
var explosion = _actor.CreateSibling<Bullet>(ExplosionData.BulletScene);
|
||||
explosion.Speed = 0;
|
||||
|
||||
explosion.Initialize(ExplosionData.MakeBullet(_actor.GlobalPosition), GameManager.Instance);
|
||||
}
|
||||
|
||||
private void CreateParticles()
|
||||
{
|
||||
if (ExplosionParticles == null) {
|
||||
return;
|
||||
}
|
||||
var particle = _actor.CreateSibling<GpuParticles2D>(ExplosionParticles);
|
||||
if (particle == null) return;
|
||||
|
||||
particle.Emitting = true;
|
||||
}
|
||||
|
||||
private void CreateDebris()
|
||||
{
|
||||
if (DebrisScene == null) return;
|
||||
_actor.CreateSibling<Barrel>(DebrisScene);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue