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@24:67dc71a8f009, 2019-05-08 (annotated)
- Committer:
- el17m2h
- Date:
- Wed May 08 14:24:53 2019 +0000
- Revision:
- 24:67dc71a8f009
- Parent:
- 23:9be87557b89a
- Child:
- 25:f122e1862cd1
Added comments 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 | 24:67dc71a8f009 | 43 | @brief Check velocity |
| el17m2h | 24:67dc71a8f009 | 44 | @details The function checks the velocity of the |
| el17m2h | 24:67dc71a8f009 | 45 | if ((double)_velocity_y > 0.00){ // no jump |
| el17m2h | 24:67dc71a8f009 | 46 | _velocity_y = (double)_velocity_y*(double)_gravity; // falls accelerating |
| el17m2h | 24:67dc71a8f009 | 47 | } else if ( (double)_velocity_y == 0.00){ |
| el17m2h | 24:67dc71a8f009 | 48 | _velocity_y = (double)_gravity; |
| el17m2h | 24:67dc71a8f009 | 49 | } else if ((double)_velocity_y < 0.00){ |
| el17m2h | 24:67dc71a8f009 | 50 | _velocity_y = -((double)_velocity_y * (double)_up); // jumps decelerating upwards (0<_up<1 so _velocity.y reaches 0) |
| el17m2h | 24:67dc71a8f009 | 51 | if (fabs((double)_velocity_y) < 0.008){ // decelerated completely |
| el17m2h | 24:67dc71a8f009 | 52 | _velocity_y = 0.00; |
| el17m2h | 24:67dc71a8f009 | 53 | */ |
| el17m2h | 24:67dc71a8f009 | 54 | void check_velocity(); |
| el17m2h | 24:67dc71a8f009 | 55 | |
| el17m2h | 24:67dc71a8f009 | 56 | /** |
| el17m2h | 24:67dc71a8f009 | 57 | @brief Returns the current doodler's velocity in the x-axis |
| el17m2h | 24:67dc71a8f009 | 58 | @details Gets the current value in the doodler's class for the doodler's velocity in the x-axis |
| el17m2h | 24:67dc71a8f009 | 59 | */ |
| el17m2h | 10:e1d2289705ef | 60 | float get_velocity_x(); |
| el17m2h | 24:67dc71a8f009 | 61 | |
| el17m2h | 24:67dc71a8f009 | 62 | /** |
| el17m2h | 24:67dc71a8f009 | 63 | @brief Returns the current doodler's velocity in the y-axis |
| el17m2h | 24:67dc71a8f009 | 64 | @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 | 65 | */ |
| el17m2h | 10:e1d2289705ef | 66 | double get_velocity_y(); |
| el17m2h | 24:67dc71a8f009 | 67 | |
| el17m2h | 24:67dc71a8f009 | 68 | /** |
| el17m2h | 24:67dc71a8f009 | 69 | @brief Returns the current doodler's position in the x-axis |
| el17m2h | 24:67dc71a8f009 | 70 | @details Gets the current value in the doodler's class for the doodler's position in the x-axis |
| el17m2h | 24:67dc71a8f009 | 71 | */ |
| el17m2h | 10:e1d2289705ef | 72 | float get_position_x(); |
| el17m2h | 24:67dc71a8f009 | 73 | |
| el17m2h | 24:67dc71a8f009 | 74 | /** |
| el17m2h | 24:67dc71a8f009 | 75 | @brief Returns the current doodler's position in the y-axis |
| el17m2h | 24:67dc71a8f009 | 76 | @details Gets the current value in the doodler's class for the doodler's position in the y-axis |
| el17m2h | 24:67dc71a8f009 | 77 | */ |
| el17m2h | 10:e1d2289705ef | 78 | float get_position_y(); |
| el17m2h | 24:67dc71a8f009 | 79 | |
| el17m2h | 24:67dc71a8f009 | 80 | /** |
| el17m2h | 24:67dc71a8f009 | 81 | @brief |
| el17m2h | 24:67dc71a8f009 | 82 | @param float vel_x |
| el17m2h | 24:67dc71a8f009 | 83 | @param float vel_y |
| el17m2h | 24:67dc71a8f009 | 84 | @details |
| el17m2h | 24:67dc71a8f009 | 85 | */ |
| el17m2h | 14:529f798adae4 | 86 | void set_velocity(float vel_x, double vel_y); |
| el17m2h | 24:67dc71a8f009 | 87 | |
| el17m2h | 24:67dc71a8f009 | 88 | /** |
| el17m2h | 24:67dc71a8f009 | 89 | @brief |
| el17m2h | 24:67dc71a8f009 | 90 | @param |
| el17m2h | 24:67dc71a8f009 | 91 | @param |
| el17m2h | 24:67dc71a8f009 | 92 | @details |
| el17m2h | 24:67dc71a8f009 | 93 | */ |
| el17m2h | 14:529f798adae4 | 94 | void set_position(float pos_x, float pos_y); |
| el17m2h | 4:8ec314f806ae | 95 | |
| el17m2h | 4:8ec314f806ae | 96 | private: |
| el17m2h | 14:529f798adae4 | 97 | float _position_x; |
| el17m2h | 14:529f798adae4 | 98 | float _position_y; |
| el17m2h | 10:e1d2289705ef | 99 | float _velocity_x; |
| el17m2h | 10:e1d2289705ef | 100 | double _velocity_y; |
| el17m2h | 10:e1d2289705ef | 101 | double _gravity; |
| el17m2h | 10:e1d2289705ef | 102 | double _up; |
| el17m2h | 4:8ec314f806ae | 103 | }; |
| el17m2h | 4:8ec314f806ae | 104 | #endif |