Rally X
ELEN3009 Project by Justin Wernick and David Schneider
|
A GameObject that is controlled by the player. More...
#include <PlayerCar.h>
Public Member Functions | |
PlayerCar (double x, double y, Maze::Direction facing=Maze::UP) | |
Creates a PlayerCar at the given location facing in the given direction. | |
void | update (const Maze &maze, list< Smokescreen > ¤tSmoke) |
Processes one frame's worth of activity for the object, called every frame. | |
void | makeSmoke (list< Smokescreen > ¤tSmoke) |
Creates a Smokescreen one block behind the player if the action is viable. | |
void | gotCheckpoint () |
Function that is called when the PlayerCar collides with a Checkpoint. | |
void | crash () |
Function that is called when the PlayerCar collides with an EnemyCar. | |
double | petrol () const |
Function to allow access to the amount of petrol that the PlayerCar still has. | |
Private Attributes | |
KeyboardHandler | _input |
Object that handles all interaction with the player. | |
double | _petrol |
The amount of petrol that the PlayerCar still has. | |
Static Private Attributes | |
static const double | PETROL_USE_RATE = 0.0007 |
The amount of petrol used every frame. | |
static const double | PETROL_USE_SMOKESCREEN = 0.05 |
The amount of petrol used to create a Smokescreen. | |
static const double | PETROL_FROM_CHECKPOINT = 0.2 |
The amount of petrol gained from collecting a Checkpoint. |
A GameObject that is controlled by the player.
Contains a KeyboardHandler to accept user input.
Definition at line 23 of file PlayerCar.h.
PlayerCar::PlayerCar | ( | double | x, |
double | y, | ||
Maze::Direction | facing = Maze::UP |
||
) |
Creates a PlayerCar at the given location facing in the given direction.
In the current form of the level files, there is no way to distinguish the direction that the player is facing, so the default of UP is used. However, the ability to pass in a facing is useful in the unit tests.
[in] | x | The x coordinate of the object's initial position. |
[in] | y | The y coordinate of the object's initial position. |
[in] | facing | The direction that the object is initially facing. |
Definition at line 3 of file PlayerCar.cpp.
void PlayerCar::crash | ( | ) |
Function that is called when the PlayerCar collides with an EnemyCar.
Definition at line 73 of file PlayerCar.cpp.
void PlayerCar::gotCheckpoint | ( | ) |
Function that is called when the PlayerCar collides with a Checkpoint.
Increases the amount of petrol by PETROL_FROM_CHECKPOINT.
Definition at line 78 of file PlayerCar.cpp.
void PlayerCar::makeSmoke | ( | list< Smokescreen > & | currentSmoke | ) |
Creates a Smokescreen one block behind the player if the action is viable.
The action is viable if the object has more than PETROL_USE_SMOKESCREEN petrol. Further, the position must not overlap with existing Smokescreens. This allows the player to hold down the Smokescreen button without creating a new Smokescreen every frame. Creating a Smokescreen decreases the petrol by PETROL_USE_SMOKESCREEN.
[in,out] | currentSmoke | The list of Smokescreens being drawn, that the new Smokescreens will be added to the back of. |
Definition at line 28 of file PlayerCar.cpp.
double PlayerCar::petrol | ( | ) | const |
Function to allow access to the amount of petrol that the PlayerCar still has.
Definition at line 84 of file PlayerCar.cpp.
void PlayerCar::update | ( | const Maze & | maze, |
list< Smokescreen > & | currentSmoke | ||
) |
Processes one frame's worth of activity for the object, called every frame.
The Keyboard handler is called for the user's input. Based on this, the direction can be changed, and a Smokescreen can be created and added to the list of already existing Smokescreens. The PlayerCar is then moved. Petrol is decreased by PETROL_USE_RATE on every update.
[in] | maze | The Maze that confines the PlayerCar's movement. |
[in,out] | currentSmoke | The list of Smokescreens being drawn, that the new Smokescreens will be added to the back of. |
Definition at line 10 of file PlayerCar.cpp.
KeyboardHandler PlayerCar::_input [private] |
Object that handles all interaction with the player.
Definition at line 84 of file PlayerCar.h.
double PlayerCar::_petrol [private] |
The amount of petrol that the PlayerCar still has.
Measured as a fraction, with 1 being a full tank and 0 being empty. When the petrol reaches 0, it is kept at zero and the PlayerCar's speed is halved.
Definition at line 92 of file PlayerCar.h.
const double PlayerCar::PETROL_FROM_CHECKPOINT = 0.2 [static, private] |
The amount of petrol gained from collecting a Checkpoint.
Definition at line 96 of file PlayerCar.h.
const double PlayerCar::PETROL_USE_RATE = 0.0007 [static, private] |
The amount of petrol used every frame.
Definition at line 94 of file PlayerCar.h.
const double PlayerCar::PETROL_USE_SMOKESCREEN = 0.05 [static, private] |
The amount of petrol used to create a Smokescreen.
Definition at line 95 of file PlayerCar.h.