Game codes for Pokemon Academy Yiu Fai Kwok - 201198802 I have read the University Regulations on Plagiarism and state that the work covered by this declaration is my own and does not contain any unacknowledged work from other sources.
Dependencies: mbed FXOS8700CQ mbed-rtos
Game_one/Game_one.h@34:3ddfaa217eca, 2019-05-09 (annotated)
- Committer:
- yfkwok
- Date:
- Thu May 09 00:41:05 2019 +0000
- Revision:
- 34:3ddfaa217eca
- Parent:
- 30:0ff3bede5307
09/05/2019 - Last commit before submission
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 | 30:0ff3bede5307 | 14 | * @version 2.0 |
yfkwok | 25:31111e6e13ad | 15 | * @author Yiu Fai Kwok |
yfkwok | 30:0ff3bede5307 | 16 | * @date May, 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 Update parameter alt |
yfkwok | 19:903d67bb0dea | 86 | * @return current value of alt (int) |
yfkwok | 19:903d67bb0dea | 87 | * @details The function flips the value of alt to draw the alternative sprite of character to create a running animation |
yfkwok | 19:903d67bb0dea | 88 | */ |
yfkwok | 19:903d67bb0dea | 89 | int update_alt(); |
yfkwok | 19:903d67bb0dea | 90 | |
yfkwok | 2:464c7e62d97d | 91 | private: |
yfkwok | 2:464c7e62d97d | 92 | |
yfkwok | 17:5d8ff39a0e49 | 93 | /** |
yfkwok | 17:5d8ff39a0e49 | 94 | * @brief Check coin collection |
yfkwok | 17:5d8ff39a0e49 | 95 | * @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 | 96 | */ |
yfkwok | 2:464c7e62d97d | 97 | void check_player_collect(Gamepad &pad); |
yfkwok | 17:5d8ff39a0e49 | 98 | |
yfkwok | 17:5d8ff39a0e49 | 99 | /** |
yfkwok | 17:5d8ff39a0e49 | 100 | * @brief Check block collision |
yfkwok | 17:5d8ff39a0e49 | 101 | * @details The private function checks if the block is collided, terminates the game loop and display the gameover screen |
yfkwok | 17:5d8ff39a0e49 | 102 | */ |
yfkwok | 2:464c7e62d97d | 103 | void check_player_collide(Gamepad &pad, N5110 &lcd); |
yfkwok | 17:5d8ff39a0e49 | 104 | |
yfkwok | 17:5d8ff39a0e49 | 105 | /** |
yfkwok | 17:5d8ff39a0e49 | 106 | * @brief Check coin missed |
yfkwok | 17:5d8ff39a0e49 | 107 | * @details The private function checks if the coin has been missed, update the counter, and initiates new object in the game |
yfkwok | 17:5d8ff39a0e49 | 108 | */ |
yfkwok | 2:464c7e62d97d | 109 | void check_miss_coin(Gamepad &pad); |
yfkwok | 17:5d8ff39a0e49 | 110 | |
yfkwok | 17:5d8ff39a0e49 | 111 | /** |
yfkwok | 17:5d8ff39a0e49 | 112 | * @brief Check block missed |
yfkwok | 17:5d8ff39a0e49 | 113 | * @details The private function checks if the block has been missed, then initiates new object in the game |
yfkwok | 17:5d8ff39a0e49 | 114 | */ |
yfkwok | 2:464c7e62d97d | 115 | void check_miss_block(Gamepad &pad); |
yfkwok | 17:5d8ff39a0e49 | 116 | |
yfkwok | 17:5d8ff39a0e49 | 117 | /** |
yfkwok | 17:5d8ff39a0e49 | 118 | * @brief Gameover screen |
yfkwok | 17:5d8ff39a0e49 | 119 | * @details The private function initiates the gameover screen and termiate term |
yfkwok | 17:5d8ff39a0e49 | 120 | */ |
yfkwok | 2:464c7e62d97d | 121 | void gameover(N5110 &lcd, Gamepad &pad); |
yfkwok | 17:5d8ff39a0e49 | 122 | |
yfkwok | 20:50ad2dad310d | 123 | /** |
yfkwok | 20:50ad2dad310d | 124 | * @brief Moving background |
yfkwok | 20:50ad2dad310d | 125 | * @param position x (int) |
yfkwok | 20:50ad2dad310d | 126 | * @details The private function draws the moving background according to parameter x |
yfkwok | 20:50ad2dad310d | 127 | */ |
yfkwok | 20:50ad2dad310d | 128 | void draw_background(int x, N5110 &lcd); |
yfkwok | 20:50ad2dad310d | 129 | |
yfkwok | 20:50ad2dad310d | 130 | /** |
yfkwok | 20:50ad2dad310d | 131 | * @brief Stationary background |
yfkwok | 20:50ad2dad310d | 132 | * @details The private function draws the stationary background for further objects |
yfkwok | 20:50ad2dad310d | 133 | */ |
yfkwok | 20:50ad2dad310d | 134 | void background(N5110 &lcd); |
yfkwok | 20:50ad2dad310d | 135 | |
yfkwok | 2:464c7e62d97d | 136 | Score music; |
yfkwok | 2:464c7e62d97d | 137 | Game_one_cha _p1; |
yfkwok | 2:464c7e62d97d | 138 | |
yfkwok | 2:464c7e62d97d | 139 | int _speed; |
yfkwok | 2:464c7e62d97d | 140 | int _cha; |
yfkwok | 2:464c7e62d97d | 141 | int _rand; |
yfkwok | 2:464c7e62d97d | 142 | |
yfkwok | 2:464c7e62d97d | 143 | // x positions of the player |
yfkwok | 2:464c7e62d97d | 144 | int _p1x; |
yfkwok | 20:50ad2dad310d | 145 | int _x; |
yfkwok | 2:464c7e62d97d | 146 | |
yfkwok | 2:464c7e62d97d | 147 | Coin _coin; |
yfkwok | 2:464c7e62d97d | 148 | Object _block; |
yfkwok | 2:464c7e62d97d | 149 | |
yfkwok | 2:464c7e62d97d | 150 | Direction _d; |
yfkwok | 2:464c7e62d97d | 151 | float _mag; |
yfkwok | 2:464c7e62d97d | 152 | int _count; |
yfkwok | 2:464c7e62d97d | 153 | int _alt; |
yfkwok | 2:464c7e62d97d | 154 | int _type; |
yfkwok | 2:464c7e62d97d | 155 | |
yfkwok | 2:464c7e62d97d | 156 | }; |
yfkwok | 2:464c7e62d97d | 157 | |
yfkwok | 2:464c7e62d97d | 158 | #endif |