feat: added damage function to player
This commit is contained in:
parent
80270546e0
commit
5bb287252c
|
@ -1,4 +1,6 @@
|
|||
#include "car_player.hpp"
|
||||
#include "rally_rush_game_mode.hpp"
|
||||
#include "utils/game_root.hpp"
|
||||
#include "utils/player_input.hpp"
|
||||
#include <godot_cpp/variant/transform3d.hpp>
|
||||
#include <godot_cpp/classes/physics_direct_body_state3d.hpp>
|
||||
|
@ -19,6 +21,8 @@ void CarPlayer::spawn_at_position(Transform3D const &transform) {
|
|||
this->set_scale({1,1,1});
|
||||
}
|
||||
|
||||
Node *CarPlayer::to_node() { return this; }
|
||||
|
||||
void CarPlayer::on_steer(Ref<InputEvent> event, float value) {
|
||||
this->set_current_steering(value * this->steering_factor);
|
||||
}
|
||||
|
@ -31,5 +35,11 @@ void CarPlayer::on_accelerate(Ref<InputEvent> input, float value) {
|
|||
this->set_target_speed(max_speed * value);
|
||||
}
|
||||
|
||||
Node *CarPlayer::to_node() { return this; }
|
||||
void CarPlayer::damage() {
|
||||
--this->health;
|
||||
if(this->health <= 0) {
|
||||
RallyRushGameMode *game_mode = Ref<RallyRushGameMode>(GameRoot3D::get_singleton()->get_game_mode()).ptr();
|
||||
game_mode->notify_player_death();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,10 @@ public:
|
|||
void on_steer(Ref<InputEvent> event, float value);
|
||||
void on_brake(Ref<InputEvent> event, float value);
|
||||
void on_accelerate(Ref<InputEvent> event, float value);
|
||||
|
||||
void damage();
|
||||
private:
|
||||
int health{0};
|
||||
int health{1};
|
||||
|
||||
const float max_speed{40.f};
|
||||
const float max_speed_reverse{10.f};
|
||||
|
|
Loading…
Reference in a new issue