From b524f97e7f1b09b4179bd12e5dff4aeb0c8ca4b3 Mon Sep 17 00:00:00 2001 From: Rendo Date: Sat, 12 Jul 2025 00:15:17 +0500 Subject: [PATCH] Zombie death and damage indicators --- .../animations/zombies/basic_zombie_tree.tres | 10 +- resources/animations/zombies/hobo_zombie.res | Bin 12589 -> 12589 bytes resources/effects/SnowSlow.tres | 2 +- scenes/entities/Zombies/bucket_zombie.tscn | 82 ++++++-- scenes/entities/Zombies/cone_zombie.tscn | 73 ++++--- scenes/entities/Zombies/zombie.tscn | 197 +++++++++++++----- scenes/prototype_survival.tscn | 4 +- scripts/Entity.cs | 2 +- scripts/EntityHPObserver.cs | 32 +++ scripts/EntityHPObserver.cs.uid | 1 + scripts/ZombieKillHandler.cs | 24 +++ scripts/ZombieKillHandler.cs.uid | 1 + scripts/particles/FallParticle.cs | 8 +- scripts/zombies/RuntimeZombieData.cs | 5 + 14 files changed, 324 insertions(+), 117 deletions(-) create mode 100644 scripts/EntityHPObserver.cs create mode 100644 scripts/EntityHPObserver.cs.uid create mode 100644 scripts/ZombieKillHandler.cs create mode 100644 scripts/ZombieKillHandler.cs.uid diff --git a/resources/animations/zombies/basic_zombie_tree.tres b/resources/animations/zombies/basic_zombie_tree.tres index 26e010d..2deba5a 100644 --- a/resources/animations/zombies/basic_zombie_tree.tres +++ b/resources/animations/zombies/basic_zombie_tree.tres @@ -1,5 +1,8 @@ [gd_resource type="AnimationNodeStateMachine" load_steps=10 format=3 uid="uid://dj0blope85bg7"] +[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_w2cv7"] +animation = &"dead_lmao" + [sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_h0rfo"] animation = &"basic_zombie_eating" @@ -9,9 +12,6 @@ animation = &"basic_zombie_stand" [sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_g2uel"] animation = &"basic_zombie_walk" -[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_w2cv7"] -animation = &"dead_lmao" - [sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_vxhht"] advance_mode = 2 @@ -40,6 +40,8 @@ advance_mode = 2 advance_expression = "get(\"isEating\") == false" [resource] +states/Death/node = SubResource("AnimationNodeAnimation_w2cv7") +states/Death/position = Vector2(778, 100) states/End/position = Vector2(977, 90) states/basic_zombie_eat/node = SubResource("AnimationNodeAnimation_h0rfo") states/basic_zombie_eat/position = Vector2(575, 185) @@ -47,7 +49,5 @@ states/basic_zombie_idle/node = SubResource("AnimationNodeAnimation_nog33") states/basic_zombie_idle/position = Vector2(366, 100) states/basic_zombie_walk/node = SubResource("AnimationNodeAnimation_g2uel") states/basic_zombie_walk/position = Vector2(575, 35) -states/dead_lmao/node = SubResource("AnimationNodeAnimation_w2cv7") -states/dead_lmao/position = Vector2(778, 100) transitions = ["Start", "basic_zombie_idle", SubResource("AnimationNodeStateMachineTransition_vxhht"), "basic_zombie_idle", "basic_zombie_walk", SubResource("AnimationNodeStateMachineTransition_r8rju"), "basic_zombie_idle", "basic_zombie_eat", SubResource("AnimationNodeStateMachineTransition_y2ivb"), "basic_zombie_walk", "basic_zombie_eat", SubResource("AnimationNodeStateMachineTransition_7d3k4"), "basic_zombie_eat", "basic_zombie_walk", SubResource("AnimationNodeStateMachineTransition_kk4wi")] graph_offset = Vector2(-7, -20) diff --git a/resources/animations/zombies/hobo_zombie.res b/resources/animations/zombies/hobo_zombie.res index d09abfab3cfbeff47494972a6746fea807313f4d..4bfc0b8ff7b7cbf3fd774adb41e031bfc0902118 100644 GIT binary patch delta 112 zcmV-$0FVEzVy$AZ;3o-L&B2XQC4z-Ov*{-|0RfDYA}P56inH7)@B%p@bdS!itH^X+ z#immZ1>4muk7i`&_dkN&=U_53s{W!yk5^WB(+m9$6z=`VWpHVeXxrB2W7{+Zvjr`O S0SFo$svrS^lLNDqE|~(fh%<@+ delta 112 zcmV-$0FVEzVy$AZ;3o+X4(3yjv4X`xv*{-|0Rf7WA}P56jI-P+@B%pjcaP4ltH^X+ z#imp4W!*Lu=WsT{|9s|R_Bql!n3?;d$15wm>4km=3ip2GGPtx!v~6qiv2B_Hvjr`O S0SE;;Gy#GGCp5E^E|~)8gEP _threshold) + { + EmitSignal(SignalName.ThresholdReached); + _observedEntity.OnHPChanged -= OnHPChanged; + QueueFree(); + } + } +} diff --git a/scripts/EntityHPObserver.cs.uid b/scripts/EntityHPObserver.cs.uid new file mode 100644 index 0000000..11c1d76 --- /dev/null +++ b/scripts/EntityHPObserver.cs.uid @@ -0,0 +1 @@ +uid://dau0tfmlfiqmo diff --git a/scripts/ZombieKillHandler.cs b/scripts/ZombieKillHandler.cs new file mode 100644 index 0000000..a0c2351 --- /dev/null +++ b/scripts/ZombieKillHandler.cs @@ -0,0 +1,24 @@ +using Godot; +using Newlon.Components.Zombies; + +public partial class ZombieKillHandler : Node +{ + [Export] private AnimationTree _tree; + [Export] private CollisionShape2D _collider; + private void OnKilled(RuntimeZombieData who) + { + var tween = CreateTween(); + tween.TweenInterval(4.0); + tween.TweenCallback(Callable.From(() => + { + ((AnimationNodeStateMachinePlayback)_tree.Get("parameters/Tree/playback")).Travel("Death"); + _collider.Disabled = true; + })); + tween.TweenInterval(3.0); + tween.TweenProperty(who, "modulate",new Color(1, 1, 1, 0),1.0); + tween.TweenCallback(Callable.From(() => + { + who.Kill(); + })); + } +} diff --git a/scripts/ZombieKillHandler.cs.uid b/scripts/ZombieKillHandler.cs.uid new file mode 100644 index 0000000..a47f9b0 --- /dev/null +++ b/scripts/ZombieKillHandler.cs.uid @@ -0,0 +1 @@ +uid://dk32ln8c2574d diff --git a/scripts/particles/FallParticle.cs b/scripts/particles/FallParticle.cs index 860afd6..0c71d23 100644 --- a/scripts/particles/FallParticle.cs +++ b/scripts/particles/FallParticle.cs @@ -2,6 +2,9 @@ using Godot; using Newlon.Components.Level; using Newlon.Components.Zombies; +namespace Newlon.Components; + +[GlobalClass] public partial class FallParticle : RigidBody2D { [Export] private RuntimeZombieData data; @@ -19,10 +22,11 @@ public partial class FallParticle : RigidBody2D } Callable.From(() => { - Reparent(PoolContainer.Instance.Zombies); + Reparent(PoolContainer.Instance.Particles); float rng_angle = Mathf.DegToRad((float)GD.RandRange(minAngle, maxAngle)); float rng_torque = Mathf.DegToRad((float)GD.RandRange(minTorque, maxTorque)); - ApplyImpulse(new Vector2(Mathf.Sin(rng_angle) * Impulse, Mathf.Cos(rng_angle) * Impulse)); + if (Impulse != 0) + ApplyImpulse(new Vector2(Mathf.Sin(rng_angle) * Impulse, Mathf.Cos(rng_angle) * Impulse)); ApplyTorqueImpulse(rng_torque); }).CallDeferred(); var tween = CreateTween(); diff --git a/scripts/zombies/RuntimeZombieData.cs b/scripts/zombies/RuntimeZombieData.cs index 781158c..b4fb94b 100644 --- a/scripts/zombies/RuntimeZombieData.cs +++ b/scripts/zombies/RuntimeZombieData.cs @@ -10,6 +10,7 @@ public partial class RuntimeZombieData : Entity private AudioStream garlicSound; [Export] private AudioStream freezeSound; + [Signal] public delegate void HasBeenKilledEventHandler(RuntimeZombieData who); public bool AbleToEat = true; public override void Heal(float amount, Node origin) @@ -44,9 +45,13 @@ public partial class RuntimeZombieData : Entity } } #region Death sequence + private bool _killed = false; public override void KillByDamage() { + if (_killed) return; + _killed = true; AbleToEat = false; + EmitSignal(SignalName.HasBeenKilled,this); } #endregion