feat: player character implements health entity interface

This commit is contained in:
Sara 2024-03-18 16:28:00 +01:00
parent 50392dd3ed
commit 99b844cc76
2 changed files with 16 additions and 1 deletions

View file

@ -12,6 +12,7 @@ void PlayerCharacter::_bind_methods() {
void PlayerCharacter::_enter_tree() { GDGAMEONLY();
this->nav_agent = this->get_node<NavigationAgent3D>("NavigationAgent3D");
this->target_rotation = this->get_global_transform().get_basis().get_quaternion();
this->health = this->get_node<Health>("Health");
}
void PlayerCharacter::_process(double delta_time) { GDGAMEONLY();
@ -51,6 +52,14 @@ Ref<Curve> PlayerCharacter::get_rotation_speed_curve() const {
return this->rotation_speed_curve;
}
Health *PlayerCharacter::get_health() {
return this->health;
}
Health const *PlayerCharacter::get_health() const {
return this->health;
}
void PlayerCharacter::process_ai(double delta_time) {
this->velocity_target = this->nav_agent->get_velocity();
}

View file

@ -2,12 +2,14 @@
#define PLAYER_CHARACTER_HPP
#include "godot_cpp/classes/curve.hpp"
#include "health.hpp"
#include <godot_cpp/classes/character_body3d.hpp>
namespace godot {
class NavigationAgent3D;
class PlayerCharacter : public CharacterBody3D {
class PlayerCharacter : public CharacterBody3D,
public IHealthEntity {
GDCLASS(PlayerCharacter, CharacterBody3D);
static void _bind_methods();
public:
@ -20,6 +22,9 @@ public:
void set_rotation_speed_curve(Ref<Curve> curve);
Ref<Curve> get_rotation_speed_curve() const;
virtual Health *get_health() override;
virtual Health const *get_health() const override;
protected:
void process_ai(double delta_time);
void process_rotation(double delta_time);
@ -28,6 +33,7 @@ private:
Basis target_rotation{};
NavigationAgent3D *nav_agent{nullptr};
bool mode_manual{false};
Health *health{nullptr};
Ref<Curve> rotation_speed_curve{};