Add Dying animation

This commit is contained in:
Morph01
2024-08-22 17:53:25 +02:00
parent 1f52eb2c52
commit faf6a9116d
3 changed files with 828 additions and 110 deletions

File diff suppressed because one or more lines are too long

View File

@@ -16,6 +16,7 @@ void Zombie::_bind_methods() {
ClassDB::bind_method(D_METHOD("hit_finished"), &Zombie::hit_finished);
ClassDB::bind_method(D_METHOD("_on_area_3d_a_zombie_head_shot_hit", "m_Health"), &Zombie::_on_area_3d_a_zombie_head_shot_hit);
ClassDB::bind_method(D_METHOD("_on_area_3d_a_zombie_body_shot_hit", "m_Health"), &Zombie::_on_area_3d_a_zombie_body_shot_hit);
ClassDB::bind_method(D_METHOD("_on_timer_timeout"), &Zombie::_on_timer_timeout);
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "m_PlayerPath"), "set_m_PlayerPath", "get_m_PlayerPath");
}
@@ -44,6 +45,9 @@ void Zombie::_ready() {
DEV_ASSERT(m_HeadCollision);
m_HeadCollision->connect("a_ZombieHeadShotHit", Callable(this, "_on_area_3d_a_zombie_head_shot_hit"));
connect_collision_shapes(m_BodyPartsCollision);
m_Timer = memnew(Timer);
add_child(m_Timer);
m_Timer->connect("timeout", callable_mp(this, &Zombie::_on_timer_timeout));
}
void Zombie::_process(float a_Delta) {
@@ -92,7 +96,10 @@ void Zombie::hit_finished() {
void Zombie::apply_damage(int dam) {
m_Health -= dam;
if (m_Health <= 0) {
queue_free();
m_AnimationTree->set("parameters/conditions/die", true);
this->set_velocity(Vector3(0, 0, 0));
m_Timer->set_wait_time(4.0);
m_Timer->start();
}
}
@@ -113,4 +120,8 @@ void Zombie::connect_collision_shapes(const std::vector<StringName>& body_parts)
}
}
void Zombie::_on_timer_timeout() {
queue_free();
}
} // namespace blitz

View File

@@ -8,6 +8,7 @@
#include <godot_cpp/classes/navigation_agent3d.hpp>
#include <godot_cpp/variant/node_path.hpp>
#include <godot_cpp/variant/string_name.hpp>
#include <godot_cpp/classes/timer.hpp>
namespace blitz {
@@ -37,12 +38,14 @@ class Zombie : public godot::CharacterBody3D {
std::vector<godot::StringName> m_BodyPartsCollision = {"Neck", "Spine", "Hips", "LeftArm", "LeftForearm", "LeftHand", "RightArm",
"RightForearm", "RightHand", "LeftUpLeg", "RightUpLeg", "LeftLeg", "RightLeg", "LeftFoot", "RightFoot"};
int m_Health = 6;
godot::Timer* m_Timer;
void set_m_PlayerPath(const godot::NodePath& path);
godot::NodePath get_m_PlayerPath() const;
void hit_finished();
void apply_damage(int dam);
void connect_collision_shapes(const std::vector<godot::StringName>& body_parts);
void _on_timer_timeout();
};
} // namespace blitz