Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Joystick N5110 SDFileSystem beep fsmMenu mbed
Fork of SnakeProjectRev1 by
Diff: main.cpp
- Revision:
- 19:8907a82ebe09
- Parent:
- 18:67d5ae64fbd1
- Child:
- 20:f634b1060981
--- a/main.cpp Wed May 04 18:27:39 2016 +0000 +++ b/main.cpp Wed May 04 19:20:40 2016 +0000 @@ -54,65 +54,8 @@ LB.rise(&lb_isr); - while(1) { - - lcd.printString("Classic",0,1); - lcd.printString("Infinite",0,3); - lcd.printString("Hard Map",0,5); - - if (rb_flag == 1) { - rb_flag = 0; - gamePlaying = true; - mainGame(); - //break; - } - - // check if flag i.e. interrupt has occured - if (printFlag ==1) { - printFlag = 0; // if it has, clear the flag + mainMenu(); - // swap direction when button has been pressed - // (could just use ! but want this to be explicit to aid understanding) - if (joystick.direction == CENTRE) { - serial.printf(" CENTRE\n"); - menuDirection = menuSTOP; - } - else if (joystick.direction == UP) { - serial.printf(" UP\n"); - menuDirection = menuUP; - buzzer.beep(2000,0.2); - } - else if (joystick.direction == DOWN) { - serial.printf(" DOWN\n"); - menuDirection = menuDOWN; - buzzer.beep(2000,0.2); - } - } - - - menuFSM(); - - - wait(0.2); // small delay - if (state ==0) { - lcd.clear(); - lcd.printString("*",70,1); - gameType = classicMode; - } - else if (state ==1) { - lcd.clear(); - lcd.printString("*",70,3); - gameType = infiniteMode; - } - else if (state ==2) { - lcd.clear(); - lcd.printString("*",70,5); - gameType = hardMode; - } - - } - - //mainGame(); } @@ -330,7 +273,8 @@ } if (lb_flag == 1) { lb_flag = 0; - + gamePlaying = false; + mainMenu(); } sleep(); } @@ -489,7 +433,8 @@ initSnakeTail(); snakeTailLength = 3; score = 0; - fruitValue = 10; // init everything + fruitValue = 10; + pauseCount = 0; // init everything while(gamePlaying == true) { @@ -516,8 +461,63 @@ void mainMenu() { + while(1) { + + lcd.printString("Classic",0,1); + lcd.printString("Infinite",0,3); + lcd.printString("Hard Map",0,5); + + if (rb_flag == 1) { + rb_flag = 0; + gamePlaying = true; + mainGame(); + } + + // check if flag i.e. interrupt has occured + if (printFlag ==1) { + printFlag = 0; // if it has, clear the flag + + // swap direction when button has been pressed + // (could just use ! but want this to be explicit to aid understanding) + if (joystick.direction == CENTRE) { + serial.printf(" CENTRE\n"); + menuDirection = menuSTOP; + } + else if (joystick.direction == UP) { + serial.printf(" UP\n"); + menuDirection = menuUP; + buzzer.beep(2000,0.2); + } + else if (joystick.direction == DOWN) { + serial.printf(" DOWN\n"); + menuDirection = menuDOWN; + buzzer.beep(2000,0.2); + } + } + menuFSM(); + + + wait(0.2); // small delay + if (state ==0) { + lcd.clear(); + lcd.printString("*",70,1); + gameType = classicMode; + } + else if (state ==1) { + lcd.clear(); + lcd.printString("*",70,3); + gameType = infiniteMode; + } + else if (state ==2) { + lcd.clear(); + lcd.printString("*",70,5); + gameType = hardMode; + } + + } + } void timer_isr()