Snake Game using accelerometer with many fun features.
Dependencies: C12832 MMA7660 mbed
Fork of app-board-Bubble-Level by
Revision 3:2d625f49afb9, committed 2015-02-19
- Comitter:
- Xinliang_Zhao
- Date:
- Thu Feb 19 10:26:14 2015 +0000
- Parent:
- 2:dd83ac1aba6c
- Commit message:
- Snake game using accelerometer with many fun features
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r dd83ac1aba6c -r 2d625f49afb9 main.cpp --- a/main.cpp Thu Feb 19 08:15:47 2015 +0000 +++ b/main.cpp Thu Feb 19 10:26:14 2015 +0000 @@ -21,6 +21,7 @@ //static C12832_LCD lcd; PwmOut spkr(p26); + int level = 1; int score = 0; bool acc_joy = true; @@ -85,6 +86,7 @@ snake.x[2] = 64; snake.y[2] = 16; snake.node_num = 3; + while(true) { if(fire) { acc_joy = !acc_joy; @@ -142,6 +144,7 @@ for(int i = 0; i < snake.node_num; i++) { lcd.fillrect(snake.x[i], snake.y[i], snake.x[i] + 3, snake.y[i] + 3, 1); + lcd.rect(0,0,127,31,1); } wait(0.5 - 0.1 * level); @@ -153,13 +156,14 @@ while(true) { game_play(); lcd.cls(); + lcd.rect(0,0,127,31,1); lcd.locate(35,6); lcd.printf("GAME OVER"); lcd.locate(16,16); lcd.printf("MOVE THE JOYSTICK"); - while(!check_joy() || fire) { + while(!check_joy() && !fire) { for (float i=2000.0; i<10000.0; i+=100) { - if(check_joy()) { + if(check_joy() || fire) { break; } spkr.period(1.0/i); @@ -169,11 +173,15 @@ spkr=0.0; } lcd.cls(); + lcd.rect(0,0,127,31,1); lcd.locate(35,6); lcd.printf("LENGTH: %d", snake.node_num); lcd.locate(35,16); lcd.printf("SCORE: %d", score); + + wait(3); + lcd.cls(); } }