![](/media/cache/profiles/LinkedIn_0NghoZJ.jpeg.50x50_q85.jpg)
Snake vs Block Game to be run upon K64F.
GameEngine/WinLoose/WinLoose.cpp@85:d50ba0994676, 2019-05-06 (annotated)
- Committer:
- AhmedPlaymaker
- Date:
- Mon May 06 23:41:03 2019 +0000
- Revision:
- 85:d50ba0994676
- Parent:
- 83:329da564799a
- Child:
- 87:871d9fecb593
I Think the tutorial needs no more content work... But i know i cant help but improvise ;)
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 | 83:329da564799a | 13 | void WinLoose::init(N5110 *lcd, Gamepad *pad) |
AhmedPlaymaker | 83:329da564799a | 14 | { |
AhmedPlaymaker | 83:329da564799a | 15 | _lcd = lcd; |
AhmedPlaymaker | 83:329da564799a | 16 | _pad = pad; |
AhmedPlaymaker | 83:329da564799a | 17 | } |
AhmedPlaymaker | 83:329da564799a | 18 | |
AhmedPlaymaker | 83:329da564799a | 19 | int WinLoose::LevelComplete(int level) |
AhmedPlaymaker | 44:cd10d07ea1e5 | 20 | { |
AhmedPlaymaker | 44:cd10d07ea1e5 | 21 | level += 1; |
AhmedPlaymaker | 83:329da564799a | 22 | _lcd->clear(); |
AhmedPlaymaker | 83:329da564799a | 23 | _lcd->printString("Level Complete",0,1); |
AhmedPlaymaker | 83:329da564799a | 24 | _lcd->printString("Press Start",10,3); |
AhmedPlaymaker | 83:329da564799a | 25 | _lcd->printString("to Proceed",12,4); |
AhmedPlaymaker | 83:329da564799a | 26 | _lcd->refresh(); |
AhmedPlaymaker | 63:205f0ca48473 | 27 | wait(0.05); //to avoid race condition of skipping the following while loop. |
AhmedPlaymaker | 83:329da564799a | 28 | while ((_pad->check_event(Gamepad::START_PRESSED) == false)&&(_pad->check_event(Gamepad::A_PRESSED) == false)) { |
AhmedPlaymaker | 83:329da564799a | 29 | _pad->leds_on(); |
AhmedPlaymaker | 83:329da564799a | 30 | _pad->tone(rand()%1001,0.1); //helps to set max freq for random sound |
AhmedPlaymaker | 44:cd10d07ea1e5 | 31 | wait(0.1); |
AhmedPlaymaker | 83:329da564799a | 32 | _pad->leds_off(); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 33 | wait(0.1); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 34 | } |
AhmedPlaymaker | 83:329da564799a | 35 | WinLoose::displayLevel(level); |
AhmedPlaymaker | 49:441c32f6603e | 36 | return level; |
AhmedPlaymaker | 49:441c32f6603e | 37 | } |
AhmedPlaymaker | 49:441c32f6603e | 38 | |
AhmedPlaymaker | 83:329da564799a | 39 | void WinLoose::displayLevel(int level) |
AhmedPlaymaker | 49:441c32f6603e | 40 | { |
AhmedPlaymaker | 44:cd10d07ea1e5 | 41 | sprintf(bufferlevel,"%d",level); |
AhmedPlaymaker | 83:329da564799a | 42 | _lcd->printString("Level:",25,1); |
AhmedPlaymaker | 83:329da564799a | 43 | _lcd->printString(bufferlevel,40,3); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 44 | wait(2); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 45 | } |
AhmedPlaymaker | 63:205f0ca48473 | 46 | |
AhmedPlaymaker | 83:329da564799a | 47 | void WinLoose::GameOver() |
AhmedPlaymaker | 44:cd10d07ea1e5 | 48 | { |
AhmedPlaymaker | 83:329da564799a | 49 | //_pad->init(); |
AhmedPlaymaker | 83:329da564799a | 50 | while ((_pad->check_event(Gamepad::BACK_PRESSED) == false)) { |
AhmedPlaymaker | 83:329da564799a | 51 | _lcd->clear(); |
AhmedPlaymaker | 83:329da564799a | 52 | _lcd->printString("Game",33,1); |
AhmedPlaymaker | 83:329da564799a | 53 | _lcd->printString("Over",33,3); |
AhmedPlaymaker | 83:329da564799a | 54 | _lcd->printString("Press Back",14,5); //Function used to promt the user to Restart. |
AhmedPlaymaker | 83:329da564799a | 55 | _lcd->refresh(); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 56 | wait(0.1); |
AhmedPlaymaker | 44:cd10d07ea1e5 | 57 | } |
AhmedPlaymaker | 83:329da564799a | 58 | _lcd->clear(); |
AhmedPlaymaker | 49:441c32f6603e | 59 | //NVIC_SystemReset(); //Software Reset. |
AhmedPlaymaker | 44:cd10d07ea1e5 | 60 | } |