Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
WinLoose/WinLoose.cpp@46:dc7dccae9f9e, 2019-04-26 (annotated)
- Committer:
- AhmedPlaymaker
- Date:
- Fri Apr 26 11:36:01 2019 +0000
- Revision:
- 46:dc7dccae9f9e
- Parent:
- 44:cd10d07ea1e5
- Child:
- 49:441c32f6603e
Levels were not getting saved because of a previous edit, fixed it!
Who changed what in which revision?
User | Revision | Line number | New 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 | 46:dc7dccae9f9e | 21 | pad.init(); //to fix an issue with debouncing. |
AhmedPlaymaker | 44:cd10d07ea1e5 | 22 | while (pad.check_event(Gamepad::START_PRESSED) == false) { |
AhmedPlaymaker | 44:cd10d07ea1e5 | 23 | pad.leds_on(); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 24 | pad.tone(rand()%1001,0.1); //helps to set max freq for random sound |
AhmedPlaymaker | 44:cd10d07ea1e5 | 25 | wait(0.1); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 26 | pad.leds_off(); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 27 | wait(0.1); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 28 | } |
AhmedPlaymaker | 44:cd10d07ea1e5 | 29 | lcd.clear(); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 30 | sprintf(bufferlevel,"%d",level); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 31 | lcd.printString("Level:",25,1); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 32 | lcd.printString(bufferlevel,40,3); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 33 | lcd.refresh(); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 34 | wait(2); |
AhmedPlaymaker | 46:dc7dccae9f9e | 35 | return level; |
AhmedPlaymaker | 44:cd10d07ea1e5 | 36 | } |
AhmedPlaymaker | 44:cd10d07ea1e5 | 37 | |
AhmedPlaymaker | 44:cd10d07ea1e5 | 38 | void WinLoose::GameOver(N5110 &lcd, Gamepad &pad) |
AhmedPlaymaker | 44:cd10d07ea1e5 | 39 | { |
AhmedPlaymaker | 44:cd10d07ea1e5 | 40 | pad.init(); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 41 | while ((pad.check_event(Gamepad::BACK_PRESSED) == false)) { |
AhmedPlaymaker | 44:cd10d07ea1e5 | 42 | lcd.clear(); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 43 | lcd.printString("Game",33,1); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 44 | lcd.printString("Over",33,3); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 45 | lcd.printString("Press Back",14,5); //Function used to promt the user to Restart. |
AhmedPlaymaker | 44:cd10d07ea1e5 | 46 | lcd.refresh(); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 47 | wait(0.1); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 48 | } |
AhmedPlaymaker | 44:cd10d07ea1e5 | 49 | NVIC_SystemReset(); //Software Reset. //change this condition to loosing screen. |
AhmedPlaymaker | 44:cd10d07ea1e5 | 50 | } |