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.cpp@33:f7ec806e14b6, 2019-05-08 (annotated)
- Committer:
- yfkwok
- Date:
- Wed May 08 23:57:04 2019 +0000
- Revision:
- 33:f7ec806e14b6
- Parent:
- 29:75a05e9f0e8d
09/05/19 - Inline comment added, functionalities complete, all Deoxygen comment added for classes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yfkwok | 13:02002658e718 | 1 | #include "Game_two.h" |
yfkwok | 13:02002658e718 | 2 | |
yfkwok | 13:02002658e718 | 3 | Game_two::Game_two() |
yfkwok | 13:02002658e718 | 4 | { |
yfkwok | 13:02002658e718 | 5 | |
yfkwok | 13:02002658e718 | 6 | } |
yfkwok | 13:02002658e718 | 7 | |
yfkwok | 13:02002658e718 | 8 | Game_two::~Game_two() |
yfkwok | 13:02002658e718 | 9 | { |
yfkwok | 13:02002658e718 | 10 | |
yfkwok | 13:02002658e718 | 11 | } |
yfkwok | 13:02002658e718 | 12 | |
yfkwok | 13:02002658e718 | 13 | //Enumerate instruction menu from page 1 - 3 |
yfkwok | 13:02002658e718 | 14 | enum Page { |
yfkwok | 13:02002658e718 | 15 | PAGE_1, PAGE_2, PAGE_3 |
yfkwok | 13:02002658e718 | 16 | }; |
yfkwok | 13:02002658e718 | 17 | |
yfkwok | 13:02002658e718 | 18 | void Game_two::init(int speed, int cha, int r) |
yfkwok | 13:02002658e718 | 19 | { |
yfkwok | 13:02002658e718 | 20 | // Set the speed of the objects |
yfkwok | 13:02002658e718 | 21 | _speed = speed; |
yfkwok | 13:02002658e718 | 22 | |
yfkwok | 13:02002658e718 | 23 | // Set the character being drawn |
yfkwok | 13:02002658e718 | 24 | _cha = cha; |
yfkwok | 13:02002658e718 | 25 | |
yfkwok | 19:903d67bb0dea | 26 | // Set the random parameter for determining difficulty level |
yfkwok | 13:02002658e718 | 27 | _rand = r; |
yfkwok | 13:02002658e718 | 28 | |
yfkwok | 13:02002658e718 | 29 | // initialize round counter |
yfkwok | 13:02002658e718 | 30 | _count = 0; |
yfkwok | 13:02002658e718 | 31 | _alt = 0; |
yfkwok | 14:abe64fe0b6a5 | 32 | |
yfkwok | 14:abe64fe0b6a5 | 33 | // Game initiation |
yfkwok | 14:abe64fe0b6a5 | 34 | _p1.init(); |
yfkwok | 21:704d938acf5d | 35 | _insta.init(_speed); |
yfkwok | 21:704d938acf5d | 36 | _twitt.init(_speed); |
yfkwok | 21:704d938acf5d | 37 | _face.init(_speed); |
yfkwok | 21:704d938acf5d | 38 | _yt.init(_speed); |
yfkwok | 14:abe64fe0b6a5 | 39 | |
yfkwok | 19:903d67bb0dea | 40 | // Create random parameter to determine which social app should be drawn |
yfkwok | 14:abe64fe0b6a5 | 41 | srand(time(NULL)); |
yfkwok | 14:abe64fe0b6a5 | 42 | _type = rand() % 4; // randomise type. |
yfkwok | 14:abe64fe0b6a5 | 43 | _so = rand() % 3; |
yfkwok | 13:02002658e718 | 44 | |
yfkwok | 13:02002658e718 | 45 | } |
yfkwok | 13:02002658e718 | 46 | |
yfkwok | 33:f7ec806e14b6 | 47 | // Function to render the images |
yfkwok | 14:abe64fe0b6a5 | 48 | void Game_two::render(N5110 &lcd, int cha) |
yfkwok | 13:02002658e718 | 49 | { |
yfkwok | 13:02002658e718 | 50 | lcd.clear(); |
yfkwok | 13:02002658e718 | 51 | draw(lcd, cha); |
yfkwok | 13:02002658e718 | 52 | lcd.refresh(); |
yfkwok | 13:02002658e718 | 53 | } |
yfkwok | 13:02002658e718 | 54 | |
yfkwok | 33:f7ec806e14b6 | 55 | // Function to read the input from the FXOS8700CQ device to get direction and magnitude |
yfkwok | 14:abe64fe0b6a5 | 56 | void Game_two::read_input(FXOS8700CQ &device) |
yfkwok | 13:02002658e718 | 57 | { |
yfkwok | 14:abe64fe0b6a5 | 58 | _d = device.get_direction(); |
yfkwok | 14:abe64fe0b6a5 | 59 | _mag = device.get_mag(); |
yfkwok | 13:02002658e718 | 60 | } |
yfkwok | 13:02002658e718 | 61 | |
yfkwok | 33:f7ec806e14b6 | 62 | // Function to draw all objects in the game |
yfkwok | 13:02002658e718 | 63 | void Game_two::draw(N5110 &lcd, int cha) |
yfkwok | 13:02002658e718 | 64 | { |
yfkwok | 13:02002658e718 | 65 | int alt = update_alt(); |
yfkwok | 13:02002658e718 | 66 | // draw player on lcd |
yfkwok | 13:02002658e718 | 67 | if(alt <= 1){_p1.draw(lcd, cha);} |
yfkwok | 13:02002658e718 | 68 | else {_p1.draw_alt(lcd, cha);} |
yfkwok | 19:903d67bb0dea | 69 | // spawn app icon |
yfkwok | 14:abe64fe0b6a5 | 70 | if(_type < _rand) { |
yfkwok | 33:f7ec806e14b6 | 71 | if (_so == 0) {_insta.draw(lcd);} // Draw instagram if _so is randomized to 0 |
yfkwok | 33:f7ec806e14b6 | 72 | else if (_so == 1) {_face.draw(lcd);} // Draw facebook if _so is randomized to 1 |
yfkwok | 33:f7ec806e14b6 | 73 | else if (_so == 2) {_twitt.draw(lcd);} // Draw twitter if _so is randomized to 2 |
yfkwok | 14:abe64fe0b6a5 | 74 | } |
yfkwok | 33:f7ec806e14b6 | 75 | else {_yt.draw(lcd);} // Draw youtube if _type < _rand |
yfkwok | 13:02002658e718 | 76 | } |
yfkwok | 13:02002658e718 | 77 | |
yfkwok | 14:abe64fe0b6a5 | 78 | void Game_two::update(Gamepad &pad, N5110 &lcd, int cha) |
yfkwok | 13:02002658e718 | 79 | { |
yfkwok | 33:f7ec806e14b6 | 80 | // check if the object is dodged |
yfkwok | 33:f7ec806e14b6 | 81 | // update the player's position |
yfkwok | 33:f7ec806e14b6 | 82 | // update the object's position |
yfkwok | 33:f7ec806e14b6 | 83 | // check if the object is collided with the player |
yfkwok | 14:abe64fe0b6a5 | 84 | if (_type < _rand) { |
yfkwok | 14:abe64fe0b6a5 | 85 | if (_so == 0){ |
yfkwok | 14:abe64fe0b6a5 | 86 | check_miss_insta(pad); |
yfkwok | 14:abe64fe0b6a5 | 87 | _p1.update(_d,_mag); |
yfkwok | 14:abe64fe0b6a5 | 88 | _insta.update(); |
yfkwok | 14:abe64fe0b6a5 | 89 | check_insta_collide(pad, lcd, cha); |
yfkwok | 14:abe64fe0b6a5 | 90 | } else if (_so == 1){ |
yfkwok | 14:abe64fe0b6a5 | 91 | check_miss_face(pad); |
yfkwok | 14:abe64fe0b6a5 | 92 | _p1.update(_d,_mag); |
yfkwok | 14:abe64fe0b6a5 | 93 | _face.update(); |
yfkwok | 14:abe64fe0b6a5 | 94 | check_face_collide(pad, lcd, cha); |
yfkwok | 14:abe64fe0b6a5 | 95 | } else if (_so == 2){ |
yfkwok | 14:abe64fe0b6a5 | 96 | check_miss_twitt(pad); |
yfkwok | 14:abe64fe0b6a5 | 97 | _p1.update(_d,_mag); |
yfkwok | 14:abe64fe0b6a5 | 98 | _twitt.update(); |
yfkwok | 14:abe64fe0b6a5 | 99 | check_twitt_collide(pad, lcd, cha); |
yfkwok | 14:abe64fe0b6a5 | 100 | } |
yfkwok | 13:02002658e718 | 101 | } |
yfkwok | 13:02002658e718 | 102 | else { |
yfkwok | 14:abe64fe0b6a5 | 103 | check_miss_yt(pad); |
yfkwok | 13:02002658e718 | 104 | _p1.update(_d,_mag); |
yfkwok | 14:abe64fe0b6a5 | 105 | _yt.update(); |
yfkwok | 14:abe64fe0b6a5 | 106 | check_yt_collide(pad, lcd, cha); |
yfkwok | 13:02002658e718 | 107 | } |
yfkwok | 13:02002658e718 | 108 | } |
yfkwok | 13:02002658e718 | 109 | |
yfkwok | 14:abe64fe0b6a5 | 110 | void Game_two::check_insta_collide(Gamepad &pad, N5110 &lcd, int cha) |
yfkwok | 13:02002658e718 | 111 | { |
yfkwok | 19:903d67bb0dea | 112 | // read current object attributes |
yfkwok | 14:abe64fe0b6a5 | 113 | Vector2D insta_pos = _insta.get_pos(); |
yfkwok | 14:abe64fe0b6a5 | 114 | Vector2D insta_speed = _insta.get_velocity(); |
yfkwok | 14:abe64fe0b6a5 | 115 | |
yfkwok | 14:abe64fe0b6a5 | 116 | // check p1 first |
yfkwok | 14:abe64fe0b6a5 | 117 | Vector2D p1_pos = _p1.get_pos(); |
yfkwok | 14:abe64fe0b6a5 | 118 | |
yfkwok | 19:903d67bb0dea | 119 | // see if object has hit the player by checking for overlaps |
yfkwok | 14:abe64fe0b6a5 | 120 | if (cha == 1){ |
yfkwok | 14:abe64fe0b6a5 | 121 | if ( |
yfkwok | 33:f7ec806e14b6 | 122 | (insta_pos.y >= p1_pos.y - 4) && //top |
yfkwok | 33:f7ec806e14b6 | 123 | (insta_pos.y <= p1_pos.y + 13) && //bottom |
yfkwok | 33:f7ec806e14b6 | 124 | (insta_pos.x >= p1_pos.x - 4) && //left |
yfkwok | 33:f7ec806e14b6 | 125 | (insta_pos.x <= p1_pos.x + 15) //right |
yfkwok | 14:abe64fe0b6a5 | 126 | ) |
yfkwok | 14:abe64fe0b6a5 | 127 | { |
yfkwok | 14:abe64fe0b6a5 | 128 | // write new attributes |
yfkwok | 14:abe64fe0b6a5 | 129 | _insta.init(_speed); |
yfkwok | 14:abe64fe0b6a5 | 130 | gameover(lcd, pad); |
yfkwok | 14:abe64fe0b6a5 | 131 | } |
yfkwok | 14:abe64fe0b6a5 | 132 | } |
yfkwok | 14:abe64fe0b6a5 | 133 | if (cha == 2){ |
yfkwok | 14:abe64fe0b6a5 | 134 | if ( |
yfkwok | 33:f7ec806e14b6 | 135 | (insta_pos.y >= p1_pos.y - 5) && //top |
yfkwok | 33:f7ec806e14b6 | 136 | (insta_pos.y <= p1_pos.y + 14) && //bottom |
yfkwok | 33:f7ec806e14b6 | 137 | (insta_pos.x >= p1_pos.x - 4) && //left |
yfkwok | 33:f7ec806e14b6 | 138 | (insta_pos.x <= p1_pos.x + 16) //right |
yfkwok | 14:abe64fe0b6a5 | 139 | ) |
yfkwok | 14:abe64fe0b6a5 | 140 | { |
yfkwok | 14:abe64fe0b6a5 | 141 | // write new attributes |
yfkwok | 14:abe64fe0b6a5 | 142 | _insta.init(_speed); |
yfkwok | 14:abe64fe0b6a5 | 143 | gameover(lcd, pad); |
yfkwok | 14:abe64fe0b6a5 | 144 | } |
yfkwok | 14:abe64fe0b6a5 | 145 | } |
yfkwok | 14:abe64fe0b6a5 | 146 | if (cha == 3){ |
yfkwok | 14:abe64fe0b6a5 | 147 | if ( |
yfkwok | 33:f7ec806e14b6 | 148 | (insta_pos.y >= p1_pos.y - 6) && //top |
yfkwok | 33:f7ec806e14b6 | 149 | (insta_pos.y <= p1_pos.y + 16) && //bottom |
yfkwok | 33:f7ec806e14b6 | 150 | (insta_pos.x >= p1_pos.x - 4) && //left |
yfkwok | 33:f7ec806e14b6 | 151 | (insta_pos.x <= p1_pos.x + 23) //right |
yfkwok | 14:abe64fe0b6a5 | 152 | ) |
yfkwok | 14:abe64fe0b6a5 | 153 | { |
yfkwok | 14:abe64fe0b6a5 | 154 | // write new attributes |
yfkwok | 14:abe64fe0b6a5 | 155 | _insta.init(_speed); |
yfkwok | 14:abe64fe0b6a5 | 156 | gameover(lcd, pad); |
yfkwok | 14:abe64fe0b6a5 | 157 | } |
yfkwok | 14:abe64fe0b6a5 | 158 | } |
yfkwok | 14:abe64fe0b6a5 | 159 | } |
yfkwok | 14:abe64fe0b6a5 | 160 | |
yfkwok | 14:abe64fe0b6a5 | 161 | void Game_two::check_miss_insta(Gamepad &pad) |
yfkwok | 14:abe64fe0b6a5 | 162 | { |
yfkwok | 14:abe64fe0b6a5 | 163 | Vector2D insta_pos = _insta.get_pos(); |
yfkwok | 14:abe64fe0b6a5 | 164 | // player has missed |
yfkwok | 14:abe64fe0b6a5 | 165 | if ((insta_pos.x > 84) || (insta_pos.x < -15) || (insta_pos.y < -15) || (insta_pos.y > 50)) { |
yfkwok | 14:abe64fe0b6a5 | 166 | _insta.init(_speed); |
yfkwok | 14:abe64fe0b6a5 | 167 | pad.tone(750.0,0.1); |
yfkwok | 14:abe64fe0b6a5 | 168 | _count++; |
yfkwok | 14:abe64fe0b6a5 | 169 | wait(0.1); |
yfkwok | 14:abe64fe0b6a5 | 170 | _type = rand() % 8; // randomise type |
yfkwok | 21:704d938acf5d | 171 | _so = rand() % 3; |
yfkwok | 14:abe64fe0b6a5 | 172 | } |
yfkwok | 14:abe64fe0b6a5 | 173 | } |
yfkwok | 14:abe64fe0b6a5 | 174 | |
yfkwok | 14:abe64fe0b6a5 | 175 | void Game_two::check_face_collide(Gamepad &pad, N5110 &lcd, int cha) |
yfkwok | 14:abe64fe0b6a5 | 176 | { |
yfkwok | 19:903d67bb0dea | 177 | // read current object attributes |
yfkwok | 14:abe64fe0b6a5 | 178 | Vector2D face_pos = _face.get_pos(); |
yfkwok | 14:abe64fe0b6a5 | 179 | Vector2D face_speed = _face.get_velocity(); |
yfkwok | 13:02002658e718 | 180 | |
yfkwok | 13:02002658e718 | 181 | // check p1 first |
yfkwok | 13:02002658e718 | 182 | Vector2D p1_pos = _p1.get_pos(); |
yfkwok | 13:02002658e718 | 183 | |
yfkwok | 19:903d67bb0dea | 184 | // see if object has hit the player by checking for overlaps |
yfkwok | 14:abe64fe0b6a5 | 185 | if (cha == 1){ |
yfkwok | 14:abe64fe0b6a5 | 186 | if ( |
yfkwok | 33:f7ec806e14b6 | 187 | (face_pos.y >= p1_pos.y - 8) && //top |
yfkwok | 33:f7ec806e14b6 | 188 | (face_pos.y <= p1_pos.y + 18) && //bottom |
yfkwok | 33:f7ec806e14b6 | 189 | (face_pos.x >= p1_pos.x - 6) && //left |
yfkwok | 33:f7ec806e14b6 | 190 | (face_pos.x <= p1_pos.x + 20) //right |
yfkwok | 14:abe64fe0b6a5 | 191 | ) |
yfkwok | 14:abe64fe0b6a5 | 192 | { |
yfkwok | 14:abe64fe0b6a5 | 193 | // write new attributes |
yfkwok | 14:abe64fe0b6a5 | 194 | _face.init(_speed); |
yfkwok | 14:abe64fe0b6a5 | 195 | gameover(lcd, pad); |
yfkwok | 14:abe64fe0b6a5 | 196 | } |
yfkwok | 14:abe64fe0b6a5 | 197 | } |
yfkwok | 14:abe64fe0b6a5 | 198 | if (cha == 2){ |
yfkwok | 14:abe64fe0b6a5 | 199 | if ( |
yfkwok | 33:f7ec806e14b6 | 200 | (face_pos.y >= p1_pos.y - 8) && //top |
yfkwok | 33:f7ec806e14b6 | 201 | (face_pos.y <= p1_pos.y + 21) && //bottom |
yfkwok | 33:f7ec806e14b6 | 202 | (face_pos.x >= p1_pos.x - 6) && //left |
yfkwok | 33:f7ec806e14b6 | 203 | (face_pos.x <= p1_pos.x + 21) //right |
yfkwok | 14:abe64fe0b6a5 | 204 | ) |
yfkwok | 14:abe64fe0b6a5 | 205 | { |
yfkwok | 14:abe64fe0b6a5 | 206 | // write new attributes |
yfkwok | 14:abe64fe0b6a5 | 207 | _face.init(_speed); |
yfkwok | 14:abe64fe0b6a5 | 208 | gameover(lcd, pad); |
yfkwok | 14:abe64fe0b6a5 | 209 | } |
yfkwok | 14:abe64fe0b6a5 | 210 | } |
yfkwok | 14:abe64fe0b6a5 | 211 | if (cha == 3){ |
yfkwok | 14:abe64fe0b6a5 | 212 | if ( |
yfkwok | 33:f7ec806e14b6 | 213 | (face_pos.y >= p1_pos.y - 8) && //top |
yfkwok | 33:f7ec806e14b6 | 214 | (face_pos.y <= p1_pos.y + 21) && //bottom |
yfkwok | 33:f7ec806e14b6 | 215 | (face_pos.x >= p1_pos.x - 6) && //left |
yfkwok | 33:f7ec806e14b6 | 216 | (face_pos.x <= p1_pos.x + 29) //right |
yfkwok | 14:abe64fe0b6a5 | 217 | ) |
yfkwok | 14:abe64fe0b6a5 | 218 | { |
yfkwok | 14:abe64fe0b6a5 | 219 | // write new attributes |
yfkwok | 14:abe64fe0b6a5 | 220 | _face.init(_speed); |
yfkwok | 14:abe64fe0b6a5 | 221 | gameover(lcd, pad); |
yfkwok | 14:abe64fe0b6a5 | 222 | } |
yfkwok | 13:02002658e718 | 223 | } |
yfkwok | 13:02002658e718 | 224 | } |
yfkwok | 13:02002658e718 | 225 | |
yfkwok | 14:abe64fe0b6a5 | 226 | void Game_two::check_miss_face(Gamepad &pad) |
yfkwok | 13:02002658e718 | 227 | { |
yfkwok | 14:abe64fe0b6a5 | 228 | Vector2D face_pos = _face.get_pos(); |
yfkwok | 13:02002658e718 | 229 | // player has missed |
yfkwok | 14:abe64fe0b6a5 | 230 | if ((face_pos.x > 84) || (face_pos.x < -15) || (face_pos.y < -15) || (face_pos.y > 50)) { |
yfkwok | 14:abe64fe0b6a5 | 231 | _face.init(_speed); |
yfkwok | 13:02002658e718 | 232 | pad.tone(750.0,0.1); |
yfkwok | 13:02002658e718 | 233 | _count++; |
yfkwok | 13:02002658e718 | 234 | wait(0.1); |
yfkwok | 13:02002658e718 | 235 | _type = rand() % 8; // randomise type |
yfkwok | 21:704d938acf5d | 236 | _so = rand() % 3; |
yfkwok | 14:abe64fe0b6a5 | 237 | } |
yfkwok | 14:abe64fe0b6a5 | 238 | } |
yfkwok | 14:abe64fe0b6a5 | 239 | |
yfkwok | 14:abe64fe0b6a5 | 240 | void Game_two::check_twitt_collide(Gamepad &pad, N5110 &lcd, int cha) |
yfkwok | 14:abe64fe0b6a5 | 241 | { |
yfkwok | 19:903d67bb0dea | 242 | // read current object attributes |
yfkwok | 14:abe64fe0b6a5 | 243 | Vector2D twitt_pos = _twitt.get_pos(); |
yfkwok | 14:abe64fe0b6a5 | 244 | Vector2D twitt_speed = _twitt.get_velocity(); |
yfkwok | 14:abe64fe0b6a5 | 245 | |
yfkwok | 14:abe64fe0b6a5 | 246 | // check p1 first |
yfkwok | 14:abe64fe0b6a5 | 247 | Vector2D p1_pos = _p1.get_pos(); |
yfkwok | 14:abe64fe0b6a5 | 248 | |
yfkwok | 19:903d67bb0dea | 249 | // see if object has hit the player by checking for overlaps |
yfkwok | 14:abe64fe0b6a5 | 250 | if (cha == 1){ |
yfkwok | 14:abe64fe0b6a5 | 251 | if ( |
yfkwok | 33:f7ec806e14b6 | 252 | (twitt_pos.y >= p1_pos.y - 8) && //top |
yfkwok | 33:f7ec806e14b6 | 253 | (twitt_pos.y <= p1_pos.y + 18) && //bottom |
yfkwok | 33:f7ec806e14b6 | 254 | (twitt_pos.x >= p1_pos.x - 6) && //left |
yfkwok | 33:f7ec806e14b6 | 255 | (twitt_pos.x <= p1_pos.x + 20) //right |
yfkwok | 14:abe64fe0b6a5 | 256 | ) |
yfkwok | 14:abe64fe0b6a5 | 257 | { |
yfkwok | 14:abe64fe0b6a5 | 258 | // write new attributes |
yfkwok | 14:abe64fe0b6a5 | 259 | _twitt.init(_speed); |
yfkwok | 14:abe64fe0b6a5 | 260 | gameover(lcd, pad); |
yfkwok | 14:abe64fe0b6a5 | 261 | } |
yfkwok | 13:02002658e718 | 262 | } |
yfkwok | 14:abe64fe0b6a5 | 263 | if (cha == 2){ |
yfkwok | 14:abe64fe0b6a5 | 264 | if ( |
yfkwok | 33:f7ec806e14b6 | 265 | (twitt_pos.y >= p1_pos.y - 8) && //top |
yfkwok | 33:f7ec806e14b6 | 266 | (twitt_pos.y <= p1_pos.y + 21) && //bottom |
yfkwok | 33:f7ec806e14b6 | 267 | (twitt_pos.x >= p1_pos.x - 6) && //left |
yfkwok | 33:f7ec806e14b6 | 268 | (twitt_pos.x <= p1_pos.x + 21) //right |
yfkwok | 14:abe64fe0b6a5 | 269 | ) |
yfkwok | 14:abe64fe0b6a5 | 270 | { |
yfkwok | 14:abe64fe0b6a5 | 271 | // write new attributes |
yfkwok | 14:abe64fe0b6a5 | 272 | _twitt.init(_speed); |
yfkwok | 14:abe64fe0b6a5 | 273 | gameover(lcd, pad); |
yfkwok | 14:abe64fe0b6a5 | 274 | } |
yfkwok | 14:abe64fe0b6a5 | 275 | } |
yfkwok | 14:abe64fe0b6a5 | 276 | if (cha == 3){ |
yfkwok | 14:abe64fe0b6a5 | 277 | if ( |
yfkwok | 33:f7ec806e14b6 | 278 | (twitt_pos.y >= p1_pos.y - 8) && //top |
yfkwok | 33:f7ec806e14b6 | 279 | (twitt_pos.y <= p1_pos.y + 21) && //bottom |
yfkwok | 33:f7ec806e14b6 | 280 | (twitt_pos.x >= p1_pos.x - 6) && //left |
yfkwok | 33:f7ec806e14b6 | 281 | (twitt_pos.x <= p1_pos.x + 29) //right |
yfkwok | 14:abe64fe0b6a5 | 282 | ) |
yfkwok | 14:abe64fe0b6a5 | 283 | { |
yfkwok | 14:abe64fe0b6a5 | 284 | // write new attributes |
yfkwok | 14:abe64fe0b6a5 | 285 | _twitt.init(_speed); |
yfkwok | 14:abe64fe0b6a5 | 286 | gameover(lcd, pad); |
yfkwok | 14:abe64fe0b6a5 | 287 | } |
yfkwok | 14:abe64fe0b6a5 | 288 | } |
yfkwok | 13:02002658e718 | 289 | } |
yfkwok | 13:02002658e718 | 290 | |
yfkwok | 14:abe64fe0b6a5 | 291 | void Game_two::check_miss_twitt(Gamepad &pad) |
yfkwok | 14:abe64fe0b6a5 | 292 | { |
yfkwok | 14:abe64fe0b6a5 | 293 | Vector2D twitt_pos = _twitt.get_pos(); |
yfkwok | 14:abe64fe0b6a5 | 294 | // player has missed |
yfkwok | 14:abe64fe0b6a5 | 295 | if ((twitt_pos.x > 84) || (twitt_pos.x < -15) || (twitt_pos.y < -15) || (twitt_pos.y > 50)) { |
yfkwok | 14:abe64fe0b6a5 | 296 | _twitt.init(_speed); |
yfkwok | 14:abe64fe0b6a5 | 297 | pad.tone(750.0,0.1); |
yfkwok | 14:abe64fe0b6a5 | 298 | _count++; |
yfkwok | 14:abe64fe0b6a5 | 299 | wait(0.1); |
yfkwok | 14:abe64fe0b6a5 | 300 | _type = rand() % 8; // randomise type |
yfkwok | 21:704d938acf5d | 301 | _so = rand() % 3; |
yfkwok | 14:abe64fe0b6a5 | 302 | } |
yfkwok | 14:abe64fe0b6a5 | 303 | } |
yfkwok | 14:abe64fe0b6a5 | 304 | |
yfkwok | 14:abe64fe0b6a5 | 305 | void Game_two::check_yt_collide(Gamepad &pad, N5110 &lcd, int cha) |
yfkwok | 14:abe64fe0b6a5 | 306 | { |
yfkwok | 19:903d67bb0dea | 307 | // read current object attributes |
yfkwok | 14:abe64fe0b6a5 | 308 | Vector2D yt_pos = _yt.get_pos(); |
yfkwok | 14:abe64fe0b6a5 | 309 | Vector2D yt_speed = _yt.get_velocity(); |
yfkwok | 14:abe64fe0b6a5 | 310 | |
yfkwok | 14:abe64fe0b6a5 | 311 | // check p1 first |
yfkwok | 14:abe64fe0b6a5 | 312 | Vector2D p1_pos = _p1.get_pos(); |
yfkwok | 14:abe64fe0b6a5 | 313 | |
yfkwok | 19:903d67bb0dea | 314 | // see if object has hit the player by checking for overlaps |
yfkwok | 14:abe64fe0b6a5 | 315 | if (cha == 1){ |
yfkwok | 14:abe64fe0b6a5 | 316 | if ( |
yfkwok | 33:f7ec806e14b6 | 317 | (yt_pos.y >= p1_pos.y - 8) && //top |
yfkwok | 33:f7ec806e14b6 | 318 | (yt_pos.y <= p1_pos.y + 18) && //bottom |
yfkwok | 33:f7ec806e14b6 | 319 | (yt_pos.x >= p1_pos.x - 25) && //left |
yfkwok | 33:f7ec806e14b6 | 320 | (yt_pos.x <= p1_pos.x + 20) //right |
yfkwok | 14:abe64fe0b6a5 | 321 | ) |
yfkwok | 14:abe64fe0b6a5 | 322 | { |
yfkwok | 14:abe64fe0b6a5 | 323 | // write new attributes |
yfkwok | 14:abe64fe0b6a5 | 324 | _yt.init(_speed); |
yfkwok | 14:abe64fe0b6a5 | 325 | gameover(lcd, pad); |
yfkwok | 14:abe64fe0b6a5 | 326 | } |
yfkwok | 14:abe64fe0b6a5 | 327 | } |
yfkwok | 14:abe64fe0b6a5 | 328 | if (cha == 2){ |
yfkwok | 14:abe64fe0b6a5 | 329 | if ( |
yfkwok | 33:f7ec806e14b6 | 330 | (yt_pos.y >= p1_pos.y - 8) && //top |
yfkwok | 33:f7ec806e14b6 | 331 | (yt_pos.y <= p1_pos.y + 21) && //bottom |
yfkwok | 33:f7ec806e14b6 | 332 | (yt_pos.x >= p1_pos.x - 25) && //left |
yfkwok | 33:f7ec806e14b6 | 333 | (yt_pos.x <= p1_pos.x + 21) //right |
yfkwok | 14:abe64fe0b6a5 | 334 | ) |
yfkwok | 14:abe64fe0b6a5 | 335 | { |
yfkwok | 14:abe64fe0b6a5 | 336 | // write new attributes |
yfkwok | 14:abe64fe0b6a5 | 337 | _yt.init(_speed); |
yfkwok | 14:abe64fe0b6a5 | 338 | gameover(lcd, pad); |
yfkwok | 14:abe64fe0b6a5 | 339 | } |
yfkwok | 14:abe64fe0b6a5 | 340 | } |
yfkwok | 14:abe64fe0b6a5 | 341 | if (cha == 3){ |
yfkwok | 14:abe64fe0b6a5 | 342 | if ( |
yfkwok | 33:f7ec806e14b6 | 343 | (yt_pos.y >= p1_pos.y - 8) && //top |
yfkwok | 33:f7ec806e14b6 | 344 | (yt_pos.y <= p1_pos.y + 21) && //bottom |
yfkwok | 33:f7ec806e14b6 | 345 | (yt_pos.x >= p1_pos.x - 25) && //left |
yfkwok | 33:f7ec806e14b6 | 346 | (yt_pos.x <= p1_pos.x + 29) //right |
yfkwok | 14:abe64fe0b6a5 | 347 | ) |
yfkwok | 14:abe64fe0b6a5 | 348 | { |
yfkwok | 14:abe64fe0b6a5 | 349 | // write new attributes |
yfkwok | 14:abe64fe0b6a5 | 350 | _yt.init(_speed); |
yfkwok | 14:abe64fe0b6a5 | 351 | gameover(lcd, pad); |
yfkwok | 14:abe64fe0b6a5 | 352 | } |
yfkwok | 14:abe64fe0b6a5 | 353 | } |
yfkwok | 14:abe64fe0b6a5 | 354 | } |
yfkwok | 14:abe64fe0b6a5 | 355 | |
yfkwok | 14:abe64fe0b6a5 | 356 | void Game_two::check_miss_yt(Gamepad &pad) |
yfkwok | 14:abe64fe0b6a5 | 357 | { |
yfkwok | 14:abe64fe0b6a5 | 358 | Vector2D yt_pos = _yt.get_pos(); |
yfkwok | 14:abe64fe0b6a5 | 359 | // player has missed |
yfkwok | 14:abe64fe0b6a5 | 360 | if ((yt_pos.x > 84) || (yt_pos.x < -15) || (yt_pos.y < -15) || (yt_pos.y > 50)) { |
yfkwok | 14:abe64fe0b6a5 | 361 | _yt.init(_speed); |
yfkwok | 14:abe64fe0b6a5 | 362 | pad.tone(750.0,0.1); |
yfkwok | 14:abe64fe0b6a5 | 363 | _count++; |
yfkwok | 14:abe64fe0b6a5 | 364 | wait(0.1); |
yfkwok | 14:abe64fe0b6a5 | 365 | _type = rand() % 8; // randomise type |
yfkwok | 21:704d938acf5d | 366 | _so = rand() % 3; |
yfkwok | 14:abe64fe0b6a5 | 367 | } |
yfkwok | 14:abe64fe0b6a5 | 368 | } |
yfkwok | 14:abe64fe0b6a5 | 369 | |
yfkwok | 13:02002658e718 | 370 | void Game_two::set_count(int count) |
yfkwok | 13:02002658e718 | 371 | { |
yfkwok | 13:02002658e718 | 372 | _count = count; |
yfkwok | 13:02002658e718 | 373 | } |
yfkwok | 13:02002658e718 | 374 | |
yfkwok | 13:02002658e718 | 375 | int Game_two::get_count() |
yfkwok | 13:02002658e718 | 376 | { |
yfkwok | 13:02002658e718 | 377 | int count = _count; |
yfkwok | 13:02002658e718 | 378 | return count; |
yfkwok | 13:02002658e718 | 379 | } |
yfkwok | 13:02002658e718 | 380 | |
yfkwok | 13:02002658e718 | 381 | int Game_two::update_alt() |
yfkwok | 13:02002658e718 | 382 | { |
yfkwok | 13:02002658e718 | 383 | if(_alt < 4){_alt = _alt++;} |
yfkwok | 13:02002658e718 | 384 | else {_alt=0;} |
yfkwok | 13:02002658e718 | 385 | int alt = _alt; |
yfkwok | 13:02002658e718 | 386 | return alt; |
yfkwok | 13:02002658e718 | 387 | } |
yfkwok | 13:02002658e718 | 388 | |
yfkwok | 13:02002658e718 | 389 | void Game_two::gameover(N5110 &lcd, Gamepad &pad) |
yfkwok | 13:02002658e718 | 390 | { |
yfkwok | 13:02002658e718 | 391 | while(pad.check_event(Gamepad::B_PRESSED) == false) { |
yfkwok | 13:02002658e718 | 392 | lcd.clear(); |
yfkwok | 13:02002658e718 | 393 | lcd.printString("You rushed ",0,0); |
yfkwok | 14:abe64fe0b6a5 | 394 | lcd.printString("into social",0,1); |
yfkwok | 14:abe64fe0b6a5 | 395 | lcd.printString("media!",0,2); |
yfkwok | 14:abe64fe0b6a5 | 396 | lcd.printString("Game Over!",0,3); |
yfkwok | 13:02002658e718 | 397 | lcd.printString("Press B",0,5); |
yfkwok | 13:02002658e718 | 398 | lcd.refresh(); |
yfkwok | 13:02002658e718 | 399 | wait(0.1); |
yfkwok | 13:02002658e718 | 400 | } |
yfkwok | 14:abe64fe0b6a5 | 401 | _count = 30; |
yfkwok | 13:02002658e718 | 402 | } |
yfkwok | 13:02002658e718 | 403 | |
yfkwok | 13:02002658e718 | 404 | void Game_two::intro(Gamepad &pad, N5110 &lcd) |
yfkwok | 13:02002658e718 | 405 | { |
yfkwok | 13:02002658e718 | 406 | Page currentPage = PAGE_1; |
yfkwok | 13:02002658e718 | 407 | int fps = 8.0; |
yfkwok | 13:02002658e718 | 408 | int instruct_data[4][7] = { |
yfkwok | 13:02002658e718 | 409 | {1,1,1,1,1,1,1}, |
yfkwok | 13:02002658e718 | 410 | {0,1,1,1,1,1,0}, |
yfkwok | 13:02002658e718 | 411 | {0,0,1,1,1,0,0}, |
yfkwok | 13:02002658e718 | 412 | {0,0,0,1,0,0,0}, |
yfkwok | 13:02002658e718 | 413 | }; |
yfkwok | 13:02002658e718 | 414 | |
yfkwok | 13:02002658e718 | 415 | while(pad.check_event(Gamepad::A_PRESSED) == false){ |
yfkwok | 13:02002658e718 | 416 | switch (currentPage) { |
yfkwok | 13:02002658e718 | 417 | case PAGE_1: |
yfkwok | 13:02002658e718 | 418 | lcd.clear(); |
yfkwok | 14:abe64fe0b6a5 | 419 | lcd.printString("Charmander",0,0); |
yfkwok | 14:abe64fe0b6a5 | 420 | lcd.printString("is trying",0,1); |
yfkwok | 14:abe64fe0b6a5 | 421 | lcd.printString("to study!",0,2); |
yfkwok | 14:abe64fe0b6a5 | 422 | lcd.printString("Avoid all",0,4); |
yfkwok | 13:02002658e718 | 423 | lcd.drawSprite(39, 44, 4, 7, (int *)instruct_data); |
yfkwok | 13:02002658e718 | 424 | lcd.refresh(); |
yfkwok | 13:02002658e718 | 425 | if(pad.get_direction() == S){currentPage = PAGE_2;} |
yfkwok | 13:02002658e718 | 426 | wait(1.0f/fps); |
yfkwok | 13:02002658e718 | 427 | break; |
yfkwok | 13:02002658e718 | 428 | case PAGE_2: |
yfkwok | 13:02002658e718 | 429 | lcd.clear(); |
yfkwok | 14:abe64fe0b6a5 | 430 | lcd.printString("distractions",0,0); |
yfkwok | 14:abe64fe0b6a5 | 431 | lcd.printString("so he can pass",0,1); |
yfkwok | 26:c60becf3f840 | 432 | lcd.printString("the test by",0,2); |
yfkwok | 26:c60becf3f840 | 433 | lcd.printString("tilting the",0,3); |
yfkwok | 26:c60becf3f840 | 434 | lcd.printString("Gamepad!",0,4); |
yfkwok | 13:02002658e718 | 435 | lcd.printString("Press A",0,5); |
yfkwok | 13:02002658e718 | 436 | lcd.refresh(); |
yfkwok | 13:02002658e718 | 437 | wait(1.0f/fps); |
yfkwok | 14:abe64fe0b6a5 | 438 | break; |
yfkwok | 13:02002658e718 | 439 | } |
yfkwok | 13:02002658e718 | 440 | } |
yfkwok | 14:abe64fe0b6a5 | 441 | } |