Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
Diff: StartScreen/StartScreen.cpp
- Revision:
- 35:ce47cde57bd3
- Parent:
- 34:89f53ffc81bb
- Child:
- 36:dfdd619874ae
--- a/StartScreen/StartScreen.cpp Wed Apr 17 08:54:40 2019 +0000 +++ b/StartScreen/StartScreen.cpp Wed Apr 17 09:15:43 2019 +0000 @@ -295,54 +295,68 @@ wait(2/cs); pad.init(); while ((pad.check_event(Gamepad::A_PRESSED) == false)&&(pad.check_event(Gamepad::START_PRESSED) == false)) { //Change this to if button pressed. - - Direction d = pad.get_direction(); - wait(1/cs); - if((d==E)&&(gs==4)) { - gs=1; - } - else if((d==W)&&(gs==1)) { - gs=4; - } - else if((d==E)&&(1<=gs<=3)) { - gs=gs+1; - } - else if((d==W)&&(2<=gs<=4)) { - gs=gs-1; - } - lcd.clear(); - lcd.drawSprite(10,22,13,8,(int *)navL); //Function used to draw the sprite. - lcd.drawSprite(65,22,13,8,(int *)navR); //Function used to draw the sprite. - lcd.printString("Game Speed",10,1); - if(gs==1) { - lcd.printString("SNAIL",26,3); - fps = 12; + StartScreen::ImplementGS(lcd, pad); + StartScreen::DisplayGSContents(lcd, pad); + if (pad.check_event(Gamepad::BACK_PRESSED) == true) { //This is a very important process, this helps the code to not get stuck in menu loop. + pad.tone(1000.0,0.1); + back_pressed = 1; + break; } - if(gs==2) { - lcd.printString("TURTLE",24,3); - fps = 18; - } - if(gs==3) { - lcd.printString("RABBIT",24,3); - fps = 22; - } - if(gs==4) { - lcd.printString("CHEETHA",21,3); - fps = 27; - } - - if (pad.check_event(Gamepad::BACK_PRESSED) == true) { - pad.tone(1000.0,0.1); - game_mode(lcd, pad, sd); - } + else {back_pressed = 0;} + } + if(back_pressed) { + game_mode(lcd, pad, sd); + } + else { + pad.tone(1000.0,0.1); + lcd.clear(); + wait(1/cs); + lcd.printString("Level:",25,1); //created so that the gamer can keep track of their game. //change this to be operated remotely + lcd.printString("1",40,3); lcd.refresh(); + wait(2); } - - pad.tone(1000.0,0.1); - lcd.clear(); +} + +void StartScreen::ImplementGS(N5110 &lcd, Gamepad &pad) +{ + Direction d = pad.get_direction(); wait(1/cs); - lcd.printString("Level:",25,1); //created so that the gamer can keep track of their game. //change this to be operated remotely - lcd.printString("1",40,3); + if((d==E)&&(gs==4)) { + gs=1; + } + else if((d==W)&&(gs==1)) { + gs=4; + } + else if((d==E)&&(1<=gs<=3)) { + gs=gs+1; + } + else if((d==W)&&(2<=gs<=4)) { + gs=gs-1; + } +} + +void StartScreen::DisplayGSContents(N5110 &lcd, Gamepad &pad) +{ + lcd.clear(); + lcd.drawSprite(10,22,13,8,(int *)navL); //Function used to draw the sprite. + lcd.drawSprite(65,22,13,8,(int *)navR); //Function used to draw the sprite. + lcd.printString("Game Speed",10,1); + if(gs==1) { + lcd.printString("SNAIL",26,3); + fps = 12; + } + if(gs==2) { + lcd.printString("TURTLE",24,3); + fps = 18; + } + if(gs==3) { + lcd.printString("RABBIT",24,3); + fps = 22; + } + if(gs==4) { + lcd.printString("CHEETHA",21,3); + fps = 27; + } lcd.refresh(); - wait(2); } \ No newline at end of file