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
Floors/Floors.h@35:b99b563c3eb6, 2019-05-09 (annotated)
- Committer:
- el17m2h
- Date:
- Thu May 09 14:17:12 2019 +0000
- Revision:
- 35:b99b563c3eb6
- Parent:
- 31:5c4acae51026
- Child:
- 36:0c852c5ade4b
Finished comments on floor file
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17m2h | 1:0001cb3eb053 | 1 | #ifndef FLOORS_H |
el17m2h | 1:0001cb3eb053 | 2 | #define FLOORS_H |
el17m2h | 1:0001cb3eb053 | 3 | |
el17m2h | 1:0001cb3eb053 | 4 | #include "mbed.h" |
el17m2h | 1:0001cb3eb053 | 5 | #include "N5110.h" |
el17m2h | 1:0001cb3eb053 | 6 | #include "Gamepad.h" |
el17m2h | 20:a359092079b0 | 7 | #include "Enemy.h" |
el17m2h | 8:90e789413e0b | 8 | |
el17m2h | 26:d16a5b1e0ace | 9 | /** Floor class |
el17m2h | 26:d16a5b1e0ace | 10 | @brief Class for the floor |
el17m2h | 24:67dc71a8f009 | 11 | @author Melissa Hartmann |
el17m2h | 24:67dc71a8f009 | 12 | @date May 2019 |
el17m2h | 24:67dc71a8f009 | 13 | */ |
el17m2h | 29:15e9640646b7 | 14 | class Floors |
el17m2h | 29:15e9640646b7 | 15 | { |
el17m2h | 1:0001cb3eb053 | 16 | public: |
el17m2h | 1:0001cb3eb053 | 17 | Floors(); |
el17m2h | 1:0001cb3eb053 | 18 | ~Floors(); |
el17m2h | 29:15e9640646b7 | 19 | |
el17m2h | 29:15e9640646b7 | 20 | /** |
el17m2h | 26:d16a5b1e0ace | 21 | @brief Defines the initial position of the floor, its width and height |
el17m2h | 29:15e9640646b7 | 22 | @param int y |
el17m2h | 29:15e9640646b7 | 23 | @param int width |
el17m2h | 26:d16a5b1e0ace | 24 | @param int height |
el17m2h | 29:15e9640646b7 | 25 | @details The x-coordinate is initially random and excludes the space 30-40 so that the doodler falls |
el17m2h | 29:15e9640646b7 | 26 | to a floor that is set to be at the bottom center (instead of a random position) in the engine cpp |
el17m2h | 29:15e9640646b7 | 27 | (to make sure there is always a stating point position for the doodler). This is done by using a |
el17m2h | 29:15e9640646b7 | 28 | decision object to choose which randomly generated x-coordinate position the doodler will have |
el17m2h | 29:15e9640646b7 | 29 | (either at the left side or the right side). The y-coordinate position is inputed from the engine |
el17m2h | 29:15e9640646b7 | 30 | cpp and kept the same. |
el17m2h | 29:15e9640646b7 | 31 | */ |
el17m2h | 11:2041290b5a74 | 32 | void init(int y, int width, int height); |
el17m2h | 29:15e9640646b7 | 33 | |
el17m2h | 29:15e9640646b7 | 34 | /** |
el17m2h | 26:d16a5b1e0ace | 35 | @brief Prints the floor into the LCD screen |
el17m2h | 26:d16a5b1e0ace | 36 | @param N5110 &lcd |
el17m2h | 26:d16a5b1e0ace | 37 | @details The function draws a 14 x 1 rectangle |
el17m2h | 24:67dc71a8f009 | 38 | */ |
el17m2h | 1:0001cb3eb053 | 39 | void draw(N5110 &lcd); |
el17m2h | 29:15e9640646b7 | 40 | |
el17m2h | 29:15e9640646b7 | 41 | /** |
el17m2h | 26:d16a5b1e0ace | 42 | @brief Updates the position of the floor |
el17m2h | 29:15e9640646b7 | 43 | @param float doodler_pos_y is inputed into the function to decides if the floor should move |
el17m2h | 26:d16a5b1e0ace | 44 | or remain at its position. |
el17m2h | 29:15e9640646b7 | 45 | @details The function first checks if the position should change, which occurs if the doodler's position is above |
el17m2h | 29:15e9640646b7 | 46 | the middle of the screen's height (x-coordinate less than 25). If it is so, the floor will shift downwards (add 1 to |
el17m2h | 26:d16a5b1e0ace | 47 | the y-coordinate). The function then checks if the floor has reached the bottom of the screen (y-coordinate over 45) |
el17m2h | 29:15e9640646b7 | 48 | and if so, the floor will re-appear at the top of the screen (y-coordinate = 9) and at a random x-coordinate position, |
el17m2h | 29:15e9640646b7 | 49 | making there be 6 floors always on the screen. |
el17m2h | 24:67dc71a8f009 | 50 | */ |
el17m2h | 29:15e9640646b7 | 51 | void update(float doodler_pos_x, float doodler_pos_y, float _bullet_pos_x, float _bullet_pos_y); |
el17m2h | 29:15e9640646b7 | 52 | |
el17m2h | 35:b99b563c3eb6 | 53 | /** |
el17m2h | 35:b99b563c3eb6 | 54 | @brief Function to check if doodler or bullet have collided with the enemy |
el17m2h | 35:b99b563c3eb6 | 55 | @param float _bullet_pos_x |
el17m2h | 35:b99b563c3eb6 | 56 | @param float _bullet_pos_y |
el17m2h | 35:b99b563c3eb6 | 57 | @details Gets the current values of doodler (already defined as private variables) and the bullet (inputed to the |
el17m2h | 35:b99b563c3eb6 | 58 | function) in order to compare it with the position of the enemy. If they collide, the end_game decision variable will |
el17m2h | 35:b99b563c3eb6 | 59 | indicate if the game should end, or if the bullet hit the enemy, the game will continue but the enemy will be erased. |
el17m2h | 35:b99b563c3eb6 | 60 | */ |
el17m2h | 29:15e9640646b7 | 61 | void check_enemy(float _bullet_pos_x, float _bullet_pos_y); |
el17m2h | 29:15e9640646b7 | 62 | |
el17m2h | 29:15e9640646b7 | 63 | /** |
el17m2h | 26:d16a5b1e0ace | 64 | @brief Returns the current floor's position as a vector |
el17m2h | 26:d16a5b1e0ace | 65 | @details Gets the current value in the floor's class for the position |
el17m2h | 24:67dc71a8f009 | 66 | */ |
el17m2h | 29:15e9640646b7 | 67 | Vector2D get_position(); |
el17m2h | 29:15e9640646b7 | 68 | |
el17m2h | 26:d16a5b1e0ace | 69 | /** |
el17m2h | 26:d16a5b1e0ace | 70 | @brief Sets the floor's position in the Floor's class to equal the inputed vector parameter |
el17m2h | 26:d16a5b1e0ace | 71 | @param Vector2D pos is inputed to define the new position |
el17m2h | 29:15e9640646b7 | 72 | @details The function sets the floor's position by making the current position equal the inputed |
el17m2h | 26:d16a5b1e0ace | 73 | vector parameter to the function. |
el17m2h | 24:67dc71a8f009 | 74 | */ |
el17m2h | 14:529f798adae4 | 75 | void set_position(Vector2D pos); // mutators |
el17m2h | 31:5c4acae51026 | 76 | |
el17m2h | 35:b99b563c3eb6 | 77 | /** |
el17m2h | 35:b99b563c3eb6 | 78 | @brief Returns a true/false statement that is called on engine to decide if game should end or not |
el17m2h | 35:b99b563c3eb6 | 79 | @details The function can be called in the engine to check if the game should end or not (if the doodler has collided |
el17m2h | 35:b99b563c3eb6 | 80 | with the enemy) |
el17m2h | 35:b99b563c3eb6 | 81 | */ |
el17m2h | 31:5c4acae51026 | 82 | bool get_end_game(); |
el17m2h | 29:15e9640646b7 | 83 | |
el17m2h | 1:0001cb3eb053 | 84 | private: |
el17m2h | 1:0001cb3eb053 | 85 | int _height; |
el17m2h | 1:0001cb3eb053 | 86 | int _width; |
el17m2h | 14:529f798adae4 | 87 | Vector2D _position; |
el17m2h | 29:15e9640646b7 | 88 | Enemy eny; |
el17m2h | 31:5c4acae51026 | 89 | Vector2D enemy_position; |
el17m2h | 29:15e9640646b7 | 90 | bool put_enemy; |
el17m2h | 31:5c4acae51026 | 91 | bool end_game; |
el17m2h | 20:a359092079b0 | 92 | int place; |
el17m2h | 29:15e9640646b7 | 93 | float _doodler_pos_x; |
el17m2h | 29:15e9640646b7 | 94 | float _doodler_pos_y; |
el17m2h | 29:15e9640646b7 | 95 | |
el17m2h | 1:0001cb3eb053 | 96 | }; |
el17m2h | 1:0001cb3eb053 | 97 | #endif |