Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
GameEngine/WinLoose/WinLoose.cpp@63:205f0ca48473, 2019-05-01 (annotated)
- Committer:
- AhmedPlaymaker
- Date:
- Wed May 01 22:35:40 2019 +0000
- Revision:
- 63:205f0ca48473
- Parent:
- 62:ebf6ecf8a6d5
- Child:
- 83:329da564799a
Sorted out some functions, specifically related to their functionality
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 | 63:205f0ca48473 | 21 | wait(0.05); //to avoid race condition of skipping the following while loop. |
AhmedPlaymaker | 63:205f0ca48473 | 22 | while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_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 | 63:205f0ca48473 | 42 | |
AhmedPlaymaker | 44:cd10d07ea1e5 | 43 | void WinLoose::GameOver(N5110 &lcd, Gamepad &pad) |
AhmedPlaymaker | 44:cd10d07ea1e5 | 44 | { |
AhmedPlaymaker | 61:f3c402bc2ad0 | 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 | } |