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:
- 18:67d5ae64fbd1
- Parent:
- 17:4e6f0f7f22fb
- Child:
- 19:8907a82ebe09
--- a/main.cpp Wed May 04 17:31:25 2016 +0000 +++ b/main.cpp Wed May 04 18:27:39 2016 +0000 @@ -45,11 +45,7 @@ redLed = 0; lcd.init(); //snakeIntro(); - //hardWall(); - //wrapAround(); - //generateFood(); gamePlaying = false; - //initSnakeTail(); button.rise(&buttonISR); gameTicker.attach(&timer_isr,0.1); RB.mode(PullDown); @@ -67,7 +63,8 @@ if (rb_flag == 1) { rb_flag = 0; gamePlaying = true; - break; + mainGame(); + //break; } // check if flag i.e. interrupt has occured @@ -115,7 +112,7 @@ } - mainGame(); + //mainGame(); } @@ -220,7 +217,8 @@ lcd.refresh(); lcd.drawRect(randomX,randomY,1,1,1); // food - if (gameType == classicMode) { + + if (gameType == classicMode) { // map types hardWall(); } else if (gameType == infiniteMode) { @@ -299,7 +297,7 @@ if (length <= 14) { // if string will fit on display lcd.printString(buffer,0,1); } // display on screen buzzer.beep(262,2); - + wait(0.5); ////////////////////// Simple reading example ////////////////////////// // now open file for reading @@ -323,25 +321,33 @@ lcd.printString("RB - Restart",0,4); wait(0.5); lcd.printString("LB - Menu",0,5); - /* if (RB == 0) { - moveSnake(); - } */ + + while(1) { + if (rb_flag == 1) { + rb_flag = 0; + gamePlaying = true; + mainGame(); + } + if (lb_flag == 1) { + lb_flag = 0; + + } + sleep(); + } + } void specialMap() { - for (int x=41; x<43; x++) { // vertical cross line - for (int y=14; y<34; y++) { - lcd.setPixel(i,j); - lcd.refresh(); - } - } - for (int x=32; x<52; x++) { // horizontal cross line - for (int y=23; y<25; y++) { - lcd.setPixel(i,j); - lcd.refresh(); - } + lcd.drawRect(0,0,83,47,0); + lcd.refresh(); + if (i == 0 || i+1 == 0 || + i == 83 || i+1 == 83 || // if any of the 4 pixels within the snake head touch the border + j == 0 || j+1 == 0 || + j == 47 || j+1 == 47) + { + gameOver(); } } @@ -481,6 +487,7 @@ } generateFood(); initSnakeTail(); + snakeTailLength = 3; score = 0; fruitValue = 10; // init everything @@ -507,6 +514,11 @@ } } +void mainMenu() { + + + +} void timer_isr() {