Mbed project for a FRDM-K64F microcontroller. Game made out of five sub-games including flappy birds, snake, stack, trivia and space invaders.

Dependencies:   mbed

Fork of The_Children_of_Cronos_el15mggr by ELEC2645 (2016/17)

Committer:
matirc
Date:
Tue Jul 18 09:55:49 2017 +0000
Revision:
5:4111d3255f24
Parent:
3:151ac98b6252
Final version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
matirc 3:151ac98b6252 1
matirc 2:8b95be711648 2 #include "game.h"
matirc 3:151ac98b6252 3 //serial object for checking with printf()
matirc 3:151ac98b6252 4 Serial serial(USBTX, USBRX);
matirc 2:8b95be711648 5 ////////////////////////////////////////////////////
matirc 2:8b95be711648 6 int main()
matirc 2:8b95be711648 7 {
matirc 3:151ac98b6252 8 init(); //initialisats all games inits
matirc 3:151ac98b6252 9
matirc 3:151ac98b6252 10 //pc.printf("intro done\n");
matirc 3:151ac98b6252 11
matirc 3:151ac98b6252 12 intro(); //fancy intro
matirc 3:151ac98b6252 13 introlights.detach(); //detach into switching on lights function
matirc 2:8b95be711648 14 while(menuselection) {
matirc 3:151ac98b6252 15
matirc 3:151ac98b6252 16 //pcd.printf("menu screen\n");
matirc 3:151ac98b6252 17
matirc 3:151ac98b6252 18 pad.leds_on();
matirc 2:8b95be711648 19 float pott=pad.read_pot();
matirc 2:8b95be711648 20 lcd.setBrightness(pott);
matirc 3:151ac98b6252 21 menuscreen(); //displays manu screen
matirc 3:151ac98b6252 22 menuselect(); //allows to switch between positions
matirc 2:8b95be711648 23 }
matirc 3:151ac98b6252 24
matirc 3:151ac98b6252 25 //pc.printf("out of the game\n");
matirc 2:8b95be711648 26
matirc 2:8b95be711648 27 }
matirc 2:8b95be711648 28 /////////////////////////////////////////////////////////////////
matirc 3:151ac98b6252 29
matirc 3:151ac98b6252 30 //if new game selected do this
matirc 2:8b95be711648 31 void newgame()
matirc 2:8b95be711648 32 {
matirc 3:151ac98b6252 33 while(selection) { //while the games selection variable is true,allow to choose game
matirc 3:151ac98b6252 34
matirc 3:151ac98b6252 35 //pc.printf("games screen in\n");
matirc 3:151ac98b6252 36
matirc 2:8b95be711648 37 pad.leds_on();
matirc 2:8b95be711648 38 float pott=pad.read_pot();
matirc 3:151ac98b6252 39 totalscore=scoreg1+scoreg2+scoreg3+scoreg4+scoreg5;//adds up all the individual games scores
matirc 3:151ac98b6252 40
matirc 3:151ac98b6252 41 //pc.printf("score:%d\n",totalscore);
matirc 3:151ac98b6252 42
matirc 3:151ac98b6252 43 game(); //peforms the game selection screen
matirc 3:151ac98b6252 44 select(); //allows to select between screens
matirc 3:151ac98b6252 45 if (r) { //if back button(in this case r) is pressed,set the games selector running variable as false and the menu selecor variable to true
matirc 3:151ac98b6252 46
matirc 3:151ac98b6252 47 //pc.printf("go back\n");
matirc 3:151ac98b6252 48
matirc 2:8b95be711648 49 selection=false;
matirc 2:8b95be711648 50 menuselection=true;
matirc 2:8b95be711648 51 }
matirc 2:8b95be711648 52 }
matirc 2:8b95be711648 53 }
matirc 2:8b95be711648 54
matirc 2:8b95be711648 55 ////////////////////////////////////////////////////////////////////
matirc 2:8b95be711648 56
matirc 3:151ac98b6252 57 //if menuselection is true,menu screen is running
matirc 2:8b95be711648 58 void menuscreen()
matirc 2:8b95be711648 59 {
matirc 3:151ac98b6252 60 drawselectmenu(); //allows o select options
matirc 2:8b95be711648 61 Direction d = pad.get_direction();
matirc 2:8b95be711648 62 if (d==S || a) {
matirc 3:151ac98b6252 63 wait(0.1); //small button debouncing
matirc 2:8b95be711648 64 if (d==S || a) {
matirc 3:151ac98b6252 65 statemenu = menu[statemenu].nextstate[1]; //swiches between options
matirc 3:151ac98b6252 66 }
matirc 2:8b95be711648 67 }
matirc 2:8b95be711648 68 if (d==N || y) {
matirc 2:8b95be711648 69 wait(0.1);
matirc 2:8b95be711648 70 if(d==N || y) {
matirc 3:151ac98b6252 71 statemenu = menu[statemenu].nextstate[0];
matirc 3:151ac98b6252 72 }
matirc 3:151ac98b6252 73 }
matirc 3:151ac98b6252 74 outputmenu=menu[statemenu].position;
matirc 3:151ac98b6252 75 //pc.printf("%d\n",statemenu);
matirc 2:8b95be711648 76 }
matirc 2:8b95be711648 77
matirc 3:151ac98b6252 78 //if selection is true, the games selector screen is running
matirc 2:8b95be711648 79 void game()
matirc 2:8b95be711648 80 {
matirc 3:151ac98b6252 81 drawselectscreen(); //displays games to be chosen
matirc 2:8b95be711648 82 Direction d = pad.get_direction();
matirc 2:8b95be711648 83 if (d==S || a) {
matirc 3:151ac98b6252 84 wait(0.1); //small debouncing
matirc 2:8b95be711648 85 if (d==S || a) {
matirc 3:151ac98b6252 86 state = games[state].nextstate[1];
matirc 3:151ac98b6252 87 }
matirc 2:8b95be711648 88 }
matirc 2:8b95be711648 89 if (d==N || y) {
matirc 2:8b95be711648 90 wait(0.1);
matirc 2:8b95be711648 91 if(d==N || y) {
matirc 3:151ac98b6252 92 state = games[state].nextstate[0];//same as previous function
matirc 3:151ac98b6252 93 wait(0.1);
matirc 3:151ac98b6252 94 }
matirc 3:151ac98b6252 95 }
matirc 2:8b95be711648 96 output=games[state].position;
matirc 3:151ac98b6252 97 //pc.printf("%d\n",state);
matirc 2:8b95be711648 98
matirc 2:8b95be711648 99 }
matirc 3:151ac98b6252 100 //in the menu screen,the player selects the desired option screen by pressing l
matirc 2:8b95be711648 101 void menuselect()
matirc 2:8b95be711648 102 {
matirc 3:151ac98b6252 103 if(l && outputmenu==0) { //if one option is chosen
matirc 3:151ac98b6252 104 menuselection=false; //stop running menu screen, log off from this screen
matirc 3:151ac98b6252 105 selection=true; //start running the chosen option, log in in this screen
matirc 3:151ac98b6252 106 newgame(); //do the chosen option functions
matirc 2:8b95be711648 107 }
matirc 3:151ac98b6252 108
matirc 2:8b95be711648 109 if(l && outputmenu==1) {
matirc 2:8b95be711648 110 menuselection=false;
matirc 2:8b95be711648 111 highscr=true;
matirc 2:8b95be711648 112 highscores();
matirc 2:8b95be711648 113 }
matirc 3:151ac98b6252 114
matirc 3:151ac98b6252 115 if(l && outputmenu==2) {
matirc 2:8b95be711648 116 menuselection=false;
matirc 2:8b95be711648 117 tut=true;
matirc 2:8b95be711648 118 tutorial();
matirc 2:8b95be711648 119 }
matirc 3:151ac98b6252 120
matirc 3:151ac98b6252 121 if(l && outputmenu==3) {
matirc 2:8b95be711648 122 menuselection=false;
matirc 2:8b95be711648 123 stor=true;
matirc 2:8b95be711648 124 story();
matirc 2:8b95be711648 125 }
matirc 2:8b95be711648 126 }
matirc 0:1ed3f8d98beb 127
matirc 3:151ac98b6252 128 //same as previous function but instead of wih menu options wih the different games
matirc 1:101e060118fa 129
matirc 2:8b95be711648 130 void select()
matirc 0:1ed3f8d98beb 131 {
matirc 2:8b95be711648 132 if(start && output==0) {
matirc 2:8b95be711648 133 selection=false;
matirc 2:8b95be711648 134 game1=true;
matirc 2:8b95be711648 135 gameone();
matirc 2:8b95be711648 136 }
matirc 2:8b95be711648 137 if(start && output==1) {
matirc 2:8b95be711648 138 selection=false;
matirc 2:8b95be711648 139 game2=true;
matirc 2:8b95be711648 140 gametwo();
matirc 2:8b95be711648 141 }
matirc 2:8b95be711648 142 if(start && output==2) {
matirc 2:8b95be711648 143 selection=false;
matirc 2:8b95be711648 144 game3=true;
matirc 2:8b95be711648 145 gamethree();
matirc 2:8b95be711648 146 }
matirc 2:8b95be711648 147 if(start && output==3) {
matirc 2:8b95be711648 148 selection=false;
matirc 2:8b95be711648 149 game4=true;
matirc 2:8b95be711648 150 gamefour();
matirc 2:8b95be711648 151 }
matirc 2:8b95be711648 152 if(start && output==4) {
matirc 2:8b95be711648 153 selection=false;
matirc 2:8b95be711648 154 game5=true;
matirc 2:8b95be711648 155 gamefive();
matirc 2:8b95be711648 156 }
matirc 0:1ed3f8d98beb 157 }
matirc 0:1ed3f8d98beb 158
matirc 0:1ed3f8d98beb 159
matirc 0:1ed3f8d98beb 160
matirc 2:8b95be711648 161 //////////////////////GAMES/////////////////////////////////////////////////////
matirc 2:8b95be711648 162 void gamefive()
matirc 2:8b95be711648 163 {
matirc 3:151ac98b6252 164 while(game5) { //if game 5 running
matirc 3:151ac98b6252 165
matirc 3:151ac98b6252 166 //pc.printf("game05\n");
matirc 3:151ac98b6252 167
matirc 2:8b95be711648 168 float pott=pad.read_pot();
matirc 2:8b95be711648 169 lcd.setBrightness(pott);
matirc 2:8b95be711648 170 if(back) {
matirc 3:151ac98b6252 171 if (tau.score()>scoreg5) { //if back,get the score if bigger than the previous one
matirc 2:8b95be711648 172 scoreg5=tau.score();
matirc 2:8b95be711648 173 }
matirc 3:151ac98b6252 174 game5=false; //log off the game 5 function
matirc 3:151ac98b6252 175 selection=true; //go back to games selecor screen,log into it
matirc 2:8b95be711648 176 }
matirc 3:151ac98b6252 177 tau.game(lcd,pad,a,start,b,x); //performs game 5
matirc 3:151ac98b6252 178
matirc 2:8b95be711648 179 }
matirc 2:8b95be711648 180 }
matirc 0:1ed3f8d98beb 181
matirc 1:101e060118fa 182 void gamefour()
matirc 1:101e060118fa 183 {
matirc 3:151ac98b6252 184
matirc 3:151ac98b6252 185 //pc.printf("game04\n");
matirc 3:151ac98b6252 186
matirc 1:101e060118fa 187 while(game4) {
matirc 1:101e060118fa 188 float pott=pad.read_pot();
matirc 1:101e060118fa 189 lcd.setBrightness(pott);
matirc 3:151ac98b6252 190 if(back) { //same as before
matirc 2:8b95be711648 191 game4=false;
matirc 2:8b95be711648 192 selection=true;
matirc 2:8b95be711648 193 }
matirc 3:151ac98b6252 194 if(!cer.die()) { //if player hasnt died
matirc 3:151ac98b6252 195 cer.commands(b,a,x,y,pad); //performs the game in the addecuate order of first commands(players input)
matirc 3:151ac98b6252 196 cer.updatescr(); //then updates the movment of the blocks and check if they are dopped(refer to library for more info)
matirc 3:151ac98b6252 197 cer.draw(lcd); //draws the game and checks if player dies
matirc 3:151ac98b6252 198 cer.velocities(); //depending on the score increase or not the game velocity
matirc 3:151ac98b6252 199 } else if(cer.die()) { //if died game over and allows to restart
matirc 2:8b95be711648 200 cer.gameover(lcd,start);
matirc 2:8b95be711648 201 if (cer.score()>scoreg4) {
matirc 2:8b95be711648 202 scoreg4=cer.score();
matirc 2:8b95be711648 203 }
matirc 1:101e060118fa 204 }
matirc 1:101e060118fa 205 }
matirc 1:101e060118fa 206 }
matirc 1:101e060118fa 207
matirc 1:101e060118fa 208 void gamethree()
matirc 1:101e060118fa 209 {
matirc 3:151ac98b6252 210
matirc 3:151ac98b6252 211 //pc.printf("game03\n");
matirc 3:151ac98b6252 212
matirc 1:101e060118fa 213 while(game3) {
matirc 0:1ed3f8d98beb 214 float pott=pad.read_pot();
matirc 0:1ed3f8d98beb 215 lcd.setBrightness(pott);
matirc 3:151ac98b6252 216 if(back) { //same as before
matirc 2:8b95be711648 217 game3=false;
matirc 2:8b95be711648 218 selection=true;
matirc 2:8b95be711648 219 }
matirc 3:151ac98b6252 220 if(aurig.touch()) { //if bird didnt touch the pipes
matirc 3:151ac98b6252 221 srand( time( NULL ) ); //genrates random
matirc 3:151ac98b6252 222 aurig.pipegenerator(pad,start); //generaes pipes (for more info refer to library)
matirc 3:151ac98b6252 223 aurig.updatescr(a,b,x,y,pad); //updates the screen movement and bird movement
matirc 1:101e060118fa 224 aurig.draw(lcd);
matirc 1:101e060118fa 225 wait(0.05);
matirc 3:151ac98b6252 226 } else { //if bird touched the pipes
matirc 3:151ac98b6252 227 aurig.gameover(lcd,pad,l,r); //gameover and allows to reset
matirc 2:8b95be711648 228 if (aurig.score()>scoreg3) {
matirc 2:8b95be711648 229 scoreg3=aurig.score();
matirc 2:8b95be711648 230 }
matirc 1:101e060118fa 231 }
matirc 1:101e060118fa 232 }
matirc 1:101e060118fa 233 }
matirc 0:1ed3f8d98beb 234
matirc 1:101e060118fa 235 void gametwo()
matirc 1:101e060118fa 236 {
matirc 3:151ac98b6252 237
matirc 3:151ac98b6252 238 //pc.printf("game02\n");
matirc 3:151ac98b6252 239
matirc 2:8b95be711648 240 alienmove.attach(&aliens, 1.0);
matirc 0:1ed3f8d98beb 241 while(game2) {
matirc 0:1ed3f8d98beb 242 float pott=pad.read_pot();
matirc 0:1ed3f8d98beb 243 lcd.setBrightness(pott);
matirc 3:151ac98b6252 244 if(back) { //same as before
matirc 2:8b95be711648 245 game2=false;
matirc 2:8b95be711648 246 selection=true;
matirc 3:151ac98b6252 247 alienmove.detach(); //detach the movement of the aliens if the player gets out of the game
matirc 2:8b95be711648 248 }
matirc 3:151ac98b6252 249 if (!stym.die()) { //if player didnt die (refer to library for more info)
matirc 3:151ac98b6252 250 stym.leds(pad); //lifes showed in the leds
matirc 3:151ac98b6252 251 stym.commands(pad,l,b,x,r); //input
matirc 3:151ac98b6252 252 stym.touch(); //checks if any bullet has hitted anything
matirc 1:101e060118fa 253 srand(time(NULL));
matirc 3:151ac98b6252 254 stym.auxiliar(); //generates new alien bullets
matirc 3:151ac98b6252 255 stym.updatescr(); //updates the movement
matirc 3:151ac98b6252 256 stym.draw(lcd); //draws the screen
matirc 3:151ac98b6252 257 wait(0.08); //small delay
matirc 3:151ac98b6252 258 } else if(stym.die()) { //if dead
matirc 3:151ac98b6252 259 stym.gameover(lcd,start,pad); //gameover allowing to restart
matirc 2:8b95be711648 260 if (stym.score()>scoreg2) {
matirc 2:8b95be711648 261 scoreg2=stym.score();
matirc 2:8b95be711648 262 }
matirc 1:101e060118fa 263 }
matirc 1:101e060118fa 264 }
matirc 1:101e060118fa 265 }
matirc 0:1ed3f8d98beb 266
matirc 0:1ed3f8d98beb 267
matirc 0:1ed3f8d98beb 268 void gameone()
matirc 0:1ed3f8d98beb 269 {
matirc 2:8b95be711648 270
matirc 3:151ac98b6252 271 //pc.printf("game01\n");
matirc 3:151ac98b6252 272
matirc 0:1ed3f8d98beb 273 while(game1) {
matirc 2:8b95be711648 274 float pott=pad.read_pot();
matirc 2:8b95be711648 275 lcd.setBrightness(pott);
matirc 3:151ac98b6252 276 if(back) { //same as before
matirc 2:8b95be711648 277 game1=false;
matirc 2:8b95be711648 278 selection=true;
matirc 2:8b95be711648 279 }
matirc 3:151ac98b6252 280 if (hyd.border()) { //if player didnt hit anything
matirc 3:151ac98b6252 281 hyd.leds(pad); //lifes
matirc 3:151ac98b6252 282 hyd.commands(pad,a,b,x,y); //input(refer to library for more info)
matirc 3:151ac98b6252 283 if (hyd.eat()) { //if snake eats food
matirc 3:151ac98b6252 284 pad.tone(NOTE_GS6,0.5);
matirc 0:1ed3f8d98beb 285 srand( time( NULL ) );
matirc 3:151ac98b6252 286 hyd.auxiliar(); //generates new food
matirc 1:101e060118fa 287 }
matirc 3:151ac98b6252 288 hyd.updatescr(); //updates movement
matirc 3:151ac98b6252 289 hyd.pausegame(l,r,lcd,back); //checks if the game has been paused
matirc 3:151ac98b6252 290 hyd.draw(lcd); //draws screen
matirc 3:151ac98b6252 291 hyd.touch(); //checks if snake ates itself
matirc 3:151ac98b6252 292 hyd.velocities(); //the higher score the faster the gam will go
matirc 1:101e060118fa 293 } else {
matirc 1:101e060118fa 294 hyd.gameover(lcd,start,pad);
matirc 2:8b95be711648 295 if (hyd.score()>scoreg1) {
matirc 2:8b95be711648 296 scoreg1=hyd.score();
matirc 2:8b95be711648 297 }
matirc 1:101e060118fa 298 }
matirc 0:1ed3f8d98beb 299 }
matirc 0:1ed3f8d98beb 300 }
matirc 0:1ed3f8d98beb 301
matirc 2:8b95be711648 302 ///////////////////////////////////////////////////////////////////////////////
matirc 2:8b95be711648 303
matirc 3:151ac98b6252 304 //draws the games selector screen
matirc 2:8b95be711648 305 void drawselectscreen()
matirc 2:8b95be711648 306 {
matirc 2:8b95be711648 307 lcd.clear();
matirc 2:8b95be711648 308
matirc 2:8b95be711648 309 if(output==0) {
matirc 2:8b95be711648 310 lcd.drawRect(0,8,84,8,FILL_BLACK);
matirc 2:8b95be711648 311 }
matirc 2:8b95be711648 312 if(output==1) {
matirc 2:8b95be711648 313 lcd.drawRect(0,16,84,8,FILL_BLACK);
matirc 2:8b95be711648 314 }
matirc 2:8b95be711648 315 if(output==2) {
matirc 2:8b95be711648 316 lcd.drawRect(0,24,84,8,FILL_BLACK);
matirc 2:8b95be711648 317 }
matirc 2:8b95be711648 318 if(output==3) {
matirc 2:8b95be711648 319 lcd.drawRect(0,32,84,8,FILL_BLACK);
matirc 2:8b95be711648 320 }
matirc 2:8b95be711648 321 if(output==4) {
matirc 2:8b95be711648 322 lcd.drawRect(0,40,84,8,FILL_BLACK);
matirc 2:8b95be711648 323 }
matirc 2:8b95be711648 324 lcd.printString("DEMETER",0,1);
matirc 2:8b95be711648 325 lcd.printString("ZEUS",0,2);
matirc 2:8b95be711648 326 lcd.printString("HERA",0,3);
matirc 2:8b95be711648 327 lcd.printString("POSEIDON",0,4);
matirc 2:8b95be711648 328 lcd.printString("HADES",0,5);
matirc 2:8b95be711648 329 lcd.refresh();
matirc 2:8b95be711648 330 }
matirc 3:151ac98b6252 331 //draws the men options selectors
matirc 2:8b95be711648 332 void drawselectmenu()
matirc 2:8b95be711648 333 {
matirc 2:8b95be711648 334 lcd.clear();
matirc 2:8b95be711648 335 lcd.printString("MENU",30,0);
matirc 3:151ac98b6252 336 lcd.printString("GAME",0,2);
matirc 3:151ac98b6252 337 lcd.printString("SCORES",0,3);
matirc 3:151ac98b6252 338 lcd.printString("TUTORIAL",0,4);
matirc 3:151ac98b6252 339 lcd.printString("STORY",0,5);
matirc 2:8b95be711648 340
matirc 2:8b95be711648 341 if(outputmenu==0) {
matirc 2:8b95be711648 342 lcd.drawRect(0,16,84,8,FILL_BLACK);
matirc 2:8b95be711648 343 lcd.printString("GAME",0,2);
matirc 2:8b95be711648 344 }
matirc 2:8b95be711648 345 if(outputmenu==1) {
matirc 2:8b95be711648 346 lcd.drawRect(0,24,84,8,FILL_BLACK);
matirc 3:151ac98b6252 347 lcd.printString("SCORES",0,3);
matirc 2:8b95be711648 348 }
matirc 2:8b95be711648 349 if(outputmenu==2) {
matirc 2:8b95be711648 350 lcd.drawRect(0,32,84,8,FILL_BLACK);
matirc 3:151ac98b6252 351 lcd.printString("TUTORIAL",0,4);
matirc 2:8b95be711648 352 }
matirc 2:8b95be711648 353 if(outputmenu==3) {
matirc 2:8b95be711648 354 lcd.drawRect(0,40,84,8,FILL_BLACK);
matirc 2:8b95be711648 355 lcd.printString("STORY",0,5);
matirc 2:8b95be711648 356 }
matirc 3:151ac98b6252 357
matirc 2:8b95be711648 358 lcd.refresh();
matirc 2:8b95be711648 359 }
matirc 2:8b95be711648 360
matirc 3:151ac98b6252 361 //prints the intro
matirc 2:8b95be711648 362 void intro()
matirc 2:8b95be711648 363 {
matirc 3:151ac98b6252 364 //pc.printf("intro\n");
matirc 2:8b95be711648 365 Bitmap sprite(randulfe,15,72);
matirc 2:8b95be711648 366 sprite.render(lcd,6,0);
matirc 2:8b95be711648 367 sprite.print();
matirc 2:8b95be711648 368 lcd.printString("presents",5,4);
matirc 2:8b95be711648 369 lcd.refresh();
matirc 2:8b95be711648 370 wait(1);
matirc 2:8b95be711648 371 lcd.printString(".",60,4);
matirc 2:8b95be711648 372 lcd.refresh();
matirc 2:8b95be711648 373 wait(1);
matirc 2:8b95be711648 374 lcd.printString(".",65,4);
matirc 2:8b95be711648 375 lcd.refresh();
matirc 2:8b95be711648 376 wait(1);
matirc 2:8b95be711648 377 lcd.printString(".",70,4);
matirc 2:8b95be711648 378 lcd.refresh();
matirc 2:8b95be711648 379 wait(1);
matirc 2:8b95be711648 380 lcd.clear();
matirc 2:8b95be711648 381 Bitmap sprite1(gamename,15,72);
matirc 2:8b95be711648 382 Bitmap sprite2(gamename1,17,72);
matirc 2:8b95be711648 383 Bitmap sprite3(gamename2,10,13);
matirc 2:8b95be711648 384 sprite1.render(lcd,0,0);
matirc 2:8b95be711648 385 sprite3.render(lcd,25,15);
matirc 2:8b95be711648 386 sprite2.render(lcd,4,26);
matirc 2:8b95be711648 387 sprite1.print();
matirc 2:8b95be711648 388 sprite3.print();
matirc 2:8b95be711648 389 sprite2.print();
matirc 2:8b95be711648 390 lcd.refresh();
matirc 2:8b95be711648 391 wait(8);
matirc 1:101e060118fa 392 lcd.clear();
matirc 2:8b95be711648 393 lcd.printString("In menu scr:",0,0);
matirc 2:8b95be711648 394 lcd.printString("select:l",0,1);
matirc 2:8b95be711648 395 lcd.printString("Back:r",0,2);
matirc 2:8b95be711648 396 lcd.printString("In game scr:",0,3);
matirc 2:8b95be711648 397 lcd.printString("select:start",0,4);
matirc 2:8b95be711648 398 lcd.printString("Back:back",0,5);
matirc 2:8b95be711648 399 lcd.refresh();
matirc 3:151ac98b6252 400 wait(4);
matirc 3:151ac98b6252 401 lcd.clear();
matirc 3:151ac98b6252 402 lcd.printString("In the games",0,0);
matirc 3:151ac98b6252 403 lcd.printString("the leds",0,1);
matirc 3:151ac98b6252 404 lcd.printString("indicate",0,2);
matirc 3:151ac98b6252 405 lcd.printString("your lifes",0,3);
matirc 3:151ac98b6252 406 lcd.printString("left!",0,4);
matirc 3:151ac98b6252 407 lcd.refresh();
matirc 3:151ac98b6252 408 wait(4);
matirc 2:8b95be711648 409 }
matirc 3:151ac98b6252 410
matirc 3:151ac98b6252 411 //performs story screen and the story selector algorithm as the one i showed previously
matirc 2:8b95be711648 412 void story()
matirc 2:8b95be711648 413 {
matirc 3:151ac98b6252 414 //pc.printf("story\n");
matirc 2:8b95be711648 415 while(stor) {
matirc 2:8b95be711648 416 lcd.clear();
matirc 2:8b95be711648 417 lcd.printString("NEXT",60,5);
matirc 2:8b95be711648 418 if(outputstory==0) {
matirc 2:8b95be711648 419 lcd.printString("Hey there! :)",0,0);
matirc 2:8b95be711648 420 lcd.printString("Welcome to the",0,1);
matirc 2:8b95be711648 421 lcd.printString("Olympus.Hestia",0,2);
matirc 2:8b95be711648 422 lcd.printString("God of home,",0,3);
matirc 2:8b95be711648 423 lcd.printString("needs your hlp",0,4);
matirc 2:8b95be711648 424 }
matirc 2:8b95be711648 425 if(outputstory==1) {
matirc 2:8b95be711648 426 lcd.printString("for protecting",0,0);
matirc 2:8b95be711648 427 lcd.printString("the sacred",0,1);
matirc 2:8b95be711648 428 lcd.printString("fire.But first",0,2);
matirc 2:8b95be711648 429 lcd.printString("you need to",0,3);
matirc 2:8b95be711648 430 lcd.printString("prove to the",0,4);
matirc 2:8b95be711648 431 }
matirc 2:8b95be711648 432 if(outputstory==2) {
matirc 2:8b95be711648 433 lcd.printString("ancient gods",0,0);
matirc 2:8b95be711648 434 lcd.printString("(siblings of",0,1);
matirc 2:8b95be711648 435 lcd.printString("Hestia) that",0,2);
matirc 2:8b95be711648 436 lcd.printString("you're a brave",0,3);
matirc 2:8b95be711648 437 lcd.printString("soldier.",0,4);
matirc 2:8b95be711648 438 }
matirc 2:8b95be711648 439
matirc 2:8b95be711648 440 if(outputstory==3) {
matirc 2:8b95be711648 441 lcd.printString("You must pass",0,0);
matirc 2:8b95be711648 442 lcd.printString("their challen-",0,1);
matirc 2:8b95be711648 443 lcd.printString("-ges!Get ",0,2);
matirc 2:8b95be711648 444 lcd.printString("ready for the",0,3);
matirc 2:8b95be711648 445 lcd.printString("adventure!!!",0,4);
matirc 2:8b95be711648 446 }
matirc 2:8b95be711648 447 lcd.refresh();
matirc 2:8b95be711648 448
matirc 2:8b95be711648 449 Direction d = pad.get_direction();
matirc 3:151ac98b6252 450 if (d==E || b) {
matirc 3:151ac98b6252 451 wait(0.1);
matirc 3:151ac98b6252 452 if (d==E || b) {
matirc 2:8b95be711648 453 statestory = games[statestory].nextstate[1];
matirc 3:151ac98b6252 454 }
matirc 2:8b95be711648 455 }
matirc 3:151ac98b6252 456 if (d==W || x) {
matirc 3:151ac98b6252 457 wait(0.1);
matirc 3:151ac98b6252 458 if (d==W || x) {
matirc 2:8b95be711648 459 statestory = games[statestory].nextstate[0];
matirc 3:151ac98b6252 460 }
matirc 2:8b95be711648 461 }
matirc 2:8b95be711648 462 outputstory=games[statestory].position;
matirc 2:8b95be711648 463 if(r) {
matirc 2:8b95be711648 464 stor=false;
matirc 2:8b95be711648 465 menuselection=true;
matirc 2:8b95be711648 466 }
matirc 1:101e060118fa 467 }
matirc 2:8b95be711648 468 }
matirc 0:1ed3f8d98beb 469
matirc 3:151ac98b6252 470 //shows scores for each game and a total score
matirc 2:8b95be711648 471 void highscores()
matirc 2:8b95be711648 472 {
matirc 3:151ac98b6252 473 //pc.printf("highscores\n");
matirc 3:151ac98b6252 474 while(highscr) {
matirc 2:8b95be711648 475 lcd.clear();
matirc 3:151ac98b6252 476 sprintf(buffer0,"TOT score=%2d",totalscore);
matirc 3:151ac98b6252 477 lcd.printString(buffer0,0,0);
matirc 3:151ac98b6252 478 sprintf(buffer1,"Game 1=%2d",scoreg1);
matirc 3:151ac98b6252 479 lcd.printString(buffer1,0,1);
matirc 3:151ac98b6252 480 sprintf(buffer2,"Game 2=%2d",scoreg2);
matirc 3:151ac98b6252 481 lcd.printString(buffer2,0,2);
matirc 3:151ac98b6252 482 sprintf(buffer3,"Game 3=%2d",scoreg3);
matirc 3:151ac98b6252 483 lcd.printString(buffer3,0,3);
matirc 3:151ac98b6252 484 sprintf(buffer4,"Game 4=%2d",scoreg4);
matirc 3:151ac98b6252 485 lcd.printString(buffer4,0,4);
matirc 3:151ac98b6252 486 sprintf(buffer5,"Game 5=%2d",scoreg5);
matirc 3:151ac98b6252 487 lcd.printString(buffer5,0,5);
matirc 2:8b95be711648 488 lcd.refresh();
matirc 3:151ac98b6252 489 if(r) {
matirc 2:8b95be711648 490 highscr=false;
matirc 3:151ac98b6252 491 menuselection=true;
matirc 3:151ac98b6252 492 }
matirc 3:151ac98b6252 493 }
matirc 2:8b95be711648 494 }
matirc 2:8b95be711648 495
matirc 3:151ac98b6252 496 //draws the tutorial screens and allows to switch between options as showed previousl
matirc 2:8b95be711648 497 void tutorial()
matirc 2:8b95be711648 498 {
matirc 3:151ac98b6252 499 //pc.printf("tutorial\n");
matirc 2:8b95be711648 500 while(tut) {
matirc 2:8b95be711648 501 lcd.clear();
matirc 2:8b95be711648 502 lcd.printChar('1',0,0);
matirc 2:8b95be711648 503 lcd.printChar('2',16,0);
matirc 2:8b95be711648 504 lcd.printChar('3',32,0);
matirc 2:8b95be711648 505 lcd.printChar('4',48,0);
matirc 2:8b95be711648 506 lcd.printChar('5',64,0);
matirc 2:8b95be711648 507
matirc 2:8b95be711648 508 if(outpututorial==0) {
matirc 2:8b95be711648 509 lcd.drawRect(0,0,9,9,FILL_BLACK);
matirc 2:8b95be711648 510 lcd.printString("Y,A,X,B:",0,2);
matirc 2:8b95be711648 511 lcd.printString("UP,DWN,LFT,RGT",0,3);
matirc 2:8b95be711648 512 lcd.printString("L,R PAUSE",0,5);
matirc 2:8b95be711648 513 }
matirc 2:8b95be711648 514 if(outpututorial==1) {
matirc 2:8b95be711648 515 lcd.drawRect(16,0,9,9,FILL_BLACK);
matirc 2:8b95be711648 516 lcd.printString("A,B,JOY:",0,2);
matirc 2:8b95be711648 517 lcd.printString("MOVE RGT/LFT",0,3);
matirc 2:8b95be711648 518 lcd.printString("L,R SHOOT",0,5);
matirc 2:8b95be711648 519 }
matirc 2:8b95be711648 520 if(outpututorial==2) {
matirc 2:8b95be711648 521 lcd.drawRect(32,0,9,9,FILL_BLACK);
matirc 2:8b95be711648 522 lcd.printString("A,B,X,Y:",0,2);
matirc 2:8b95be711648 523 lcd.printString("JUMP",0,3);
matirc 2:8b95be711648 524 }
matirc 2:8b95be711648 525 if(outpututorial==3) {
matirc 2:8b95be711648 526 lcd.drawRect(48,0,9,9,FILL_BLACK);
matirc 2:8b95be711648 527 lcd.printString("A/B/X/Y:",0,2);
matirc 2:8b95be711648 528 lcd.printString("LEAVE BLOCK",0,3);
matirc 2:8b95be711648 529 }
matirc 2:8b95be711648 530 if(outpututorial==4) {
matirc 2:8b95be711648 531 lcd.drawRect(64,0,9,9,FILL_BLACK);
matirc 2:8b95be711648 532 lcd.printString("JOY:",0,2);
matirc 2:8b95be711648 533 lcd.printString("SELECT",0,3);
matirc 2:8b95be711648 534 lcd.printString("A:CONTINUE",0,5);
matirc 2:8b95be711648 535 }
matirc 2:8b95be711648 536 lcd.refresh();
matirc 2:8b95be711648 537
matirc 2:8b95be711648 538 Direction d = pad.get_direction();
matirc 3:151ac98b6252 539 if (d==E || b) {
matirc 3:151ac98b6252 540 wait(0.1);
matirc 3:151ac98b6252 541 if (d==E || b) {
matirc 2:8b95be711648 542 statetutorial = games[statetutorial].nextstate[1];
matirc 3:151ac98b6252 543 }
matirc 2:8b95be711648 544 }
matirc 3:151ac98b6252 545 if (d==W || x) {
matirc 3:151ac98b6252 546 wait(0.1);
matirc 3:151ac98b6252 547 if (d==W || x) {
matirc 2:8b95be711648 548 statetutorial = games[statetutorial].nextstate[0];
matirc 3:151ac98b6252 549
matirc 3:151ac98b6252 550 }}
matirc 2:8b95be711648 551 outpututorial=games[statetutorial].position;
matirc 2:8b95be711648 552 if(r) {
matirc 2:8b95be711648 553 tut=false;
matirc 2:8b95be711648 554 menuselection=true;
matirc 2:8b95be711648 555 }
matirc 2:8b95be711648 556
matirc 2:8b95be711648 557
matirc 2:8b95be711648 558 }
matirc 2:8b95be711648 559 }
matirc 3:151ac98b6252 560 //ligh function for increasing one in the intro
matirc 2:8b95be711648 561 void lights()
matirc 2:8b95be711648 562 {
matirc 2:8b95be711648 563
matirc 2:8b95be711648 564 if(k==1 && lit>6) {
matirc 2:8b95be711648 565 k=-1;
matirc 2:8b95be711648 566 }
matirc 2:8b95be711648 567 if(k==-1 && lit<0) {
matirc 2:8b95be711648 568 k=1;
matirc 2:8b95be711648 569 }
matirc 2:8b95be711648 570 lit+=k;
matirc 2:8b95be711648 571
matirc 2:8b95be711648 572
matirc 2:8b95be711648 573 for(int i=1; i<lit; i++) {
matirc 2:8b95be711648 574 pad.led(i,1);
matirc 2:8b95be711648 575 }
matirc 2:8b95be711648 576 }
matirc 3:151ac98b6252 577 //function that allows the ticker to peform a library function
matirc 2:8b95be711648 578 void aliens()
matirc 2:8b95be711648 579 {
matirc 2:8b95be711648 580 stym.move();
matirc 2:8b95be711648 581 }
matirc 3:151ac98b6252 582 //initialise objects
matirc 0:1ed3f8d98beb 583 void init()
matirc 0:1ed3f8d98beb 584 {
matirc 3:151ac98b6252 585 //pc.printf("game starts\n");
matirc 2:8b95be711648 586 introlights.attach(&lights,1);
matirc 1:101e060118fa 587 tau.init();
matirc 0:1ed3f8d98beb 588 cer.init();
matirc 0:1ed3f8d98beb 589 aurig.init();
matirc 0:1ed3f8d98beb 590 stym.init();
matirc 0:1ed3f8d98beb 591 hyd.init();
matirc 0:1ed3f8d98beb 592 pad.init();
matirc 0:1ed3f8d98beb 593 lcd.init();
matirc 1:101e060118fa 594 lcd.normalMode();
matirc 0:1ed3f8d98beb 595 lcd.setBrightness(0.5);
matirc 0:1ed3f8d98beb 596 }