mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Actor defeat script
This commit is contained in:
parent
16b7d936c9
commit
d49f5e2a45
4 changed files with 63 additions and 3 deletions
|
|
@ -9,6 +9,11 @@ public partial class Actor : CharacterBody2D
|
|||
[Export]
|
||||
public float MovementSpeed { get; private set; }
|
||||
|
||||
[ExportCategory("Defeat Script")]
|
||||
[Export] public Node2D DefeatScript { get; set; }
|
||||
|
||||
[Export] public ActivationType ActivationType { get; private set; } = ActivationType.Toggle;
|
||||
|
||||
public Vector2 MovementDirection { get; set; }
|
||||
public Vector2 FacingDirection { get; set; }
|
||||
|
||||
|
|
|
|||
46
Scripts/Components/Actors/ActorDefeatScriptHandler.cs
Normal file
46
Scripts/Components/Actors/ActorDefeatScriptHandler.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class ActorDefeatScriptHandler : ActorModule
|
||||
{
|
||||
[Export] public Node2D DefeatScript { get; private set; }
|
||||
[Export] public ActivationType ActivationType { get; private set; }
|
||||
protected Actor _actor;
|
||||
|
||||
public override void Init(Actor actor)
|
||||
{
|
||||
_actor = actor;
|
||||
DefeatScript = actor.DefeatScript;
|
||||
ActivationType = actor.ActivationType;
|
||||
_actor.OnDeath += ActorOnOnDeath;
|
||||
}
|
||||
|
||||
private void ActorOnOnDeath()
|
||||
{
|
||||
ActivateDefeatScript();
|
||||
}
|
||||
|
||||
public override void Update(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsUpdate(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected void ActivateDefeatScript()
|
||||
{
|
||||
if (DefeatScript is not IActivable target)
|
||||
{
|
||||
GD.PrintErr($"Target {DefeatScript.Name} is not activable");
|
||||
return;
|
||||
}
|
||||
|
||||
target?.Activate();
|
||||
|
||||
GD.Print($"{DefeatScript.Name} activated");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue