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