Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Committer:
AhmedPlaymaker
Date:
Mon Apr 29 12:09:31 2019 +0000
Revision:
59:c65a2e933c47
Parent:
55:df0825049171
Child:
61:f3c402bc2ad0
Changed Winning criteria and level progression in general, also fixed an error with motion control in menu and joystick misbehavior problem, next is tutorials.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AhmedPlaymaker 44:cd10d07ea1e5 1 #include "WinLoose.h"
AhmedPlaymaker 44:cd10d07ea1e5 2
AhmedPlaymaker 44:cd10d07ea1e5 3 WinLoose::WinLoose()
AhmedPlaymaker 44:cd10d07ea1e5 4 {
AhmedPlaymaker 44:cd10d07ea1e5 5
AhmedPlaymaker 44:cd10d07ea1e5 6 }
AhmedPlaymaker 44:cd10d07ea1e5 7
AhmedPlaymaker 44:cd10d07ea1e5 8 WinLoose::~WinLoose()
AhmedPlaymaker 44:cd10d07ea1e5 9 {
AhmedPlaymaker 44:cd10d07ea1e5 10
AhmedPlaymaker 44:cd10d07ea1e5 11 }
AhmedPlaymaker 44:cd10d07ea1e5 12
AhmedPlaymaker 46:dc7dccae9f9e 13 int WinLoose::LevelComplete(N5110 &lcd, Gamepad &pad, int level)
AhmedPlaymaker 44:cd10d07ea1e5 14 {
AhmedPlaymaker 44:cd10d07ea1e5 15 level += 1;
AhmedPlaymaker 44:cd10d07ea1e5 16 lcd.clear();
AhmedPlaymaker 44:cd10d07ea1e5 17 lcd.printString("Level Complete",0,1);
AhmedPlaymaker 44:cd10d07ea1e5 18 lcd.printString("Press Start",10,3);
AhmedPlaymaker 44:cd10d07ea1e5 19 lcd.printString("to Proceed",12,4);
AhmedPlaymaker 44:cd10d07ea1e5 20 lcd.refresh();
AhmedPlaymaker 44:cd10d07ea1e5 21 while (pad.check_event(Gamepad::START_PRESSED) == false) {
AhmedPlaymaker 44:cd10d07ea1e5 22 pad.leds_on();
AhmedPlaymaker 44:cd10d07ea1e5 23 pad.tone(rand()%1001,0.1); //helps to set max freq for random sound
AhmedPlaymaker 44:cd10d07ea1e5 24 wait(0.1);
AhmedPlaymaker 44:cd10d07ea1e5 25 pad.leds_off();
AhmedPlaymaker 44:cd10d07ea1e5 26 wait(0.1);
AhmedPlaymaker 44:cd10d07ea1e5 27 }
AhmedPlaymaker 49:441c32f6603e 28 WinLoose::displayLevel(lcd, level);
AhmedPlaymaker 49:441c32f6603e 29 return level;
AhmedPlaymaker 49:441c32f6603e 30 }
AhmedPlaymaker 49:441c32f6603e 31
AhmedPlaymaker 49:441c32f6603e 32 void WinLoose::displayLevel(N5110 &lcd, int level)
AhmedPlaymaker 49:441c32f6603e 33 {
AhmedPlaymaker 44:cd10d07ea1e5 34 lcd.clear();
AhmedPlaymaker 44:cd10d07ea1e5 35 sprintf(bufferlevel,"%d",level);
AhmedPlaymaker 44:cd10d07ea1e5 36 lcd.printString("Level:",25,1);
AhmedPlaymaker 44:cd10d07ea1e5 37 lcd.printString(bufferlevel,40,3);
AhmedPlaymaker 44:cd10d07ea1e5 38 lcd.refresh();
AhmedPlaymaker 44:cd10d07ea1e5 39 wait(2);
AhmedPlaymaker 44:cd10d07ea1e5 40 }
AhmedPlaymaker 44:cd10d07ea1e5 41
AhmedPlaymaker 44:cd10d07ea1e5 42 void WinLoose::GameOver(N5110 &lcd, Gamepad &pad)
AhmedPlaymaker 44:cd10d07ea1e5 43 {
AhmedPlaymaker 44:cd10d07ea1e5 44 pad.init();
AhmedPlaymaker 44:cd10d07ea1e5 45 while ((pad.check_event(Gamepad::BACK_PRESSED) == false)) {
AhmedPlaymaker 44:cd10d07ea1e5 46 lcd.clear();
AhmedPlaymaker 44:cd10d07ea1e5 47 lcd.printString("Game",33,1);
AhmedPlaymaker 44:cd10d07ea1e5 48 lcd.printString("Over",33,3);
AhmedPlaymaker 44:cd10d07ea1e5 49 lcd.printString("Press Back",14,5); //Function used to promt the user to Restart.
AhmedPlaymaker 44:cd10d07ea1e5 50 lcd.refresh();
AhmedPlaymaker 44:cd10d07ea1e5 51 wait(0.1);
AhmedPlaymaker 44:cd10d07ea1e5 52 }
AhmedPlaymaker 55:df0825049171 53 lcd.clear();
AhmedPlaymaker 49:441c32f6603e 54 //NVIC_SystemReset(); //Software Reset.
AhmedPlaymaker 44:cd10d07ea1e5 55 }