Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
Diff: StartScreen/StartScreen.cpp
- Revision:
- 34:89f53ffc81bb
- Parent:
- 33:249cf423fb18
- Child:
- 35:ce47cde57bd3
diff -r 249cf423fb18 -r 89f53ffc81bb StartScreen/StartScreen.cpp --- a/StartScreen/StartScreen.cpp Wed Apr 17 07:47:06 2019 +0000 +++ b/StartScreen/StartScreen.cpp Wed Apr 17 08:54:40 2019 +0000 @@ -187,10 +187,35 @@ StartScreen::init(); pad.init(); while ((pad.check_event(Gamepad::A_PRESSED) == false)&&(pad.check_event(Gamepad::START_PRESSED) == false)) { //Change this to if button pressed. - StartScreen::DisplaySc1Contents(lcd, pad); + StartScreen::DisplayMMContents(lcd, pad); } pad.tone(1000.0,0.1); wait(1/cs); + StartScreen::ImplementMM(lcd, pad, sd); +} + +void StartScreen::DisplayMMContents(N5110 &lcd, Gamepad &pad) +{ + lcd.printString("SnakeVSBlock",5,0); + lcd.printString("Play",0,2); + lcd.printString("Settings",0,3); + lcd.printString("Stats",0,4); + lcd.printString("Tutorial",0,5); + Direction d = pad.get_direction(); + if((d==N)&&(i>16)) { + i=i-8; + } + if((d==S)&&(i<40)) { + i=i+8; + } + lcd.drawSprite(50,i,7,9,(int *)arrow); //Function used to draw the sprite. + lcd.refresh(); + wait(1/cs); + lcd.clear(); +} + +void StartScreen::ImplementMM(N5110 &lcd, Gamepad &pad, SDFileSystem &sd) +{ if(i == 16) { game_mode(lcd, pad, sd); } @@ -213,65 +238,57 @@ } } -void StartScreen::DisplaySc1Contents(N5110 &lcd, Gamepad &pad) -{ - lcd.printString("SnakeVSBlock",5,0); - lcd.printString("Play",0,2); - lcd.printString("Settings",0,3); - lcd.printString("Stats",0,4); - lcd.printString("Tutorial",0,5); - Direction d = pad.get_direction(); - if((d==N)&&(i>16)) { - i=i-8; - } - if((d==S)&&(i<40)) { - i=i+8; - } - lcd.drawSprite(50,i,7,9,(int *)arrow); //Function used to draw the sprite. - lcd.refresh(); - wait(1/cs); - lcd.clear(); -} - void StartScreen::game_mode(N5110 &lcd, Gamepad &pad, SDFileSystem &sd) { lcd.clear(); 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)||(d==W))&&(lr==1)) { - lr=2; + StartScreen::DisplayGMContents(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; } - - else if(((d==E)||(d==W))&&(lr==2)) { - lr=1; - } + else {back_pressed = 0;} + } + if(back_pressed) { + main_menu(lcd, pad, sd); + } + else { + gs = 1; + pad.tone(1000.0,0.1); lcd.clear(); - lcd.drawRect(27,18,30,20,FILL_TRANSPARENT); - 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. - if(lr==1) { - lcd.printString("Free Wave",14,1); - lcd.refresh(); - } - if(lr==2) { - lcd.printString("Bullet Shower",4,1); - lcd.drawSprite(29,19,13,5,(int *)bullet); //Function used to draw the sprite. - } - if (pad.check_event(Gamepad::BACK_PRESSED) == true) { - pad.tone(1000.0,0.1); - main_menu(lcd, pad, sd); - } + game_speed(lcd, pad, sd); + } +} + +void StartScreen::DisplayGMContents(N5110 &lcd, Gamepad &pad) +{ + Direction d = pad.get_direction(); + wait(1/cs); + if(((d==E)||(d==W))&&(lr==1)) { + lr=2; + } + + else if(((d==E)||(d==W))&&(lr==2)) { + lr=1; + } + lcd.clear(); + lcd.drawRect(27,18,30,20,FILL_TRANSPARENT); + 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. + if(lr==1) { + lcd.printString("Joystick",18,1); lcd.refresh(); } - gs = 1; - pad.tone(1000.0,0.1); - lcd.clear(); - game_speed(lcd, pad, sd); + if(lr==2) { + lcd.printString("Motion Control",1,1); + lcd.drawSprite(29,19,13,5,(int *)bullet); //Function used to draw the sprite. + } + lcd.refresh(); } + void StartScreen::game_speed(N5110 &lcd, Gamepad &pad, SDFileSystem &sd) { lcd.clear();