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
Doodler/Doodler.h@26:d16a5b1e0ace, 2019-05-08 (annotated)
- Committer:
- el17m2h
- Date:
- Wed May 08 17:24:35 2019 +0000
- Revision:
- 26:d16a5b1e0ace
- Parent:
- 25:f122e1862cd1
- Child:
- 29:15e9640646b7
Added comments for the documentation file.
Who changed what in which revision?
| User | Revision | Line number | New 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 | 24:67dc71a8f009 | 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 | 4:8ec314f806ae | 13 | class Doodler{ |
| el17m2h | 4:8ec314f806ae | 14 | public: |
| el17m2h | 4:8ec314f806ae | 15 | Doodler(); |
| el17m2h | 4:8ec314f806ae | 16 | ~Doodler(); |
| el17m2h | 24:67dc71a8f009 | 17 | /** |
| el17m2h | 26:d16a5b1e0ace | 18 | @brief Defines the initial position of the doodler |
| el17m2h | 24:67dc71a8f009 | 19 | @param float position_x uses float since the velocity will be added, which is not an integer. |
| el17m2h | 24:67dc71a8f009 | 20 | @param float position_y uses float since the velocity will be added, which is not an integer. |
| el17m2h | 26:d16a5b1e0ace | 21 | @param double velocity_y needs to be double in order for it to decelerate to a small value that |
| el17m2h | 26:d16a5b1e0ace | 22 | approaches zero. |
| el17m2h | 26:d16a5b1e0ace | 23 | @details The intial position of the doodler is at the centre of the screen and the values are |
| el17m2h | 26:d16a5b1e0ace | 24 | gotten from the Engine class. It also defines the gravity as a positive vale greater than 1 |
| el17m2h | 26:d16a5b1e0ace | 25 | and the up object as a negative vale less than 1. |
| el17m2h | 24:67dc71a8f009 | 26 | */ |
| el17m2h | 23:9be87557b89a | 27 | void init(float position_x, float position_y, double velocity_y); |
| el17m2h | 24:67dc71a8f009 | 28 | |
| el17m2h | 24:67dc71a8f009 | 29 | /** |
| el17m2h | 24:67dc71a8f009 | 30 | @brief Prints the doodler into the LCD screen |
| el17m2h | 24:67dc71a8f009 | 31 | @param N5110 &lcd |
| el17m2h | 24:67dc71a8f009 | 32 | @details The function draws a sprite of 13 x 15 bits that shows the image of the doodler |
| el17m2h | 24:67dc71a8f009 | 33 | */ |
| el17m2h | 8:90e789413e0b | 34 | void draw(N5110 &lcd); |
| el17m2h | 24:67dc71a8f009 | 35 | |
| el17m2h | 24:67dc71a8f009 | 36 | /** |
| el17m2h | 24:67dc71a8f009 | 37 | @brief Updates the position of the doodler |
| el17m2h | 26:d16a5b1e0ace | 38 | @param Direction d is gotten from the user input of the joystick and determines the movement of |
| el17m2h | 26:d16a5b1e0ace | 39 | the doodler in the x-direction. It moves left/right if the joystick directs left/right at an angle |
| el17m2h | 26:d16a5b1e0ace | 40 | or not. |
| el17m2h | 26:d16a5b1e0ace | 41 | @param float mag is used to accelerate the movement of the doodler in the x-direction since it |
| el17m2h | 26:d16a5b1e0ace | 42 | moves 5 frames * the magnitude of the joystick. |
| el17m2h | 24:67dc71a8f009 | 43 | @details The function checks the doodler does not leave the screen rectangle (30 x 83) in the |
| el17m2h | 26:d16a5b1e0ace | 44 | x-direction and checks the direction of the velocity to keep adding or substructing a value in |
| el17m2h | 26:d16a5b1e0ace | 45 | the y-direction (depending on if it is jumping or falling) |
| el17m2h | 24:67dc71a8f009 | 46 | */ |
| el17m2h | 17:74de8c17ddac | 47 | void update(Direction d, float mag); |
| el17m2h | 24:67dc71a8f009 | 48 | |
| el17m2h | 24:67dc71a8f009 | 49 | /** |
| el17m2h | 25:f122e1862cd1 | 50 | @brief Function to check the doodler's y-coodinate velocity |
| el17m2h | 26:d16a5b1e0ace | 51 | @details The function checks the current velocity of the doodler and depending on its direction |
| el17m2h | 26:d16a5b1e0ace | 52 | (positive or negative) it will decide if the doodler's updated velocity will remain the same or |
| el17m2h | 26:d16a5b1e0ace | 53 | change direction (jump). If the velocity is positive, it means it is currently jumping, so it |
| el17m2h | 26:d16a5b1e0ace | 54 | should continue doing so but in a decreasing velocity (decelerating), which is why it is |
| el17m2h | 26:d16a5b1e0ace | 55 | multiplied times the _up constant (value less than 1). If the velocity is negative it means |
| el17m2h | 26:d16a5b1e0ace | 56 | it is falling downwards and increasing in velocity (accelerating). This is done by multiplying the |
| el17m2h | 26:d16a5b1e0ace | 57 | current velocity by the gravity constant value (greater than 1). Finally, if the velocity is 0, it |
| el17m2h | 26:d16a5b1e0ace | 58 | means it has completely decelerated upwards and so it should begin to fall. To do so, the velocity |
| el17m2h | 25:f122e1862cd1 | 59 | is given the value of gravity (which is a positive value). |
| el17m2h | 24:67dc71a8f009 | 60 | */ |
| el17m2h | 24:67dc71a8f009 | 61 | void check_velocity(); |
| el17m2h | 24:67dc71a8f009 | 62 | |
| el17m2h | 24:67dc71a8f009 | 63 | /** |
| el17m2h | 24:67dc71a8f009 | 64 | @brief Returns the current doodler's velocity in the x-axis |
| el17m2h | 24:67dc71a8f009 | 65 | @details Gets the current value in the doodler's class for the doodler's velocity in the x-axis |
| el17m2h | 24:67dc71a8f009 | 66 | */ |
| el17m2h | 10:e1d2289705ef | 67 | float get_velocity_x(); |
| el17m2h | 24:67dc71a8f009 | 68 | |
| el17m2h | 24:67dc71a8f009 | 69 | /** |
| el17m2h | 24:67dc71a8f009 | 70 | @brief Returns the current doodler's velocity in the y-axis |
| el17m2h | 26:d16a5b1e0ace | 71 | @details Gets the current value in the doodler's class for the doodler's velocity in the y-axis. It is a |
| el17m2h | 26:d16a5b1e0ace | 72 | double value since the y-velocity is a double type. |
| el17m2h | 24:67dc71a8f009 | 73 | */ |
| el17m2h | 10:e1d2289705ef | 74 | double get_velocity_y(); |
| el17m2h | 24:67dc71a8f009 | 75 | |
| el17m2h | 24:67dc71a8f009 | 76 | /** |
| el17m2h | 24:67dc71a8f009 | 77 | @brief Returns the current doodler's position in the x-axis |
| el17m2h | 24:67dc71a8f009 | 78 | @details Gets the current value in the doodler's class for the doodler's position in the x-axis |
| el17m2h | 24:67dc71a8f009 | 79 | */ |
| el17m2h | 10:e1d2289705ef | 80 | float get_position_x(); |
| el17m2h | 24:67dc71a8f009 | 81 | |
| el17m2h | 24:67dc71a8f009 | 82 | /** |
| el17m2h | 24:67dc71a8f009 | 83 | @brief Returns the current doodler's position in the y-axis |
| el17m2h | 24:67dc71a8f009 | 84 | @details Gets the current value in the doodler's class for the doodler's position in the y-axis |
| el17m2h | 24:67dc71a8f009 | 85 | */ |
| el17m2h | 10:e1d2289705ef | 86 | float get_position_y(); |
| el17m2h | 24:67dc71a8f009 | 87 | |
| el17m2h | 24:67dc71a8f009 | 88 | /** |
| el17m2h | 26:d16a5b1e0ace | 89 | @brief Sets the doodler's velocity in the Doodler's class to equal the inputed parameters |
| el17m2h | 24:67dc71a8f009 | 90 | @param float vel_x |
| el17m2h | 24:67dc71a8f009 | 91 | @param float vel_y |
| el17m2h | 26:d16a5b1e0ace | 92 | @details The function sets the doodler's velocity in the doodler's class by making the current |
| el17m2h | 26:d16a5b1e0ace | 93 | velocity equal to the inputed parameters |
| el17m2h | 24:67dc71a8f009 | 94 | */ |
| el17m2h | 14:529f798adae4 | 95 | void set_velocity(float vel_x, double vel_y); |
| el17m2h | 24:67dc71a8f009 | 96 | |
| el17m2h | 25:f122e1862cd1 | 97 | /** |
| el17m2h | 26:d16a5b1e0ace | 98 | @brief Sets the doodler's position in the Doodler's class to equal the inputed parameters |
| el17m2h | 25:f122e1862cd1 | 99 | @param float pos_x |
| el17m2h | 25:f122e1862cd1 | 100 | @param float pos_y |
| el17m2h | 26:d16a5b1e0ace | 101 | @details The function sets the doodler's position in the doodler's class by making the current |
| el17m2h | 26:d16a5b1e0ace | 102 | position equal the inputed parameters |
| el17m2h | 24:67dc71a8f009 | 103 | */ |
| el17m2h | 14:529f798adae4 | 104 | void set_position(float pos_x, float pos_y); |
| el17m2h | 4:8ec314f806ae | 105 | |
| el17m2h | 4:8ec314f806ae | 106 | private: |
| el17m2h | 14:529f798adae4 | 107 | float _position_x; |
| el17m2h | 14:529f798adae4 | 108 | float _position_y; |
| el17m2h | 10:e1d2289705ef | 109 | float _velocity_x; |
| el17m2h | 10:e1d2289705ef | 110 | double _velocity_y; |
| el17m2h | 10:e1d2289705ef | 111 | double _gravity; |
| el17m2h | 10:e1d2289705ef | 112 | double _up; |
| el17m2h | 4:8ec314f806ae | 113 | }; |
| el17m2h | 4:8ec314f806ae | 114 | #endif |