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

Committer:
yfkwok
Date:
Tue Apr 30 09:40:35 2019 +0000
Revision:
26:c60becf3f840
Parent:
21:704d938acf5d
Child:
29:75a05e9f0e8d
30/04/2019 - Documentation comments for main.cpp

Who changed what in which revision?

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