# Rally Rush: src/car_player.hpp Source File

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