mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:05:34 +00:00
Death animations and spawner
This commit is contained in:
parent
4fd31d7988
commit
16b7d936c9
13 changed files with 286 additions and 11 deletions
|
|
@ -131,8 +131,8 @@ public partial class Teleporter : Activable
|
|||
|
||||
await TweenPlayer(player);
|
||||
|
||||
|
||||
_particles.Emitting = true;
|
||||
//_particles.Emitting = true;
|
||||
FireParticles();
|
||||
|
||||
await player.Teleport();
|
||||
|
||||
|
|
|
|||
31
Scripts/Actors/ActorSpawner.cs
Normal file
31
Scripts/Actors/ActorSpawner.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Actors;
|
||||
|
||||
public partial class ActorSpawner : Node2D, IActivable
|
||||
{
|
||||
[Export]
|
||||
public PackedScene ActorPrefab { get; set; }
|
||||
|
||||
[Export] public bool WaitForActorDeath { get; private set; } = true;
|
||||
|
||||
public Actor SpawnedActor { get; private set; }
|
||||
|
||||
public virtual void Spawn()
|
||||
{
|
||||
SpawnedActor = this.CreateSibling<Actor>(ActorPrefab);
|
||||
}
|
||||
|
||||
public void Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
if (!WaitForActorDeath)
|
||||
{
|
||||
Spawn();
|
||||
}
|
||||
else if (SpawnedActor == null)
|
||||
{
|
||||
Spawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
28
Scripts/Actors/AlarmTeleporterActorSpawner.cs
Normal file
28
Scripts/Actors/AlarmTeleporterActorSpawner.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using Cirno.Scripts.Activables;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Actors;
|
||||
|
||||
public partial class AlarmTeleporterActorSpawner : ActorSpawner
|
||||
{
|
||||
private AlarmManager _alarmManager;
|
||||
|
||||
[Export]
|
||||
public Teleporter Teleporter { get; private set; }
|
||||
|
||||
[Export]
|
||||
public float ActivationRange { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_alarmManager = this.GetAlarmManager();
|
||||
_alarmManager.AlarmEnabled += AlarmManagerOnAlarmEnabled;
|
||||
}
|
||||
|
||||
private void AlarmManagerOnAlarmEnabled(Vector2 location)
|
||||
{
|
||||
if (!(location.DistanceTo(this.GlobalPosition) <= ActivationRange)) return;
|
||||
Teleporter?.FireParticles();
|
||||
Spawn();
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
32
Scripts/Resources/Events/AlarmEnableEvent.cs
Normal file
32
Scripts/Resources/Events/AlarmEnableEvent.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Resources.Events;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class AlarmEnableEvent : EventResource
|
||||
{
|
||||
private bool _isComplete = false;
|
||||
private AlarmManager _alarmManager;
|
||||
|
||||
public override bool IsComplete()
|
||||
{
|
||||
return _isComplete;
|
||||
}
|
||||
|
||||
public override void Init(Node2D parent)
|
||||
{
|
||||
_alarmManager = parent.GetAlarmManager();
|
||||
}
|
||||
|
||||
public override void Start(Node2D parent)
|
||||
{
|
||||
_alarmManager.SoundAlarm(parent.GlobalPosition);
|
||||
_isComplete = true;
|
||||
}
|
||||
|
||||
public override void UpdateEvent(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue