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 FXOS8700CQ mbed-rtos
Game_one/Game_one.h@25:31111e6e13ad, 2019-04-29 (annotated)
- Committer:
- yfkwok
- Date:
- Mon Apr 29 20:59:49 2019 +0000
- Revision:
- 25:31111e6e13ad
- Parent:
- 20:50ad2dad310d
- Child:
- 29:75a05e9f0e8d
29/04/2019 - Class documentation update
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| yfkwok | 2:464c7e62d97d | 1 | #ifndef GAME_ONE_H |
| yfkwok | 2:464c7e62d97d | 2 | #define GAME_ONE_H |
| yfkwok | 2:464c7e62d97d | 3 | |
| yfkwok | 2:464c7e62d97d | 4 | #include "mbed.h" |
| yfkwok | 2:464c7e62d97d | 5 | #include "N5110.h" |
| yfkwok | 2:464c7e62d97d | 6 | #include "Gamepad.h" |
| yfkwok | 2:464c7e62d97d | 7 | #include "Coin.h" |
| yfkwok | 2:464c7e62d97d | 8 | #include "Object.h" |
| yfkwok | 2:464c7e62d97d | 9 | #include "Game_one_cha.h" |
| yfkwok | 2:464c7e62d97d | 10 | #include "Score.h" |
| yfkwok | 2:464c7e62d97d | 11 | |
| yfkwok | 25:31111e6e13ad | 12 | /** Game One Class |
| yfkwok | 25:31111e6e13ad | 13 | * @brief This class is the game engine for the first mini-game |
| yfkwok | 25:31111e6e13ad | 14 | * @version 1.0 |
| yfkwok | 25:31111e6e13ad | 15 | * @author Yiu Fai Kwok |
| yfkwok | 25:31111e6e13ad | 16 | * @date Match, 2019 |
| yfkwok | 25:31111e6e13ad | 17 | */ |
| yfkwok | 25:31111e6e13ad | 18 | |
| yfkwok | 2:464c7e62d97d | 19 | class Game_one |
| yfkwok | 2:464c7e62d97d | 20 | { |
| yfkwok | 2:464c7e62d97d | 21 | |
| yfkwok | 2:464c7e62d97d | 22 | public: |
| yfkwok | 17:5d8ff39a0e49 | 23 | |
| yfkwok | 17:5d8ff39a0e49 | 24 | /** Constructor */ |
| yfkwok | 2:464c7e62d97d | 25 | Game_one(); |
| yfkwok | 17:5d8ff39a0e49 | 26 | /** Deconstructor */ |
| yfkwok | 2:464c7e62d97d | 27 | ~Game_one(); |
| yfkwok | 2:464c7e62d97d | 28 | |
| yfkwok | 17:5d8ff39a0e49 | 29 | /** |
| yfkwok | 17:5d8ff39a0e49 | 30 | * @brief Initialize the class parameters |
| yfkwok | 17:5d8ff39a0e49 | 31 | * @param speed (int) |
| yfkwok | 17:5d8ff39a0e49 | 32 | * @param character cha (int) |
| yfkwok | 17:5d8ff39a0e49 | 33 | * @param ratio r (int) |
| yfkwok | 17:5d8ff39a0e49 | 34 | * @details Initialize the object speed (speed), the character sprite (cha) and the ratio (r) between coin and block |
| yfkwok | 17:5d8ff39a0e49 | 35 | */ |
| yfkwok | 2:464c7e62d97d | 36 | void init(int speed, int cha, int r); |
| yfkwok | 17:5d8ff39a0e49 | 37 | |
| yfkwok | 17:5d8ff39a0e49 | 38 | /** |
| yfkwok | 17:5d8ff39a0e49 | 39 | * @brief Render the lcd screen |
| yfkwok | 17:5d8ff39a0e49 | 40 | * @param character cha (int) |
| yfkwok | 17:5d8ff39a0e49 | 41 | * @details Render all objects in game, draw character sprite according to (cha) parameter |
| yfkwok | 17:5d8ff39a0e49 | 42 | */ |
| yfkwok | 2:464c7e62d97d | 43 | void render(N5110 &lcd, int cha); |
| yfkwok | 17:5d8ff39a0e49 | 44 | |
| yfkwok | 17:5d8ff39a0e49 | 45 | /** |
| yfkwok | 17:5d8ff39a0e49 | 46 | * @brief Read input from Gamepad |
| yfkwok | 17:5d8ff39a0e49 | 47 | * @details Read input from joystick on the Gamepad to determine direction and magnitude of character's motion |
| yfkwok | 17:5d8ff39a0e49 | 48 | */ |
| yfkwok | 2:464c7e62d97d | 49 | void read_input(Gamepad &pad); |
| yfkwok | 17:5d8ff39a0e49 | 50 | |
| yfkwok | 17:5d8ff39a0e49 | 51 | /** |
| yfkwok | 17:5d8ff39a0e49 | 52 | * @brief Update the lcd screen |
| yfkwok | 17:5d8ff39a0e49 | 53 | * @details Update the lcd screen according to the input and current state of the display |
| yfkwok | 17:5d8ff39a0e49 | 54 | */ |
| yfkwok | 2:464c7e62d97d | 55 | void update(Gamepad &pad, N5110 &lcd); |
| yfkwok | 17:5d8ff39a0e49 | 56 | |
| yfkwok | 17:5d8ff39a0e49 | 57 | /** |
| yfkwok | 17:5d8ff39a0e49 | 58 | * @brief Draw function for Game 1 |
| yfkwok | 17:5d8ff39a0e49 | 59 | * @param character cha (int) |
| yfkwok | 17:5d8ff39a0e49 | 60 | * @details Draw function of Game 1 which draw all objects and characters according to the changing variables of positions, alternative sprites and constant (cha) |
| yfkwok | 17:5d8ff39a0e49 | 61 | */ |
| yfkwok | 2:464c7e62d97d | 62 | void draw(N5110 &lcd, int cha); |
| yfkwok | 17:5d8ff39a0e49 | 63 | |
| yfkwok | 17:5d8ff39a0e49 | 64 | /** |
| yfkwok | 17:5d8ff39a0e49 | 65 | * @brief Get count value |
| yfkwok | 17:5d8ff39a0e49 | 66 | * @return The current count (int) |
| yfkwok | 17:5d8ff39a0e49 | 67 | * @details The function returns the number of coins that have appeared in the game to terminate the game loop once count reaches 10 |
| yfkwok | 17:5d8ff39a0e49 | 68 | */ |
| yfkwok | 2:464c7e62d97d | 69 | int get_count(); |
| yfkwok | 17:5d8ff39a0e49 | 70 | |
| yfkwok | 17:5d8ff39a0e49 | 71 | /** |
| yfkwok | 17:5d8ff39a0e49 | 72 | * @brief Print Scores on screen |
| yfkwok | 17:5d8ff39a0e49 | 73 | * @return The current score (int) |
| yfkwok | 17:5d8ff39a0e49 | 74 | * @details The function print the number of coins collected and spawned on the lcd screen |
| yfkwok | 17:5d8ff39a0e49 | 75 | */ |
| yfkwok | 2:464c7e62d97d | 76 | int print_scores(N5110 &lcd); |
| yfkwok | 17:5d8ff39a0e49 | 77 | |
| yfkwok | 17:5d8ff39a0e49 | 78 | /** |
| yfkwok | 17:5d8ff39a0e49 | 79 | * @brief Intruction |
| yfkwok | 17:5d8ff39a0e49 | 80 | * @details The function displays the instructions which describe game rules at the beginning of the game |
| yfkwok | 17:5d8ff39a0e49 | 81 | */ |
| yfkwok | 4:5bc9c4363d31 | 82 | void intro(Gamepad &pad, N5110 &lcd); |
| yfkwok | 2:464c7e62d97d | 83 | |
| yfkwok | 19:903d67bb0dea | 84 | /** |
| yfkwok | 19:903d67bb0dea | 85 | * @brief Set count |
| yfkwok | 19:903d67bb0dea | 86 | * @param count (int) |
| yfkwok | 19:903d67bb0dea | 87 | * @details The private function set the value for private member _count |
| yfkwok | 19:903d67bb0dea | 88 | */ |
| yfkwok | 19:903d67bb0dea | 89 | void set_count(int count); |
| yfkwok | 19:903d67bb0dea | 90 | |
| yfkwok | 19:903d67bb0dea | 91 | /** |
| yfkwok | 19:903d67bb0dea | 92 | * @brief Update parameter alt |
| yfkwok | 19:903d67bb0dea | 93 | * @return current value of alt (int) |
| yfkwok | 19:903d67bb0dea | 94 | * @details The function flips the value of alt to draw the alternative sprite of character to create a running animation |
| yfkwok | 19:903d67bb0dea | 95 | */ |
| yfkwok | 19:903d67bb0dea | 96 | int update_alt(); |
| yfkwok | 19:903d67bb0dea | 97 | |
| yfkwok | 19:903d67bb0dea | 98 | /** |
| yfkwok | 19:903d67bb0dea | 99 | * @brief Set parameter _alt |
| yfkwok | 19:903d67bb0dea | 100 | * @param alt (int) |
| yfkwok | 19:903d67bb0dea | 101 | * @details The function sets the value for private memeber _alt |
| yfkwok | 19:903d67bb0dea | 102 | */ |
| yfkwok | 19:903d67bb0dea | 103 | void set_alt(int alt); |
| yfkwok | 19:903d67bb0dea | 104 | |
| yfkwok | 2:464c7e62d97d | 105 | private: |
| yfkwok | 2:464c7e62d97d | 106 | |
| yfkwok | 17:5d8ff39a0e49 | 107 | /** |
| yfkwok | 17:5d8ff39a0e49 | 108 | * @brief Check coin collection |
| yfkwok | 17:5d8ff39a0e49 | 109 | * @details The private function checks if the coin has been collected, update the counter, the score and initiates new object in the game |
| yfkwok | 17:5d8ff39a0e49 | 110 | */ |
| yfkwok | 2:464c7e62d97d | 111 | void check_player_collect(Gamepad &pad); |
| yfkwok | 17:5d8ff39a0e49 | 112 | |
| yfkwok | 17:5d8ff39a0e49 | 113 | /** |
| yfkwok | 17:5d8ff39a0e49 | 114 | * @brief Check block collision |
| yfkwok | 17:5d8ff39a0e49 | 115 | * @details The private function checks if the block is collided, terminates the game loop and display the gameover screen |
| yfkwok | 17:5d8ff39a0e49 | 116 | */ |
| yfkwok | 2:464c7e62d97d | 117 | void check_player_collide(Gamepad &pad, N5110 &lcd); |
| yfkwok | 17:5d8ff39a0e49 | 118 | |
| yfkwok | 17:5d8ff39a0e49 | 119 | /** |
| yfkwok | 17:5d8ff39a0e49 | 120 | * @brief Check coin missed |
| yfkwok | 17:5d8ff39a0e49 | 121 | * @details The private function checks if the coin has been missed, update the counter, and initiates new object in the game |
| yfkwok | 17:5d8ff39a0e49 | 122 | */ |
| yfkwok | 2:464c7e62d97d | 123 | void check_miss_coin(Gamepad &pad); |
| yfkwok | 17:5d8ff39a0e49 | 124 | |
| yfkwok | 17:5d8ff39a0e49 | 125 | /** |
| yfkwok | 17:5d8ff39a0e49 | 126 | * @brief Check block missed |
| yfkwok | 17:5d8ff39a0e49 | 127 | * @details The private function checks if the block has been missed, then initiates new object in the game |
| yfkwok | 17:5d8ff39a0e49 | 128 | */ |
| yfkwok | 2:464c7e62d97d | 129 | void check_miss_block(Gamepad &pad); |
| yfkwok | 17:5d8ff39a0e49 | 130 | |
| yfkwok | 17:5d8ff39a0e49 | 131 | /** |
| yfkwok | 17:5d8ff39a0e49 | 132 | * @brief Gameover screen |
| yfkwok | 17:5d8ff39a0e49 | 133 | * @details The private function initiates the gameover screen and termiate term |
| yfkwok | 17:5d8ff39a0e49 | 134 | */ |
| yfkwok | 2:464c7e62d97d | 135 | void gameover(N5110 &lcd, Gamepad &pad); |
| yfkwok | 17:5d8ff39a0e49 | 136 | |
| yfkwok | 20:50ad2dad310d | 137 | /** |
| yfkwok | 20:50ad2dad310d | 138 | * @brief Moving background |
| yfkwok | 20:50ad2dad310d | 139 | * @param position x (int) |
| yfkwok | 20:50ad2dad310d | 140 | * @details The private function draws the moving background according to parameter x |
| yfkwok | 20:50ad2dad310d | 141 | */ |
| yfkwok | 20:50ad2dad310d | 142 | void draw_background(int x, N5110 &lcd); |
| yfkwok | 20:50ad2dad310d | 143 | |
| yfkwok | 20:50ad2dad310d | 144 | /** |
| yfkwok | 20:50ad2dad310d | 145 | * @brief Stationary background |
| yfkwok | 20:50ad2dad310d | 146 | * @details The private function draws the stationary background for further objects |
| yfkwok | 20:50ad2dad310d | 147 | */ |
| yfkwok | 20:50ad2dad310d | 148 | void background(N5110 &lcd); |
| yfkwok | 20:50ad2dad310d | 149 | |
| yfkwok | 2:464c7e62d97d | 150 | Score music; |
| yfkwok | 2:464c7e62d97d | 151 | Game_one_cha _p1; |
| yfkwok | 2:464c7e62d97d | 152 | |
| yfkwok | 2:464c7e62d97d | 153 | int _speed; |
| yfkwok | 2:464c7e62d97d | 154 | int _cha; |
| yfkwok | 2:464c7e62d97d | 155 | int _rand; |
| yfkwok | 2:464c7e62d97d | 156 | |
| yfkwok | 2:464c7e62d97d | 157 | // x positions of the player |
| yfkwok | 2:464c7e62d97d | 158 | int _p1x; |
| yfkwok | 20:50ad2dad310d | 159 | int _x; |
| yfkwok | 2:464c7e62d97d | 160 | |
| yfkwok | 2:464c7e62d97d | 161 | Coin _coin; |
| yfkwok | 2:464c7e62d97d | 162 | Object _block; |
| yfkwok | 2:464c7e62d97d | 163 | |
| yfkwok | 2:464c7e62d97d | 164 | Direction _d; |
| yfkwok | 2:464c7e62d97d | 165 | float _mag; |
| yfkwok | 2:464c7e62d97d | 166 | int _count; |
| yfkwok | 2:464c7e62d97d | 167 | int _alt; |
| yfkwok | 2:464c7e62d97d | 168 | int _type; |
| yfkwok | 2:464c7e62d97d | 169 | |
| yfkwok | 2:464c7e62d97d | 170 | }; |
| yfkwok | 2:464c7e62d97d | 171 | |
| yfkwok | 2:464c7e62d97d | 172 | #endif |