ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Committer:
el17m2h
Date:
Wed May 08 17:24:35 2019 +0000
Revision:
26:d16a5b1e0ace
Parent:
24:67dc71a8f009
Child:
27:af14fcd5a520
Added comments for the documentation file.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17m2h 2:360a6c301a4e 1 #ifndef ENGINE_H
el17m2h 2:360a6c301a4e 2 #define ENGINE_H
el17m2h 2:360a6c301a4e 3
el17m2h 22:0d2ac98a8b48 4 #include <iostream>
el17m2h 2:360a6c301a4e 5 #include "mbed.h"
el17m2h 2:360a6c301a4e 6 #include "N5110.h"
el17m2h 2:360a6c301a4e 7 #include "Gamepad.h"
el17m2h 2:360a6c301a4e 8 #include "Floors.h"
el17m2h 4:8ec314f806ae 9 #include "Doodler.h"
el17m2h 17:74de8c17ddac 10 #include "Bullet.h"
el17m2h 2:360a6c301a4e 11
el17m2h 24:67dc71a8f009 12 /** Engine class
el17m2h 24:67dc71a8f009 13 @brief Class for the engine of the game
el17m2h 24:67dc71a8f009 14 @author Melissa Hartmann
el17m2h 24:67dc71a8f009 15 @date May 2019
el17m2h 24:67dc71a8f009 16 */
el17m2h 2:360a6c301a4e 17 class Engine{
el17m2h 2:360a6c301a4e 18 public:
el17m2h 2:360a6c301a4e 19 Engine();
el17m2h 2:360a6c301a4e 20 ~Engine();
el17m2h 24:67dc71a8f009 21
el17m2h 24:67dc71a8f009 22 /**
el17m2h 26:d16a5b1e0ace 23 @brief Initializing game
el17m2h 26:d16a5b1e0ace 24 @details The function defines the screen's size, and the initial position of the doodler,
el17m2h 26:d16a5b1e0ace 25 the bullet and the 6 floors. This is done by adding the functions of initialization to the
el17m2h 26:d16a5b1e0ace 26 corresponding class. A for loop is used to repeat the process to create 6 floors, by defining
el17m2h 26:d16a5b1e0ace 27 them as an array of 6 objects.
el17m2h 24:67dc71a8f009 28 */
el17m2h 26:d16a5b1e0ace 29 void init();
el17m2h 24:67dc71a8f009 30
el17m2h 24:67dc71a8f009 31 /**
el17m2h 26:d16a5b1e0ace 32 @brief Initializes the screen's size and the initial score
el17m2h 26:d16a5b1e0ace 33 @details The function defines the screen's position, height and width (which remains the same
el17m2h 26:d16a5b1e0ace 34 throughout the game). It also sets an initial score of 0.
el17m2h 24:67dc71a8f009 35 */
el17m2h 23:9be87557b89a 36 void screen_init();
el17m2h 24:67dc71a8f009 37
el17m2h 24:67dc71a8f009 38 /**
el17m2h 26:d16a5b1e0ace 39 @brief Sets the inputed gamepad parameters
el17m2h 26:d16a5b1e0ace 40 @param Gamepad &pad
el17m2h 26:d16a5b1e0ace 41 @details The function sets the inputed gamepad parameters for the direction of the joystick,
el17m2h 26:d16a5b1e0ace 42 the magnitude at which the joystick is moved and checks if the button Y is pressed.
el17m2h 24:67dc71a8f009 43 */
el17m2h 5:8814d6de77d0 44 void read_input(Gamepad &pad);
el17m2h 24:67dc71a8f009 45
el17m2h 24:67dc71a8f009 46 /**
el17m2h 26:d16a5b1e0ace 47 @brief Prints the doodler, floors and bullet
el17m2h 26:d16a5b1e0ace 48 @param N5110 &lcd
el17m2h 26:d16a5b1e0ace 49 @details The function calls the draw functions for the doodler, floors and bullet. For the floors, a
el17m2h 26:d16a5b1e0ace 50 for loop is used to repeat the process to draw the 6 floors. It also draws the screen rectangle and the score.
el17m2h 26:d16a5b1e0ace 51 */
el17m2h 26:d16a5b1e0ace 52 void draw(N5110 &lcd);
el17m2h 26:d16a5b1e0ace 53
el17m2h 26:d16a5b1e0ace 54 /**
el17m2h 26:d16a5b1e0ace 55 @brief Updates the classes in the game by calling it's update functions
el17m2h 26:d16a5b1e0ace 56 @param Gamepad &pad
el17m2h 26:d16a5b1e0ace 57 @details The function checks the collision of the doodler with the floors by getting their current positions
el17m2h 26:d16a5b1e0ace 58 and inputing them to the "check_floors_collision" function, which will update the velocity of the doodler. Next,
el17m2h 26:d16a5b1e0ace 59 it calls the "update" functions for the floors and doodler which will update their positions. It then calls the
el17m2h 26:d16a5b1e0ace 60 "add_score" function to update the score value. Finally, it checks if the doodler fire's by inputing the doodler's
el17m2h 26:d16a5b1e0ace 61 previous position and updated position, as well as the pad's input.
el17m2h 24:67dc71a8f009 62 */
el17m2h 5:8814d6de77d0 63 void update(Gamepad &pad);
el17m2h 24:67dc71a8f009 64
el17m2h 24:67dc71a8f009 65 /**
el17m2h 26:d16a5b1e0ace 66 @brief Checks a collision and sets the doodler's velocity (if it jumps) direction
el17m2h 26:d16a5b1e0ace 67 @param float doodler_pos_x
el17m2h 26:d16a5b1e0ace 68 @param float doodler_pos_y
el17m2h 26:d16a5b1e0ace 69 @param double doodler_vel_y
el17m2h 26:d16a5b1e0ace 70 @details Checks a collision by comparing the doodler's position with the floors' ones with 3 conditions:
el17m2h 26:d16a5b1e0ace 71 if the doodler is moving downwards (its velocity is positive), if the doodler's x-coordinate is within the
el17m2h 26:d16a5b1e0ace 72 floor's x-coordinate and if the floors' y-coordinate is the same as the doodler's feet (by getting the position
el17m2h 26:d16a5b1e0ace 73 in integers so the difference can be 0 and by adding 15 from the doodler's position (so it gets the feet position).
el17m2h 26:d16a5b1e0ace 74 If the conditions are met, it means there is a collision, which means the doodler's velocity will change direction
el17m2h 26:d16a5b1e0ace 75 (will be set to a negative value). The function also checks the doodler's velocity function to update the velocity
el17m2h 26:d16a5b1e0ace 76 accordingly (make it increase or decrease by multiplying it with constant values) so that the doodler accelerates
el17m2h 26:d16a5b1e0ace 77 or decelerates according to its current velocity.
el17m2h 24:67dc71a8f009 78 */
el17m2h 24:67dc71a8f009 79 void check_floors_collision(float doodler_pos_x, float doodler_pos_y, double doodler_vel_y);
el17m2h 24:67dc71a8f009 80
el17m2h 24:67dc71a8f009 81 /**
el17m2h 26:d16a5b1e0ace 82 @brief Checks if the doodler fires
el17m2h 26:d16a5b1e0ace 83 @param Gamepad &pad
el17m2h 26:d16a5b1e0ace 84 @param float updated_doodler_pos_x
el17m2h 26:d16a5b1e0ace 85 @param float updated_doodler_pos_y
el17m2h 26:d16a5b1e0ace 86 @param float doodler_pos_y
el17m2h 26:d16a5b1e0ace 87 @details The function checks the bullet's position and the input of the user (if the
el17m2h 26:d16a5b1e0ace 88 Y button has been pressed). If the bullet is not currently fired (its position
el17m2h 26:d16a5b1e0ace 89 equals the current doodler's trunk position) and the button Y is pressed, then the bullet is
el17m2h 26:d16a5b1e0ace 90 updated to a new position (upwards) and the pad makes a sound indicating it is shooting. If
el17m2h 26:d16a5b1e0ace 91 it is currently above the doodler's position, it means it has been fired, so continues being
el17m2h 26:d16a5b1e0ace 92 updated. The update function will eventually check if the bullet has reached the end top of the
el17m2h 26:d16a5b1e0ace 93 screen, which will make the bullet return to the doodler's trunk's position. If this is the case
el17m2h 26:d16a5b1e0ace 94 and the button Y has not been pressed, the bullet remains in the doodler's position (by inputing
el17m2h 26:d16a5b1e0ace 95 the doodler's position to the initialize function instead of the update one).
el17m2h 24:67dc71a8f009 96 */
el17m2h 23:9be87557b89a 97 void check_fire(Gamepad &pad, float updated_doodler_pos_x, float updated_doodler_pos_y, float doodler_pos_y);
el17m2h 24:67dc71a8f009 98
el17m2h 24:67dc71a8f009 99 /**
el17m2h 26:d16a5b1e0ace 100 @brief Increases score by checking the position of the floor
el17m2h 26:d16a5b1e0ace 101 @details The function uses a foor loop to check the current position of every floor and
el17m2h 26:d16a5b1e0ace 102 if they have reached the top of the screen (meaning they have re-appeared at the top, the
el17m2h 26:d16a5b1e0ace 103 score will have one point added. This means that the score depends on how many floors re-appear,
el17m2h 26:d16a5b1e0ace 104 which represents how high the doodler has moved upwards.
el17m2h 24:67dc71a8f009 105 */
el17m2h 21:6b16ca9834e6 106 void add_score();
el17m2h 24:67dc71a8f009 107
el17m2h 19:5a7b0cdf013b 108 private:
el17m2h 18:9f40a2f8c2c5 109 Bullet _b;
el17m2h 19:5a7b0cdf013b 110 float _b_pos_x;
el17m2h 19:5a7b0cdf013b 111 float _b_pos_y;
el17m2h 21:6b16ca9834e6 112
el17m2h 21:6b16ca9834e6 113 int _score;
el17m2h 19:5a7b0cdf013b 114
el17m2h 23:9be87557b89a 115 Floors _f[6]; // array of 6 floors
el17m2h 4:8ec314f806ae 116
el17m2h 2:360a6c301a4e 117 int _floors_height;
el17m2h 2:360a6c301a4e 118 int _floors_width;
el17m2h 4:8ec314f806ae 119
el17m2h 2:360a6c301a4e 120 // x and y positions of the floors
el17m2h 23:9be87557b89a 121 Vector2D _f_pos[6]; //
el17m2h 5:8814d6de77d0 122
el17m2h 5:8814d6de77d0 123 Doodler _dood;
el17m2h 24:67dc71a8f009 124 float doodler_pos_x;
el17m2h 24:67dc71a8f009 125 float doodler_pos_y;
el17m2h 24:67dc71a8f009 126 float updated_doodler_pos_x;
el17m2h 24:67dc71a8f009 127 float updated_doodler_pos_y;
el17m2h 24:67dc71a8f009 128 float doodler_vel_x;
el17m2h 24:67dc71a8f009 129 double doodler_vel_y;
el17m2h 23:9be87557b89a 130 float distance_y[6];
el17m2h 17:74de8c17ddac 131
el17m2h 19:5a7b0cdf013b 132 int _screen_pos_x;
el17m2h 19:5a7b0cdf013b 133 int _screen_pos_y;
el17m2h 19:5a7b0cdf013b 134 int _screen_width;
el17m2h 19:5a7b0cdf013b 135 int _screen_height;
el17m2h 19:5a7b0cdf013b 136
el17m2h 5:8814d6de77d0 137 Direction _d;
el17m2h 5:8814d6de77d0 138 float _mag;
el17m2h 16:e0542761fc8c 139 bool _button_A;
el17m2h 16:e0542761fc8c 140 bool _button_B;
el17m2h 16:e0542761fc8c 141 bool _button_X;
el17m2h 16:e0542761fc8c 142 bool _button_Y;
el17m2h 2:360a6c301a4e 143 };
el17m2h 2:360a6c301a4e 144 #endif