![](/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_two/Game_two.h@19:903d67bb0dea, 2019-04-21 (annotated)
- Committer:
- yfkwok
- Date:
- Sun Apr 21 12:14:59 2019 +0000
- Revision:
- 19:903d67bb0dea
- Parent:
- 14:abe64fe0b6a5
- Child:
- 25:31111e6e13ad
21/04/2019 - Documentation for all the classes created for the game
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yfkwok | 19:903d67bb0dea | 1 | /** Game Two Class |
yfkwok | 19:903d67bb0dea | 2 | * @brief This class is the game engine for the second mini-game |
yfkwok | 19:903d67bb0dea | 3 | * @version 1.0 |
yfkwok | 19:903d67bb0dea | 4 | * @author Yiu Fai Kwok |
yfkwok | 19:903d67bb0dea | 5 | * @date April, 2019 |
yfkwok | 19:903d67bb0dea | 6 | */ |
yfkwok | 13:02002658e718 | 7 | #ifndef GAME_TWO_H |
yfkwok | 13:02002658e718 | 8 | #define GAME_TWO_H |
yfkwok | 13:02002658e718 | 9 | |
yfkwok | 13:02002658e718 | 10 | #include "mbed.h" |
yfkwok | 13:02002658e718 | 11 | #include "N5110.h" |
yfkwok | 13:02002658e718 | 12 | #include "Gamepad.h" |
yfkwok | 13:02002658e718 | 13 | #include "Score.h" |
yfkwok | 13:02002658e718 | 14 | #include "FXOS8700CQ.h" |
yfkwok | 14:abe64fe0b6a5 | 15 | #include "Game_two_cha.h" |
yfkwok | 14:abe64fe0b6a5 | 16 | #include "Insta.h" |
yfkwok | 14:abe64fe0b6a5 | 17 | #include "Facebook.h" |
yfkwok | 14:abe64fe0b6a5 | 18 | #include "Twitter.h" |
yfkwok | 14:abe64fe0b6a5 | 19 | #include "YouTube.h" |
yfkwok | 13:02002658e718 | 20 | |
yfkwok | 13:02002658e718 | 21 | class Game_two |
yfkwok | 13:02002658e718 | 22 | { |
yfkwok | 13:02002658e718 | 23 | |
yfkwok | 13:02002658e718 | 24 | public: |
yfkwok | 19:903d67bb0dea | 25 | |
yfkwok | 19:903d67bb0dea | 26 | /** Constructor */ |
yfkwok | 13:02002658e718 | 27 | Game_two(); |
yfkwok | 19:903d67bb0dea | 28 | /** Deconstructor */ |
yfkwok | 13:02002658e718 | 29 | ~Game_two(); |
yfkwok | 19:903d67bb0dea | 30 | |
yfkwok | 19:903d67bb0dea | 31 | /** |
yfkwok | 19:903d67bb0dea | 32 | * @brief Initialize the class parameters |
yfkwok | 19:903d67bb0dea | 33 | * @param speed (int) |
yfkwok | 19:903d67bb0dea | 34 | * @param character cha (int) |
yfkwok | 19:903d67bb0dea | 35 | * @param ratio r (int) |
yfkwok | 19:903d67bb0dea | 36 | * @details Initialize the object speed (speed), the character sprite (cha) and the ratio (r) between how often YouTube icon will appear |
yfkwok | 19:903d67bb0dea | 37 | */ |
yfkwok | 13:02002658e718 | 38 | void init(int speed, int cha, int r); |
yfkwok | 19:903d67bb0dea | 39 | |
yfkwok | 19:903d67bb0dea | 40 | /** |
yfkwok | 19:903d67bb0dea | 41 | * @brief Render the lcd screen |
yfkwok | 19:903d67bb0dea | 42 | * @param character cha (int) |
yfkwok | 19:903d67bb0dea | 43 | * @details Render all objects in game, draw character sprite according to (cha) parameter |
yfkwok | 19:903d67bb0dea | 44 | */ |
yfkwok | 14:abe64fe0b6a5 | 45 | void render(N5110 &lcd, int cha); |
yfkwok | 19:903d67bb0dea | 46 | |
yfkwok | 19:903d67bb0dea | 47 | /** |
yfkwok | 19:903d67bb0dea | 48 | * @brief Read input from FXOS8700CQ |
yfkwok | 19:903d67bb0dea | 49 | * @details Read input from accelerometer on the Gamepad to determine direction and magnitude of character's motion |
yfkwok | 19:903d67bb0dea | 50 | */ |
yfkwok | 14:abe64fe0b6a5 | 51 | void read_input(FXOS8700CQ &device); |
yfkwok | 19:903d67bb0dea | 52 | |
yfkwok | 19:903d67bb0dea | 53 | /** |
yfkwok | 19:903d67bb0dea | 54 | * @brief Update the lcd screen |
yfkwok | 19:903d67bb0dea | 55 | * @details Update the lcd screen according to the input and current state of the display |
yfkwok | 19:903d67bb0dea | 56 | */ |
yfkwok | 14:abe64fe0b6a5 | 57 | void update(Gamepad &pad, N5110 &lcd, int cha); |
yfkwok | 19:903d67bb0dea | 58 | |
yfkwok | 19:903d67bb0dea | 59 | /** |
yfkwok | 19:903d67bb0dea | 60 | * @brief Draw function for Game 1 |
yfkwok | 19:903d67bb0dea | 61 | * @param character cha (int) |
yfkwok | 19:903d67bb0dea | 62 | * @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 | 19:903d67bb0dea | 63 | */ |
yfkwok | 14:abe64fe0b6a5 | 64 | void draw(N5110 &lcd, int cha); |
yfkwok | 19:903d67bb0dea | 65 | |
yfkwok | 19:903d67bb0dea | 66 | /** |
yfkwok | 19:903d67bb0dea | 67 | * @brief Get count value |
yfkwok | 19:903d67bb0dea | 68 | * @return The current count (int) |
yfkwok | 19:903d67bb0dea | 69 | * @details The function returns the number of coins that have appeared in the game to terminate the game loop once count reaches 10 |
yfkwok | 19:903d67bb0dea | 70 | */ |
yfkwok | 14:abe64fe0b6a5 | 71 | int get_count(); |
yfkwok | 19:903d67bb0dea | 72 | |
yfkwok | 19:903d67bb0dea | 73 | /** |
yfkwok | 19:903d67bb0dea | 74 | * @brief Update parameter alt |
yfkwok | 19:903d67bb0dea | 75 | * @return current value of alt (int) |
yfkwok | 19:903d67bb0dea | 76 | * @details The function flips the value of alt to draw the alternative sprite of character to create a running animation |
yfkwok | 19:903d67bb0dea | 77 | */ |
yfkwok | 14:abe64fe0b6a5 | 78 | int update_alt(); |
yfkwok | 19:903d67bb0dea | 79 | |
yfkwok | 19:903d67bb0dea | 80 | /** |
yfkwok | 19:903d67bb0dea | 81 | * @brief Set parameter _alt |
yfkwok | 19:903d67bb0dea | 82 | * @param alt (int) |
yfkwok | 19:903d67bb0dea | 83 | * @details The function sets the value for private memeber _alt |
yfkwok | 19:903d67bb0dea | 84 | */ |
yfkwok | 14:abe64fe0b6a5 | 85 | void set_alt(int alt); |
yfkwok | 19:903d67bb0dea | 86 | |
yfkwok | 19:903d67bb0dea | 87 | /** |
yfkwok | 19:903d67bb0dea | 88 | * @brief Intruction |
yfkwok | 19:903d67bb0dea | 89 | * @details The function displays the instructions which describe game rules at the beginning of the game |
yfkwok | 19:903d67bb0dea | 90 | */ |
yfkwok | 14:abe64fe0b6a5 | 91 | void intro(Gamepad &pad, N5110 &lcd); |
yfkwok | 13:02002658e718 | 92 | |
yfkwok | 19:903d67bb0dea | 93 | /** |
yfkwok | 19:903d67bb0dea | 94 | * @brief Set count |
yfkwok | 19:903d67bb0dea | 95 | * @param count (int) |
yfkwok | 19:903d67bb0dea | 96 | * @details The private function set the value for private member _count |
yfkwok | 19:903d67bb0dea | 97 | */ |
yfkwok | 19:903d67bb0dea | 98 | void set_count(int count); |
yfkwok | 19:903d67bb0dea | 99 | |
yfkwok | 13:02002658e718 | 100 | private: |
yfkwok | 19:903d67bb0dea | 101 | |
yfkwok | 19:903d67bb0dea | 102 | /** |
yfkwok | 19:903d67bb0dea | 103 | * @brief Check instagram collision |
yfkwok | 19:903d67bb0dea | 104 | * @param character cha (int) |
yfkwok | 19:903d67bb0dea | 105 | * @details The private function checks if instagram is collided, takes in the character value to determine the size of the hitbox, terminates the game loop and display the gameover screen |
yfkwok | 19:903d67bb0dea | 106 | */ |
yfkwok | 14:abe64fe0b6a5 | 107 | void check_insta_collide(Gamepad &pad, N5110 &lcd, int cha); |
yfkwok | 19:903d67bb0dea | 108 | |
yfkwok | 19:903d67bb0dea | 109 | /** |
yfkwok | 19:903d67bb0dea | 110 | * @brief Check instagram missed |
yfkwok | 19:903d67bb0dea | 111 | * @details The private function checks if instagram is missed, reinitiate a new object and increase round counter |
yfkwok | 19:903d67bb0dea | 112 | */ |
yfkwok | 14:abe64fe0b6a5 | 113 | void check_miss_insta(Gamepad &pad); |
yfkwok | 19:903d67bb0dea | 114 | |
yfkwok | 19:903d67bb0dea | 115 | /** |
yfkwok | 19:903d67bb0dea | 116 | * @brief Check facebook collision |
yfkwok | 19:903d67bb0dea | 117 | * @param character cha (int) |
yfkwok | 19:903d67bb0dea | 118 | * @details The private function checks if facebook is collided, takes in the character value to determine the size of the hitbox, terminates the game loop and display the gameover screen |
yfkwok | 19:903d67bb0dea | 119 | */ |
yfkwok | 14:abe64fe0b6a5 | 120 | void check_face_collide(Gamepad &pad, N5110 &lcd, int cha); |
yfkwok | 19:903d67bb0dea | 121 | |
yfkwok | 19:903d67bb0dea | 122 | /** |
yfkwok | 19:903d67bb0dea | 123 | * @brief Check facebook missed |
yfkwok | 19:903d67bb0dea | 124 | * @details The private function checks if facebook is missed, reinitiate a new object and increase round counter |
yfkwok | 19:903d67bb0dea | 125 | */ |
yfkwok | 14:abe64fe0b6a5 | 126 | void check_miss_face(Gamepad &pad); |
yfkwok | 19:903d67bb0dea | 127 | |
yfkwok | 19:903d67bb0dea | 128 | /** |
yfkwok | 19:903d67bb0dea | 129 | * @brief Check twitter collision |
yfkwok | 19:903d67bb0dea | 130 | * @param character cha (int) |
yfkwok | 19:903d67bb0dea | 131 | * @details The private function checks if twitter is collided, takes in the character value to determine the size of the hitbox, terminates the game loop and display the gameover screen |
yfkwok | 19:903d67bb0dea | 132 | */ |
yfkwok | 14:abe64fe0b6a5 | 133 | void check_twitt_collide(Gamepad &pad, N5110 &lcd, int cha); |
yfkwok | 19:903d67bb0dea | 134 | |
yfkwok | 19:903d67bb0dea | 135 | /** |
yfkwok | 19:903d67bb0dea | 136 | * @brief Check twitter missed |
yfkwok | 19:903d67bb0dea | 137 | * @details The private function checks if twitter is missed, reinitiate a new object and increase round counter |
yfkwok | 19:903d67bb0dea | 138 | */ |
yfkwok | 14:abe64fe0b6a5 | 139 | void check_miss_twitt(Gamepad &pad); |
yfkwok | 19:903d67bb0dea | 140 | |
yfkwok | 19:903d67bb0dea | 141 | /** |
yfkwok | 19:903d67bb0dea | 142 | * @brief Check youtube collision |
yfkwok | 19:903d67bb0dea | 143 | * @param character cha (int) |
yfkwok | 19:903d67bb0dea | 144 | * @details The private function checks if youtube is collided, takes in the character value to determine the size of the hitbox, terminates the game loop and display the gameover screen |
yfkwok | 19:903d67bb0dea | 145 | */ |
yfkwok | 14:abe64fe0b6a5 | 146 | void check_yt_collide(Gamepad &pad, N5110 &lcd, int cha); |
yfkwok | 19:903d67bb0dea | 147 | |
yfkwok | 19:903d67bb0dea | 148 | /** |
yfkwok | 19:903d67bb0dea | 149 | * @brief Check youtube missed |
yfkwok | 19:903d67bb0dea | 150 | * @details The private function checks if youtube is missed, reinitiate a new object and increase round counter |
yfkwok | 19:903d67bb0dea | 151 | */ |
yfkwok | 14:abe64fe0b6a5 | 152 | void check_miss_yt(Gamepad &pad); |
yfkwok | 19:903d67bb0dea | 153 | |
yfkwok | 19:903d67bb0dea | 154 | /** |
yfkwok | 19:903d67bb0dea | 155 | * @brief Gameover screen |
yfkwok | 19:903d67bb0dea | 156 | * @details The private function initiates the gameover screen and termiate term |
yfkwok | 19:903d67bb0dea | 157 | */ |
yfkwok | 14:abe64fe0b6a5 | 158 | void gameover(N5110 &lcd, Gamepad &pad); |
yfkwok | 14:abe64fe0b6a5 | 159 | |
yfkwok | 13:02002658e718 | 160 | Score music; |
yfkwok | 13:02002658e718 | 161 | FXOS8700CQ device(I2C* sda, I2C* scl); |
yfkwok | 14:abe64fe0b6a5 | 162 | Game_two_cha _p1; |
yfkwok | 14:abe64fe0b6a5 | 163 | Insta _insta; |
yfkwok | 14:abe64fe0b6a5 | 164 | Facebook _face; |
yfkwok | 14:abe64fe0b6a5 | 165 | Twitter _twitt; |
yfkwok | 14:abe64fe0b6a5 | 166 | YouTube _yt; |
yfkwok | 13:02002658e718 | 167 | |
yfkwok | 14:abe64fe0b6a5 | 168 | Direction _d; |
yfkwok | 14:abe64fe0b6a5 | 169 | float _mag; |
yfkwok | 13:02002658e718 | 170 | int _speed; |
yfkwok | 13:02002658e718 | 171 | int _cha; |
yfkwok | 13:02002658e718 | 172 | int _rand; |
yfkwok | 13:02002658e718 | 173 | int _count; |
yfkwok | 13:02002658e718 | 174 | int _alt; |
yfkwok | 14:abe64fe0b6a5 | 175 | int _type; |
yfkwok | 14:abe64fe0b6a5 | 176 | int _so; |
yfkwok | 13:02002658e718 | 177 | |
yfkwok | 13:02002658e718 | 178 | }; |
yfkwok | 13:02002658e718 | 179 | |
yfkwok | 13:02002658e718 | 180 | #endif |