feat: player character implements health entity interface
This commit is contained in:
parent
50392dd3ed
commit
99b844cc76
|
@ -12,6 +12,7 @@ void PlayerCharacter::_bind_methods() {
|
||||||
void PlayerCharacter::_enter_tree() { GDGAMEONLY();
|
void PlayerCharacter::_enter_tree() { GDGAMEONLY();
|
||||||
this->nav_agent = this->get_node<NavigationAgent3D>("NavigationAgent3D");
|
this->nav_agent = this->get_node<NavigationAgent3D>("NavigationAgent3D");
|
||||||
this->target_rotation = this->get_global_transform().get_basis().get_quaternion();
|
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();
|
void PlayerCharacter::_process(double delta_time) { GDGAMEONLY();
|
||||||
|
@ -51,6 +52,14 @@ Ref<Curve> PlayerCharacter::get_rotation_speed_curve() const {
|
||||||
return this->rotation_speed_curve;
|
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) {
|
void PlayerCharacter::process_ai(double delta_time) {
|
||||||
this->velocity_target = this->nav_agent->get_velocity();
|
this->velocity_target = this->nav_agent->get_velocity();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,14 @@
|
||||||
#define PLAYER_CHARACTER_HPP
|
#define PLAYER_CHARACTER_HPP
|
||||||
|
|
||||||
#include "godot_cpp/classes/curve.hpp"
|
#include "godot_cpp/classes/curve.hpp"
|
||||||
|
#include "health.hpp"
|
||||||
#include <godot_cpp/classes/character_body3d.hpp>
|
#include <godot_cpp/classes/character_body3d.hpp>
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
class NavigationAgent3D;
|
class NavigationAgent3D;
|
||||||
|
|
||||||
class PlayerCharacter : public CharacterBody3D {
|
class PlayerCharacter : public CharacterBody3D,
|
||||||
|
public IHealthEntity {
|
||||||
GDCLASS(PlayerCharacter, CharacterBody3D);
|
GDCLASS(PlayerCharacter, CharacterBody3D);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
public:
|
public:
|
||||||
|
@ -20,6 +22,9 @@ public:
|
||||||
|
|
||||||
void set_rotation_speed_curve(Ref<Curve> curve);
|
void set_rotation_speed_curve(Ref<Curve> curve);
|
||||||
Ref<Curve> get_rotation_speed_curve() const;
|
Ref<Curve> get_rotation_speed_curve() const;
|
||||||
|
|
||||||
|
virtual Health *get_health() override;
|
||||||
|
virtual Health const *get_health() const override;
|
||||||
protected:
|
protected:
|
||||||
void process_ai(double delta_time);
|
void process_ai(double delta_time);
|
||||||
void process_rotation(double delta_time);
|
void process_rotation(double delta_time);
|
||||||
|
@ -28,6 +33,7 @@ private:
|
||||||
Basis target_rotation{};
|
Basis target_rotation{};
|
||||||
NavigationAgent3D *nav_agent{nullptr};
|
NavigationAgent3D *nav_agent{nullptr};
|
||||||
bool mode_manual{false};
|
bool mode_manual{false};
|
||||||
|
Health *health{nullptr};
|
||||||
|
|
||||||
Ref<Curve> rotation_speed_curve{};
|
Ref<Curve> rotation_speed_curve{};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue