![](/media/cache/profiles/LinkedIn_0NghoZJ.jpeg.50x50_q85.jpg)
Snake vs Block Game to be run upon K64F.
Diff: Snake/Snake.cpp
- Revision:
- 16:7b474f873683
- Parent:
- 13:9785f2404045
- Child:
- 17:54e13faeaf64
diff -r f4d069da093d -r 7b474f873683 Snake/Snake.cpp --- a/Snake/Snake.cpp Thu Apr 04 18:50:40 2019 +0000 +++ b/Snake/Snake.cpp Fri Apr 05 05:46:11 2019 +0000 @@ -28,7 +28,7 @@ } -void Snake::draw(N5110 &lcd, int length) +void Snake::draw(Gamepad &pad, N5110 &lcd, int length) { if(m == 0){ _x = WIDTH/2; //Spawns player sprite near the middle of the screen. @@ -65,34 +65,42 @@ } //printf("SPRITE %d %d \n", _x, _y); if(length == 0) { - NVIC_SystemReset(); //Software Reset. //change this condition to loosing screen. + while ((pad.check_event(Gamepad::BACK_PRESSED) == false)) { + lcd.clear(); + lcd.printString("Game",33,1); + lcd.printString("Over",33,3); + lcd.printString("Press Back",14,5); //Function used to promt the user to Restart. + lcd.refresh(); + wait(0.1); + } + NVIC_SystemReset(); //Software Reset. //change this condition to loosing screen. } - if(length == 1) { + else if(length == 1) { lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite. } - if(length == 2) { + else if(length == 2) { lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite. lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite); } - if(length == 3) { + else if(length == 3) { lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite. lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite); lcd.drawSprite(_xb,_yb,3,3,(int *)snake_sprite); } - if(length == 4) { + else if(length == 4) { lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite. lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite); lcd.drawSprite(_xb,_yb,3,3,(int *)snake_sprite); lcd.drawSprite(_xc,_yc,3,3,(int *)snake_sprite); } - if(length == 5) { + else if(length == 5) { lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite. lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite); lcd.drawSprite(_xb,_yb,3,3,(int *)snake_sprite); lcd.drawSprite(_xc,_yc,3,3,(int *)snake_sprite); lcd.drawSprite(_xd,_yd,3,3,(int *)snake_sprite); } - if(length == 6) { + else if(length == 6) { lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite. lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite); lcd.drawSprite(_xb,_yb,3,3,(int *)snake_sprite); @@ -100,7 +108,7 @@ lcd.drawSprite(_xd,_yd,3,3,(int *)snake_sprite); lcd.drawSprite(_xe,_ye,3,3,(int *)snake_sprite); } - if(length == 7) { + else if(length == 7) { lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite. lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite); lcd.drawSprite(_xb,_yb,3,3,(int *)snake_sprite); @@ -109,7 +117,7 @@ lcd.drawSprite(_xe,_ye,3,3,(int *)snake_sprite); lcd.drawSprite(_xf,_yf,3,3,(int *)snake_sprite); } - if(length == 8) { + else if(length == 8) { lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite. lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite); lcd.drawSprite(_xb,_yb,3,3,(int *)snake_sprite); @@ -119,7 +127,7 @@ lcd.drawSprite(_xf,_yf,3,3,(int *)snake_sprite); lcd.drawSprite(_xg,_yg,3,3,(int *)snake_sprite); } - if(length == 9) { + else if(length == 9) { lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite. lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite); lcd.drawSprite(_xb,_yb,3,3,(int *)snake_sprite); @@ -130,7 +138,7 @@ lcd.drawSprite(_xg,_yg,3,3,(int *)snake_sprite); lcd.drawSprite(_xh,_yh,3,3,(int *)snake_sprite); } - if(length == 10) { + else if(length == 10) { lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite. lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite); lcd.drawSprite(_xb,_yb,3,3,(int *)snake_sprite); @@ -142,7 +150,7 @@ lcd.drawSprite(_xh,_yh,3,3,(int *)snake_sprite); lcd.drawSprite(_xi,_yi,3,3,(int *)snake_sprite); } - if(length == 11) { + else if(length == 11) { lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite. lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite); lcd.drawSprite(_xb,_yb,3,3,(int *)snake_sprite); @@ -155,7 +163,7 @@ lcd.drawSprite(_xi,_yi,3,3,(int *)snake_sprite); lcd.drawSprite(_xj,_yj,3,3,(int *)snake_sprite); } - if(length == 12) { + else if(length == 12) { lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite. lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite); lcd.drawSprite(_xb,_yb,3,3,(int *)snake_sprite); @@ -169,7 +177,7 @@ lcd.drawSprite(_xj,_yj,3,3,(int *)snake_sprite); lcd.drawSprite(_xk,_yk,3,3,(int *)snake_sprite); } - if(length == 13) { + else if(length == 13) { lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite. lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite); lcd.drawSprite(_xb,_yb,3,3,(int *)snake_sprite); @@ -184,7 +192,7 @@ lcd.drawSprite(_xk,_yk,3,3,(int *)snake_sprite); lcd.drawSprite(_xl,_yl,3,3,(int *)snake_sprite); } - if(length == 14) { + else if(length == 14) { lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite. lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite); lcd.drawSprite(_xb,_yb,3,3,(int *)snake_sprite); @@ -200,7 +208,7 @@ lcd.drawSprite(_xl,_yl,3,3,(int *)snake_sprite); lcd.drawSprite(_xm,_ym,3,3,(int *)snake_sprite); } - if(length == 15) { + else if(length == 15) { lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite. lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite); lcd.drawSprite(_xb,_yb,3,3,(int *)snake_sprite);