ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Revision:
26:d16a5b1e0ace
Parent:
24:67dc71a8f009
Child:
27:af14fcd5a520
--- a/Engine/Engine.h	Wed May 08 15:07:04 2019 +0000
+++ b/Engine/Engine.h	Wed May 08 17:24:35 2019 +0000
@@ -20,77 +20,91 @@
     ~Engine();
     
     /** 
-    @brief defines the initial position of the bullet
-    @param float dood_pos_x 
-    @param float dood_pos_y
-    @details The intial position is in same position as doodler's trunk end (which is why I am adding the 12 and 4 to the doodler's position)
+    @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(int floors_width, int floors_height);
+    void init();
     
     /** 
-    @brief defines the initial position of the bullet
-    @param float dood_pos_x 
-    @param float dood_pos_y
-    @details The intial position is in same position as doodler's trunk end (which is why I am adding the 12 and 4 to the doodler's position)
+    @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. 
     */
     void screen_init();
     
     /** 
-    @brief defines the initial position of the bullet
-    @param float dood_pos_x 
-    @param float dood_pos_y
-    @details The intial position is in same position as doodler's trunk end (which is why I am adding the 12 and 4 to the doodler's position)
+    @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. 
     */
     void read_input(Gamepad &pad);
     
     /** 
-    @brief defines the initial position of the bullet
-    @param float dood_pos_x 
-    @param float dood_pos_y
-    @details The intial position is in same position as doodler's trunk end (which is why I am adding the 12 and 4 to the doodler's position)
+    @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 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. Next,
+    it 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. Finally, it checks if the doodler fire's by inputing the doodler's
+    previous position and updated position, as well as the pad's input. 
     */
     void update(Gamepad &pad);
     
     /** 
-    @brief defines the initial position of the bullet
-    @param float dood_pos_x 
-    @param float dood_pos_y
-    @details The intial position is in same position as doodler's trunk end (which is why I am adding the 12 and 4 to the doodler's position)
-    */
-    void draw(N5110 &lcd);
-    
-    /** 
-    @brief defines the initial position of the bullet
-    @param float dood_pos_x 
-    @param float dood_pos_y
-    @details The intial position is in same position as doodler's trunk end (which is why I am adding the 12 and 4 to the doodler's position)
+    @brief  Checks a collision and sets the doodler's velocity (if it jumps) direction
+    @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 
+    accordingly (make it increase or decrease by multiplying it with constant values) so that the doodler accelerates
+    or decelerates according to its current velocity. 
     */
     void check_floors_collision(float doodler_pos_x, float doodler_pos_y, double doodler_vel_y);
     
     /** 
-    @brief defines the initial position of the bullet
-    @param float dood_pos_x 
-    @param float dood_pos_y
-    @details The intial position is in same position as doodler's trunk end (which is why I am adding the 12 and 4 to the doodler's position)
+    @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 
+    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 
+    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 
+    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 defines the initial position of the bullet
-    @param float dood_pos_x 
-    @param float dood_pos_y
-    @details The intial position is in same position as doodler's trunk end (which is why I am adding the 12 and 4 to the doodler's position)
+    @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 
+    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. 
     */
     void add_score();
     
-    /** 
-    @brief defines the initial position of the bullet
-    @param float dood_pos_x 
-    @param float dood_pos_y
-    @details The intial position is in same position as doodler's trunk end (which is why I am adding the 12 and 4 to the doodler's position)
-    */
-    void print_score(N5110 &lcd);
-    
 private:
     Bullet _b;
     float _b_pos_x;