![](/media/cache/profiles/LinkedIn_0NghoZJ.jpeg.50x50_q85.jpg)
Snake vs Block Game to be run upon K64F.
GameEngine/WinLoose/WinLoose.cpp@55:df0825049171, 2019-04-27 (annotated)
- Committer:
- AhmedPlaymaker
- Date:
- Sat Apr 27 18:56:30 2019 +0000
- Revision:
- 55:df0825049171
- Parent:
- 51:387249f9b333
- Child:
- 59:c65a2e933c47
Converted menus from if implementation to case structures
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 | 49:441c32f6603e | 29 | WinLoose::displayLevel(lcd, level); |
AhmedPlaymaker | 49:441c32f6603e | 30 | return level; |
AhmedPlaymaker | 49:441c32f6603e | 31 | } |
AhmedPlaymaker | 49:441c32f6603e | 32 | |
AhmedPlaymaker | 49:441c32f6603e | 33 | void WinLoose::displayLevel(N5110 &lcd, int level) |
AhmedPlaymaker | 49:441c32f6603e | 34 | { |
AhmedPlaymaker | 44:cd10d07ea1e5 | 35 | lcd.clear(); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 36 | sprintf(bufferlevel,"%d",level); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 37 | lcd.printString("Level:",25,1); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 38 | lcd.printString(bufferlevel,40,3); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 39 | lcd.refresh(); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 40 | wait(2); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 41 | } |
AhmedPlaymaker | 44:cd10d07ea1e5 | 42 | |
AhmedPlaymaker | 44:cd10d07ea1e5 | 43 | void WinLoose::GameOver(N5110 &lcd, Gamepad &pad) |
AhmedPlaymaker | 44:cd10d07ea1e5 | 44 | { |
AhmedPlaymaker | 44:cd10d07ea1e5 | 45 | pad.init(); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 46 | while ((pad.check_event(Gamepad::BACK_PRESSED) == false)) { |
AhmedPlaymaker | 44:cd10d07ea1e5 | 47 | lcd.clear(); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 48 | lcd.printString("Game",33,1); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 49 | lcd.printString("Over",33,3); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 50 | lcd.printString("Press Back",14,5); //Function used to promt the user to Restart. |
AhmedPlaymaker | 44:cd10d07ea1e5 | 51 | lcd.refresh(); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 52 | wait(0.1); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 53 | } |
AhmedPlaymaker | 55:df0825049171 | 54 | lcd.clear(); |
AhmedPlaymaker | 49:441c32f6603e | 55 | //NVIC_SystemReset(); //Software Reset. |
AhmedPlaymaker | 44:cd10d07ea1e5 | 56 | } |