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