Rally Rush
Loading...
Searching...
No Matches
car_player.hpp
Go to the documentation of this file.
1#ifndef CAR_PLAYER_HPP
2#define CAR_PLAYER_HPP
3
4#include "car_physics.hpp"
5#include "godot_cpp/classes/camera3d.hpp"
6#include "godot_cpp/classes/packed_scene.hpp"
7#include "utils/player.hpp"
8#include <godot_cpp/classes/input_event.hpp>
9#include <godot_cpp/classes/rigid_body3d.hpp>
10#include <godot_cpp/classes/collision_shape3d.hpp>
11
12namespace godot {
17class CarPlayer : public CarPhysics,
18 public IPlayer {
21 static void _bind_methods();
22public:
24 virtual void _ready() override;
26 virtual void _process(double delta_time) override;
31 virtual void setup_player_input(PlayerInput *input) override;
37 virtual void spawn_at_position(Transform3D const &transform) override;
39 virtual Node *to_node() override;
40
42 void on_steer(Ref<InputEvent> event, float value);
44 void on_brake(Ref<InputEvent> event, float value);
46 void on_accelerate(Ref<InputEvent> event, float value);
47
49 void damage();
50
54 void activate_powerup(Ref<PackedScene> scene);
56 void activate_turret();
58 void activate_beacon();
60 void activate_shield();
61
63 void set_turret_scene(Ref<PackedScene> scene);
65 Ref<PackedScene> get_turret_scene() const;
67 void set_beacon_scene(Ref<PackedScene> scene);
69 Ref<PackedScene> get_beacon_scene() const;
71 void set_shield_scene(Ref<PackedScene> scene);
73 Ref<PackedScene> get_shield_scene() const;
74private:
76 int health{5};
78 double end_of_powerup{0.0};
80 bool takes_damage{true};
82 float grace_timer_end{0.f};
83
85 Node3D *roof_slot{nullptr};
87 Camera3D *camera{nullptr};
88
90 Ref<PackedScene> turret;
92 Ref<PackedScene> beacon;
94 Ref<PackedScene> shield;
95
97 float const max_speed{40.f};
99 float const steering_factor{0.7f};
101 float const powerup_duration{10.f};
103 float const camera_distance{4.f};
105 float const camera_height{2.f};
107 float const camera_fullspeed_fov{90.f};
109 float const camera_stopped_fov{70.f};
111 float const fov_lerp_delta{40.f};
113 float const grace_time{1.f};
115 float const grace_time_flash{0.1f};
116};
117};
118
119#endif // !CAR_PLAYER_HPP
Subclass Sandbox for car physics. Uses _integrate_forces and local_velocity to abstract the behaviour...
Definition car_physics.hpp:13
Sandboxed subclass of CarPhysics.
Definition car_player.hpp:18
void set_beacon_scene(Ref< PackedScene > scene)
The object representing the beacon pickup.
Definition car_player.cpp:115
float const camera_fullspeed_fov
The FOV of the camera when the car is traveling at max_speed.
Definition car_player.hpp:107
void on_accelerate(Ref< InputEvent > event, float value)
Input callback for the accelerate key.
Definition car_player.cpp:62
void damage()
Take 1 damage.
Definition car_player.cpp:66
float const max_speed
Target speed when accelerate is pressed.
Definition car_player.hpp:97
void on_brake(Ref< InputEvent > event, float value)
Input callback for the brake key.
Definition car_player.cpp:58
Ref< PackedScene > get_turret_scene() const
The object representing the turret pickup.
Definition car_player.cpp:111
int health
Amount of hits the player's car can still take.
Definition car_player.hpp:76
virtual void setup_player_input(PlayerInput *input) override
Initialize player input callbacks.
Definition car_player.cpp:41
float const camera_stopped_fov
FOV of the camera when the car is not moving.
Definition car_player.hpp:109
float const steering_factor
Amount of steering to apply based on input.
Definition car_player.hpp:99
GDCLASS(CarPlayer, CarPhysics)
float const powerup_duration
Duration of a powerup after it is picked up.
Definition car_player.hpp:101
void activate_powerup(Ref< PackedScene > scene)
Destroy all children and activate a new powerup.
Definition car_player.cpp:88
Ref< PackedScene > shield
The ramming shield powerup scene.
Definition car_player.hpp:94
double end_of_powerup
The time at which the current powerup will be deactivated.
Definition car_player.hpp:78
void on_steer(Ref< InputEvent > event, float value)
Input callback for the steering axis.
Definition car_player.cpp:54
float const camera_height
Height the camera should be at relative to the pivot.
Definition car_player.hpp:105
Ref< PackedScene > beacon
The hacking beacon powerup scene.
Definition car_player.hpp:92
void activate_turret()
Destroy all powerups and spawn a turret.
Definition car_player.cpp:96
virtual Node * to_node() override
Convert to node.
Definition car_player.cpp:52
Camera3D * camera
The camera.
Definition car_player.hpp:87
Ref< PackedScene > get_beacon_scene() const
The object representing the beacon pickup.
Definition car_player.cpp:119
void activate_beacon()
Destroy all powerups and spawn a beacon.
Definition car_player.cpp:100
virtual void _process(double delta_time) override
Update powerup and grace period timers. As well as the camera position.
Definition car_player.cpp:25
float grace_timer_end
The time at which the current grace period will end.
Definition car_player.hpp:82
float const camera_distance
Distance from the pivot the camera should be at.
Definition car_player.hpp:103
static void _bind_methods()
Register editor properties and damage function.
Definition car_player.cpp:12
float const grace_time
Amount of time the player should be invincible after being hit.
Definition car_player.hpp:113
void activate_shield()
Destroy all powerups and spawn a shield.
Definition car_player.cpp:101
virtual void spawn_at_position(Transform3D const &transform) override
Place player at initial position Called from the GameRoot3D of the godot-cpp-utils library.
Definition car_player.cpp:47
Ref< PackedScene > turret
The roof turret powerup scene.
Definition car_player.hpp:90
virtual void _ready() override
Get the required child nodes.
Definition car_player.cpp:20
void set_turret_scene(Ref< PackedScene > scene)
The object representing the turret pickup.
Definition car_player.cpp:107
void destroy_all_powerups()
Destroy all children of roof_slot.
Definition car_player.cpp:78
Ref< PackedScene > get_shield_scene() const
The object representing the shield pickup.
Definition car_player.cpp:127
Node3D * roof_slot
The parent of any pickup models.
Definition car_player.hpp:85
void set_shield_scene(Ref< PackedScene > scene)
The object representing the shield pickup.
Definition car_player.cpp:123
float const fov_lerp_delta
Speed in degrees-per-second that the camera FOV can change at.
Definition car_player.hpp:111
bool takes_damage
If false, the car will be invincible.
Definition car_player.hpp:80
float const grace_time_flash
Interval at which the car's model should flash while invincible after being hit.
Definition car_player.hpp:115
Definition beacon_powerup.cpp:6