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