ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Committer:
el17m2h
Date:
Thu May 09 11:21:53 2019 +0000
Revision:
32:83f410c433c2
Parent:
29:15e9640646b7
Child:
34:a9b14a4ccd46
Finished commenting the doodler.cpp file and changed the coding structure to simplify it (splitted the update function into 2 and wrote simple functions as one-line functions).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17m2h 4:8ec314f806ae 1 #ifndef DOODLER_H
el17m2h 4:8ec314f806ae 2 #define DOODLER_H
el17m2h 4:8ec314f806ae 3
el17m2h 4:8ec314f806ae 4 #include "mbed.h"
el17m2h 4:8ec314f806ae 5 #include "N5110.h"
el17m2h 4:8ec314f806ae 6 #include "Gamepad.h"
el17m2h 5:8814d6de77d0 7
el17m2h 24:67dc71a8f009 8 /** Doodler's class
el17m2h 29:15e9640646b7 9 @brief Class for the doodler
el17m2h 24:67dc71a8f009 10 @author Melissa Hartmann
el17m2h 24:67dc71a8f009 11 @date May 2019
el17m2h 24:67dc71a8f009 12 */
el17m2h 29:15e9640646b7 13 class Doodler
el17m2h 29:15e9640646b7 14 {
el17m2h 4:8ec314f806ae 15 public:
el17m2h 4:8ec314f806ae 16 Doodler();
el17m2h 4:8ec314f806ae 17 ~Doodler();
el17m2h 29:15e9640646b7 18 /**
el17m2h 26:d16a5b1e0ace 19 @brief Defines the initial position of the doodler
el17m2h 24:67dc71a8f009 20 @param float position_x uses float since the velocity will be added, which is not an integer.
el17m2h 24:67dc71a8f009 21 @param float position_y uses float since the velocity will be added, which is not an integer.
el17m2h 29:15e9640646b7 22 @param double velocity_y needs to be double in order for it to decelerate to a small value that
el17m2h 26:d16a5b1e0ace 23 approaches zero.
el17m2h 29:15e9640646b7 24 @details The intial position of the doodler is at the centre of the screen and the values are
el17m2h 29:15e9640646b7 25 gotten from the Engine class. It also defines the gravity as a positive vale greater than 1
el17m2h 26:d16a5b1e0ace 26 and the up object as a negative vale less than 1.
el17m2h 24:67dc71a8f009 27 */
el17m2h 23:9be87557b89a 28 void init(float position_x, float position_y, double velocity_y);
el17m2h 29:15e9640646b7 29
el17m2h 29:15e9640646b7 30 /**
el17m2h 24:67dc71a8f009 31 @brief Prints the doodler into the LCD screen
el17m2h 24:67dc71a8f009 32 @param N5110 &lcd
el17m2h 24:67dc71a8f009 33 @details The function draws a sprite of 13 x 15 bits that shows the image of the doodler
el17m2h 24:67dc71a8f009 34 */
el17m2h 29:15e9640646b7 35 void draw(N5110 &lcd);
el17m2h 29:15e9640646b7 36
el17m2h 29:15e9640646b7 37 /**
el17m2h 24:67dc71a8f009 38 @brief Updates the position of the doodler
el17m2h 26:d16a5b1e0ace 39 @param Direction d is gotten from the user input of the joystick and determines the movement of
el17m2h 29:15e9640646b7 40 the doodler in the x-direction. It moves left/right if the joystick directs left/right at an angle
el17m2h 26:d16a5b1e0ace 41 or not.
el17m2h 29:15e9640646b7 42 @param float mag is used to accelerate the movement of the doodler in the x-direction since it
el17m2h 26:d16a5b1e0ace 43 moves 5 frames * the magnitude of the joystick.
el17m2h 32:83f410c433c2 44 @details The function calls both the x-coordinate position update function and y-coordinate position update function.
el17m2h 24:67dc71a8f009 45 */
el17m2h 17:74de8c17ddac 46 void update(Direction d, float mag);
el17m2h 32:83f410c433c2 47
el17m2h 32:83f410c433c2 48 /**
el17m2h 32:83f410c433c2 49 @brief Updates the x-coordinate position of the doodler
el17m2h 32:83f410c433c2 50 @param Direction d is gotten from the user input of the joystick and determines the movement of
el17m2h 32:83f410c433c2 51 the doodler in the x-direction. It moves left/right if the joystick directs left/right at an angle
el17m2h 32:83f410c433c2 52 or not.
el17m2h 32:83f410c433c2 53 @param float mag is used to accelerate the movement of the doodler in the x-direction since it
el17m2h 32:83f410c433c2 54 moves 5 frames * the magnitude of the joystick.
el17m2h 32:83f410c433c2 55 @details It reads the input movement of joystick and defines the velocity_x as a variable dependent on the magnitude
el17m2h 32:83f410c433c2 56 of inclination read, so that the velocity changes accoordingly. It uses the direction input to decide in an if statement if the
el17m2h 32:83f410c433c2 57 position_x should increase or decrease in value. It then checks the doodler does not leave the screen rectangle (39 x 82) in
el17m2h 32:83f410c433c2 58 the x-direction by making it remain in the its position.
el17m2h 32:83f410c433c2 59 */
el17m2h 32:83f410c433c2 60 void update_x(Direction d, float mag);
el17m2h 32:83f410c433c2 61
el17m2h 32:83f410c433c2 62 /**
el17m2h 32:83f410c433c2 63 @brief Updates the y-coordinate position of the doodler
el17m2h 32:83f410c433c2 64 @details The function updates the y-coordinate position of the doodler. It has no input paramenters from the gamepad,
el17m2h 32:83f410c433c2 65 since it only depends on the floors below it. It checks the direction of the velocity (dependent on the collision
el17m2h 32:83f410c433c2 66 with the floors) to check the direction of the doodler's movement (depending on if it is jumping or falling). It also
el17m2h 32:83f410c433c2 67 checks the doodler remains within the y-coordinates of the screen (only top edge, because the bottom edge means the
el17m2h 32:83f410c433c2 68 game ends).
el17m2h 32:83f410c433c2 69 */
el17m2h 32:83f410c433c2 70 void update_y();
el17m2h 29:15e9640646b7 71
el17m2h 29:15e9640646b7 72 /**
el17m2h 29:15e9640646b7 73 @brief Function to check the doodler's y-coodinate velocity
el17m2h 29:15e9640646b7 74 @details The function checks the current velocity of the doodler and depending on its direction
el17m2h 29:15e9640646b7 75 (positive or negative) it will decide if the doodler's updated velocity will remain the same or
el17m2h 29:15e9640646b7 76 change direction (jump). If the velocity is positive, it means it is currently jumping, so it
el17m2h 29:15e9640646b7 77 should continue doing so but in a decreasing velocity (decelerating), which is why it is
el17m2h 29:15e9640646b7 78 multiplied times the _up constant (value less than 1). If the velocity is negative it means
el17m2h 29:15e9640646b7 79 it is falling downwards and increasing in velocity (accelerating). This is done by multiplying the
el17m2h 29:15e9640646b7 80 current velocity by the gravity constant value (greater than 1). Finally, if the velocity is 0, it
el17m2h 26:d16a5b1e0ace 81 means it has completely decelerated upwards and so it should begin to fall. To do so, the velocity
el17m2h 25:f122e1862cd1 82 is given the value of gravity (which is a positive value).
el17m2h 24:67dc71a8f009 83 */
el17m2h 29:15e9640646b7 84 void check_velocity();
el17m2h 29:15e9640646b7 85
el17m2h 29:15e9640646b7 86 /**
el17m2h 24:67dc71a8f009 87 @brief Returns the current doodler's velocity in the x-axis
el17m2h 24:67dc71a8f009 88 @details Gets the current value in the doodler's class for the doodler's velocity in the x-axis
el17m2h 24:67dc71a8f009 89 */
el17m2h 10:e1d2289705ef 90 float get_velocity_x();
el17m2h 29:15e9640646b7 91
el17m2h 29:15e9640646b7 92 /**
el17m2h 24:67dc71a8f009 93 @brief Returns the current doodler's velocity in the y-axis
el17m2h 29:15e9640646b7 94 @details Gets the current value in the doodler's class for the doodler's velocity in the y-axis. It is a
el17m2h 29:15e9640646b7 95 double value since the y-velocity is a double type.
el17m2h 24:67dc71a8f009 96 */
el17m2h 10:e1d2289705ef 97 double get_velocity_y();
el17m2h 29:15e9640646b7 98
el17m2h 29:15e9640646b7 99 /**
el17m2h 24:67dc71a8f009 100 @brief Returns the current doodler's position in the x-axis
el17m2h 24:67dc71a8f009 101 @details Gets the current value in the doodler's class for the doodler's position in the x-axis
el17m2h 24:67dc71a8f009 102 */
el17m2h 29:15e9640646b7 103 float get_position_x();
el17m2h 29:15e9640646b7 104
el17m2h 29:15e9640646b7 105 /**
el17m2h 24:67dc71a8f009 106 @brief Returns the current doodler's position in the y-axis
el17m2h 24:67dc71a8f009 107 @details Gets the current value in the doodler's class for the doodler's position in the y-axis
el17m2h 24:67dc71a8f009 108 */
el17m2h 29:15e9640646b7 109 float get_position_y();
el17m2h 29:15e9640646b7 110
el17m2h 29:15e9640646b7 111 /**
el17m2h 26:d16a5b1e0ace 112 @brief Sets the doodler's velocity in the Doodler's class to equal the inputed parameters
el17m2h 29:15e9640646b7 113 @param float vel_x
el17m2h 24:67dc71a8f009 114 @param float vel_y
el17m2h 29:15e9640646b7 115 @details The function sets the doodler's velocity in the doodler's class by making the current
el17m2h 26:d16a5b1e0ace 116 velocity equal to the inputed parameters
el17m2h 24:67dc71a8f009 117 */
el17m2h 14:529f798adae4 118 void set_velocity(float vel_x, double vel_y);
el17m2h 29:15e9640646b7 119
el17m2h 25:f122e1862cd1 120 /**
el17m2h 26:d16a5b1e0ace 121 @brief Sets the doodler's position in the Doodler's class to equal the inputed parameters
el17m2h 29:15e9640646b7 122 @param float pos_x
el17m2h 25:f122e1862cd1 123 @param float pos_y
el17m2h 29:15e9640646b7 124 @details The function sets the doodler's position in the doodler's class by making the current
el17m2h 26:d16a5b1e0ace 125 position equal the inputed parameters
el17m2h 24:67dc71a8f009 126 */
el17m2h 14:529f798adae4 127 void set_position(float pos_x, float pos_y);
el17m2h 29:15e9640646b7 128
el17m2h 4:8ec314f806ae 129 private:
el17m2h 14:529f798adae4 130 float _position_x;
el17m2h 14:529f798adae4 131 float _position_y;
el17m2h 10:e1d2289705ef 132 float _velocity_x;
el17m2h 10:e1d2289705ef 133 double _velocity_y;
el17m2h 32:83f410c433c2 134 double _gravity;
el17m2h 10:e1d2289705ef 135 double _up;
el17m2h 4:8ec314f806ae 136 };
el17m2h 4:8ec314f806ae 137 #endif