Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: Engine/Engine.h
- Revision:
- 29:15e9640646b7
- Parent:
- 28:e0161a52a8b9
- Child:
- 31:5c4acae51026
--- a/Engine/Engine.h Wed May 08 18:02:11 2019 +0000
+++ b/Engine/Engine.h Wed May 08 21:11:35 2019 +0000
@@ -14,135 +14,159 @@
@author Melissa Hartmann
@date May 2019
*/
-class Engine{
+class Engine
+{
public:
Engine();
~Engine();
-
- /**
- @brief Initializing game
- @details The function defines the screen's size, and the initial position of the doodler,
- the bullet and the 6 floors. This is done by adding the functions of initialization to the
+
+ /**
+ @brief Initializing game
+ @details The function defines the screen's size, and the initial position of the doodler,
+ the bullet and the 6 floors. This is done by adding the functions of initialization to the
corresponding class. A for loop is used to repeat the process to create 6 floors, by defining
them as an array of 6 objects.
*/
void init();
-
- /**
+
+ /**
@brief Initializes the screen's size and the initial score
- @details The function defines the screen's position, height and width (which remains the same
- throughout the game). It also sets an initial score of 0.
+ @details The function defines the screen's position, height and width (which remains the same
+ throughout the game). It also sets an initial score of 0.
*/
void screen_init();
-
- /**
+
+ /**
@brief Sets the inputed gamepad parameters
- @param Gamepad &pad
- @details The function sets the inputed gamepad parameters for the direction of the joystick,
- the magnitude at which the joystick is moved and checks if the button Y is pressed.
+ @param Gamepad &pad
+ @details The function sets the inputed gamepad parameters for the direction of the joystick,
+ the magnitude at which the joystick is moved and checks if the button Y is pressed.
*/
void read_input(Gamepad &pad);
-
- /**
+
+ /**
@brief Prints the doodler, floors and bullet
@param N5110 &lcd
@details The function calls the draw functions for the doodler, floors and bullet. For the floors, a
for loop is used to repeat the process to draw the 6 floors. It also draws the screen rectangle and the score.
*/
void draw(N5110 &lcd);
-
- /**
+
+ /**
@brief Updates the classes in the game by calling it's update functions
@param Gamepad &pad
- @details Firstly, the function checks the collision of the doodler with the floors by getting their current positions
+ @details Firstly, the function checks the collision of the doodler with the floors by getting their current positions
and inputing them to the "check_floors_collision" function, which will update the velocity of the doodler. Secondly, it
- calls the "update" functions for the floors and doodler which will update their positions. It then calls the
+ calls the "update" functions for the floors and doodler which will update their positions. It then calls the
"add_score" function to update the score value. Next, it checks if the doodler fire's by inputing the doodler's
previous position and updated position, as well as the pad's input. Finally, it calls a function to check if the doodler
has reached the bottom of the screen to end the game.
*/
void update(Gamepad &pad);
-
- /**
+
+ /**
@brief Checks a collision and sets the doodler's velocity (if it jumps) direction
+ @param Gamepad &pad to make a sound each time the doodler jumps
@param float doodler_pos_x
@param float doodler_pos_y
@param double doodler_vel_y
- @details Checks a collision by comparing the doodler's position with the floors' ones with 3 conditions:
- if the doodler is moving downwards (its velocity is positive), if the doodler's x-coordinate is within the
- floor's x-coordinate and if the floors' y-coordinate is the same as the doodler's feet (by getting the position
- in integers so the difference can be 0 and by adding 15 from the doodler's position (so it gets the feet position).
- If the conditions are met, it means there is a collision, which means the doodler's velocity will change direction
- (will be set to a negative value). The function also checks the doodler's velocity function to update the velocity
+ @details Checks a collision by comparing the doodler's position with the floors' ones with 3 conditions:
+ if the doodler is moving downwards (its velocity is positive), if the doodler's x-coordinate is within the
+ floor's x-coordinate and if the floors' y-coordinate is equal or +/-1 bits of the doodler's feet.
+ If the conditions are met, it means there is a collision, which means the doodler's velocity will change direction
+ (will be set to a negative value). The function also checks the doodler's velocity function to update the velocity
accordingly (make it increase or decrease by multiplying it with constant values) so that the doodler accelerates
- or decelerates according to its current velocity.
+ or decelerates according to its current velocity.
*/
- void check_floors_collision(float doodler_pos_x, float doodler_pos_y, double doodler_vel_y);
-
- /**
+ void check_floors_collision(Gamepad &pad, float doodler_pos_x, float doodler_pos_y, double doodler_vel_y);
+
+ /**
@brief Checks if the doodler fires
@param Gamepad &pad
@param float updated_doodler_pos_x
@param float updated_doodler_pos_y
@param float doodler_pos_y
- @details The function checks the bullet's position and the input of the user (if the
- Y button has been pressed). If the bullet is not currently fired (its position
- equals the current doodler's trunk position) and the button Y is pressed, then the bullet is
+ @details The function checks the bullet's position and the input of the user (if the
+ Y button has been pressed). If the bullet is not currently fired (its position
+ equals the current doodler's trunk position) and the button Y is pressed, then the bullet is
updated to a new position (upwards) and the pad makes a sound indicating it is shooting. If
- it is currently above the doodler's position, it means it has been fired, so continues being
- updated. The update function will eventually check if the bullet has reached the end top of the
+ it is currently above the doodler's position, it means it has been fired, so continues being
+ updated. The update function will eventually check if the bullet has reached the end top of the
screen, which will make the bullet return to the doodler's trunk's position. If this is the case
- and the button Y has not been pressed, the bullet remains in the doodler's position (by inputing
+ and the button Y has not been pressed, the bullet remains in the doodler's position (by inputing
the doodler's position to the initialize function instead of the update one).
*/
void check_fire(Gamepad &pad, float updated_doodler_pos_x, float updated_doodler_pos_y, float doodler_pos_y);
-
- /**
+
+ /**
@brief Increases score by checking the position of the floor
- @details The function uses a foor loop to check the current position of every floor and
- if they have reached the top of the screen (meaning they have re-appeared at the top, the
+ @details The function uses a foor loop to check the current position of every floor and
+ if they have reached the top of the screen (meaning they have re-appeared at the top, the
score will have one point added. This means that the score depends on how many floors re-appear,
- which represents how high the doodler has moved upwards.
+ which represents how high the doodler has moved upwards.
*/
void add_score();
+
+ void subtract_score();
+
+
+ bool get_score_check();
+
+
+ /**
+ @brief Returns the current score
+ @details The function returns the current score of the game. It is called in the main.cpp to display
+ the final score.
+ */
int get_score();
+ /**
+ @brief Sets the decision statement to end the game depending on the doodler's y-coordinate position
+ @param float doodler_pos_y
+ @details The function sets the decision statement to end the game by using an if statement dependent on
+ the read doodler's position. If the position has reached the bottom of the screen, the game should end, so
+ the decision will be true.
+ */
void set_game_over(float doodler_pos_y);
-
-
+
+ /**
+ @brief Returns a true/false statement for ending the game or not
+ @details The function returns a bool type decision true/false, which will be called on the main.cpp
+ to decide if the game should end or not.
+ */
bool get_game_over();
-
+
private:
Bullet _b;
float _b_pos_x;
float _b_pos_y;
-
+
int _score;
+ bool _score_check;
bool game_ends;
Floors _f[6]; // array of 6 floors
-
+
int _floors_height;
int _floors_width;
-
+
// x and y positions of the floors
Vector2D _f_pos[6]; //
-
+
Doodler _dood;
float doodler_pos_x;
float doodler_pos_y;
float updated_doodler_pos_x;
float updated_doodler_pos_y;
float doodler_vel_x;
- double doodler_vel_y;
- float distance_y[6];
-
+ double doodler_vel_y;
+
int _screen_pos_x;
int _screen_pos_y;
int _screen_width;
int _screen_height;
-
+
Direction _d;
float _mag;
bool _button_A;