![](/media/cache/profiles/LinkedIn_0NghoZJ.jpeg.50x50_q85.jpg)
Snake vs Block Game to be run upon K64F.
Diff: Snake/Snake.cpp
- Revision:
- 21:e41126528cc6
- Parent:
- 20:1e6338403427
- Child:
- 22:ee698f66146f
diff -r 1e6338403427 -r e41126528cc6 Snake/Snake.cpp --- a/Snake/Snake.cpp Tue Apr 09 05:32:54 2019 +0000 +++ b/Snake/Snake.cpp Wed Apr 10 04:08:13 2019 +0000 @@ -31,54 +31,54 @@ int Snake::draw(Gamepad &pad, N5110 &lcd, int length, int level) { if(m == 0){ - _x = WIDTH/2; //Spawns player sprite near the middle of the screen. - _xa = _x; - _xb = _xa; - _xc = _xb; - _xd = _xc; - _xe = _xd; - _xf = _xe; - _xg = _xf; - _xh = _xg; - _xi = _xh; - _xj = _xi; - _xk = _xj; - _xl = _xk; - _xm = _xl; - _xn = _xm; - _y = HEIGHT - 3; - _ya = _y-3; - _yb = _y-6; - _yc = _y-9; - _yd = _y-12; - _ye = _y-15; - _yf = _y-18; - _yg = _y-21; - _yh = _y-24; - _yi = _y-27; - _yj = _y-30; - _yk = _y-33; - _yl = _y-36; - _ym = _y-39; - _yn = _y-42; - b0 = 1; - b1 = 1; - b2 = 1; - b3 = 1; - b4 = 1; - b5 = 1; - b6 = 1; - b7 = 1; - b8 = 1; - b9 = 1; - b10 = 1; - b11 = 1; - b12 = 1; - b13 = 1; - b14 = 1; + _x[0] = WIDTH/2; //Spawns player sprite near the middle of the screen. + _x[1] = _x[0]; + _x[2] = _x[1]; + _x[3] = _x[2]; + _x[4] = _x[3]; + _x[5] = _x[4]; + _x[6] = _x[5]; + _x[7] = _x[6]; + _x[8] = _x[7]; + _x[9] = _x[8]; + _x[10] = _x[9]; + _x[11] = _x[10]; + _x[12] = _x[11]; + _x[13] = _x[12]; + _x[14] = _x[13]; + _y[0] = HEIGHT - 3; + _y[1] = _y[0] - 3; + _y[2] = _y[0] - 6; + _y[3] = _y[0] - 9; + _y[4] = _y[0] - 12; + _y[5] = _y[0] - 15; + _y[6] = _y[0] - 18; + _y[7] = _y[0] - 21; + _y[8] = _y[0] - 24; + _y[9] = _y[0] - 27; + _y[10] = _y[0] - 30; + _y[11] = _y[0] - 33; + _y[12] = _y[0] - 36; + _y[13] = _y[0] - 39; + _y[14] = _y[0] - 42; + b[0] = 1; + b[1] = 1; + b[2] = 1; + b[3] = 1; + b[4] = 1; + b[5] = 1; + b[6] = 1; + b[7] = 1; + b[8] = 1; + b[9] = 1; + b[10] = 1; + b[11] = 1; + b[12] = 1; + b[13] = 1; + b[14] = 1; m = m+1; } - //printf("SPRITE %d %d \n", _x, _y); + //printf("SPRITE %d %d \n", _x[0], _y[0]); if(length == 0) { while ((pad.check_event(Gamepad::BACK_PRESSED) == false)) { lcd.clear(); @@ -91,165 +91,165 @@ NVIC_SystemReset(); //Software Reset. //change this condition to loosing screen. } else if(length == 1) { - lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite. + lcd.drawSprite(_x[0],_y[0],3,3,(int *)snake_sprite); //Function used to draw the sprite. } 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); + lcd.drawSprite(_x[0],_y[0],3,3,(int *)snake_sprite); //Function used to draw the sprite. + lcd.drawSprite(_x[1],_y[1],3,3,(int *)snake_sprite); } 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); + lcd.drawSprite(_x[0],_y[0],3,3,(int *)snake_sprite); //Function used to draw the sprite. + lcd.drawSprite(_x[1],_y[1],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[2],_y[2],3,3,(int *)snake_sprite); } 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); + lcd.drawSprite(_x[0],_y[0],3,3,(int *)snake_sprite); //Function used to draw the sprite. + lcd.drawSprite(_x[1],_y[1],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[2],_y[2],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[3],_y[3],3,3,(int *)snake_sprite); } 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); + lcd.drawSprite(_x[0],_y[0],3,3,(int *)snake_sprite); //Function used to draw the sprite. + lcd.drawSprite(_x[1],_y[1],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[2],_y[2],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[3],_y[3],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[4],_y[4],3,3,(int *)snake_sprite); } 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); - lcd.drawSprite(_xc,_yc,3,3,(int *)snake_sprite); - lcd.drawSprite(_xd,_yd,3,3,(int *)snake_sprite); - lcd.drawSprite(_xe,_ye,3,3,(int *)snake_sprite); + lcd.drawSprite(_x[0],_y[0],3,3,(int *)snake_sprite); //Function used to draw the sprite. + lcd.drawSprite(_x[1],_y[1],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[2],_y[2],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[3],_y[3],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[4],_y[4],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[5],_y[5],3,3,(int *)snake_sprite); } 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); - lcd.drawSprite(_xc,_yc,3,3,(int *)snake_sprite); - lcd.drawSprite(_xd,_yd,3,3,(int *)snake_sprite); - lcd.drawSprite(_xe,_ye,3,3,(int *)snake_sprite); - lcd.drawSprite(_xf,_yf,3,3,(int *)snake_sprite); + lcd.drawSprite(_x[0],_y[0],3,3,(int *)snake_sprite); //Function used to draw the sprite. + lcd.drawSprite(_x[1],_y[1],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[2],_y[2],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[3],_y[3],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[4],_y[4],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[5],_y[5],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[6],_y[6],3,3,(int *)snake_sprite); } 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); - lcd.drawSprite(_xc,_yc,3,3,(int *)snake_sprite); - lcd.drawSprite(_xd,_yd,3,3,(int *)snake_sprite); - lcd.drawSprite(_xe,_ye,3,3,(int *)snake_sprite); - lcd.drawSprite(_xf,_yf,3,3,(int *)snake_sprite); - lcd.drawSprite(_xg,_yg,3,3,(int *)snake_sprite); + lcd.drawSprite(_x[0],_y[0],3,3,(int *)snake_sprite); //Function used to draw the sprite. + lcd.drawSprite(_x[1],_y[1],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[2],_y[2],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[3],_y[3],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[4],_y[4],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[5],_y[5],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[6],_y[6],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[7],_y[7],3,3,(int *)snake_sprite); } 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); - lcd.drawSprite(_xc,_yc,3,3,(int *)snake_sprite); - lcd.drawSprite(_xd,_yd,3,3,(int *)snake_sprite); - lcd.drawSprite(_xe,_ye,3,3,(int *)snake_sprite); - lcd.drawSprite(_xf,_yf,3,3,(int *)snake_sprite); - lcd.drawSprite(_xg,_yg,3,3,(int *)snake_sprite); - lcd.drawSprite(_xh,_yh,3,3,(int *)snake_sprite); + lcd.drawSprite(_x[0],_y[0],3,3,(int *)snake_sprite); //Function used to draw the sprite. + lcd.drawSprite(_x[1],_y[1],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[2],_y[2],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[3],_y[3],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[4],_y[4],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[5],_y[5],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[6],_y[6],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[7],_y[7],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[8],_y[8],3,3,(int *)snake_sprite); } 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); - lcd.drawSprite(_xc,_yc,3,3,(int *)snake_sprite); - lcd.drawSprite(_xd,_yd,3,3,(int *)snake_sprite); - lcd.drawSprite(_xe,_ye,3,3,(int *)snake_sprite); - lcd.drawSprite(_xf,_yf,3,3,(int *)snake_sprite); - lcd.drawSprite(_xg,_yg,3,3,(int *)snake_sprite); - lcd.drawSprite(_xh,_yh,3,3,(int *)snake_sprite); - lcd.drawSprite(_xi,_yi,3,3,(int *)snake_sprite); + lcd.drawSprite(_x[0],_y[0],3,3,(int *)snake_sprite); //Function used to draw the sprite. + lcd.drawSprite(_x[1],_y[1],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[2],_y[2],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[3],_y[3],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[4],_y[4],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[5],_y[5],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[6],_y[6],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[7],_y[7],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[8],_y[8],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[9],_y[9],3,3,(int *)snake_sprite); } 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); - lcd.drawSprite(_xc,_yc,3,3,(int *)snake_sprite); - lcd.drawSprite(_xd,_yd,3,3,(int *)snake_sprite); - lcd.drawSprite(_xe,_ye,3,3,(int *)snake_sprite); - lcd.drawSprite(_xf,_yf,3,3,(int *)snake_sprite); - lcd.drawSprite(_xg,_yg,3,3,(int *)snake_sprite); - lcd.drawSprite(_xh,_yh,3,3,(int *)snake_sprite); - lcd.drawSprite(_xi,_yi,3,3,(int *)snake_sprite); - lcd.drawSprite(_xj,_yj,3,3,(int *)snake_sprite); + lcd.drawSprite(_x[0],_y[0],3,3,(int *)snake_sprite); //Function used to draw the sprite. + lcd.drawSprite(_x[1],_y[1],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[2],_y[2],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[3],_y[3],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[4],_y[4],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[5],_y[5],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[6],_y[6],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[7],_y[7],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[8],_y[8],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[9],_y[9],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[10],_y[10],3,3,(int *)snake_sprite); } 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); - lcd.drawSprite(_xc,_yc,3,3,(int *)snake_sprite); - lcd.drawSprite(_xd,_yd,3,3,(int *)snake_sprite); - lcd.drawSprite(_xe,_ye,3,3,(int *)snake_sprite); - lcd.drawSprite(_xf,_yf,3,3,(int *)snake_sprite); - lcd.drawSprite(_xg,_yg,3,3,(int *)snake_sprite); - lcd.drawSprite(_xh,_yh,3,3,(int *)snake_sprite); - lcd.drawSprite(_xi,_yi,3,3,(int *)snake_sprite); - lcd.drawSprite(_xj,_yj,3,3,(int *)snake_sprite); - lcd.drawSprite(_xk,_yk,3,3,(int *)snake_sprite); + lcd.drawSprite(_x[0],_y[0],3,3,(int *)snake_sprite); //Function used to draw the sprite. + lcd.drawSprite(_x[1],_y[1],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[2],_y[2],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[3],_y[3],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[4],_y[4],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[5],_y[5],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[6],_y[6],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[7],_y[7],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[8],_y[8],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[9],_y[9],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[10],_y[10],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[11],_y[11],3,3,(int *)snake_sprite); } 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); - lcd.drawSprite(_xc,_yc,3,3,(int *)snake_sprite); - lcd.drawSprite(_xd,_yd,3,3,(int *)snake_sprite); - lcd.drawSprite(_xe,_ye,3,3,(int *)snake_sprite); - lcd.drawSprite(_xf,_yf,3,3,(int *)snake_sprite); - lcd.drawSprite(_xg,_yg,3,3,(int *)snake_sprite); - lcd.drawSprite(_xh,_yh,3,3,(int *)snake_sprite); - lcd.drawSprite(_xi,_yi,3,3,(int *)snake_sprite); - lcd.drawSprite(_xj,_yj,3,3,(int *)snake_sprite); - lcd.drawSprite(_xk,_yk,3,3,(int *)snake_sprite); - lcd.drawSprite(_xl,_yl,3,3,(int *)snake_sprite); + lcd.drawSprite(_x[0],_y[0],3,3,(int *)snake_sprite); //Function used to draw the sprite. + lcd.drawSprite(_x[1],_y[1],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[2],_y[2],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[3],_y[3],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[4],_y[4],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[5],_y[5],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[6],_y[6],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[7],_y[7],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[8],_y[8],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[9],_y[9],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[10],_y[10],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[11],_y[11],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[12],_y[12],3,3,(int *)snake_sprite); } 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); - lcd.drawSprite(_xc,_yc,3,3,(int *)snake_sprite); - lcd.drawSprite(_xd,_yd,3,3,(int *)snake_sprite); - lcd.drawSprite(_xe,_ye,3,3,(int *)snake_sprite); - lcd.drawSprite(_xf,_yf,3,3,(int *)snake_sprite); - lcd.drawSprite(_xg,_yg,3,3,(int *)snake_sprite); - lcd.drawSprite(_xh,_yh,3,3,(int *)snake_sprite); - lcd.drawSprite(_xi,_yi,3,3,(int *)snake_sprite); - lcd.drawSprite(_xj,_yj,3,3,(int *)snake_sprite); - lcd.drawSprite(_xk,_yk,3,3,(int *)snake_sprite); - lcd.drawSprite(_xl,_yl,3,3,(int *)snake_sprite); - lcd.drawSprite(_xm,_ym,3,3,(int *)snake_sprite); + lcd.drawSprite(_x[0],_y[0],3,3,(int *)snake_sprite); //Function used to draw the sprite. + lcd.drawSprite(_x[1],_y[1],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[2],_y[2],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[3],_y[3],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[4],_y[4],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[5],_y[5],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[6],_y[6],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[7],_y[7],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[8],_y[8],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[9],_y[9],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[10],_y[10],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[11],_y[11],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[12],_y[12],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[13],_y[13],3,3,(int *)snake_sprite); } 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); - lcd.drawSprite(_xc,_yc,3,3,(int *)snake_sprite); - lcd.drawSprite(_xd,_yd,3,3,(int *)snake_sprite); - lcd.drawSprite(_xe,_ye,3,3,(int *)snake_sprite); - lcd.drawSprite(_xf,_yf,3,3,(int *)snake_sprite); - lcd.drawSprite(_xg,_yg,3,3,(int *)snake_sprite); - lcd.drawSprite(_xh,_yh,3,3,(int *)snake_sprite); - lcd.drawSprite(_xi,_yi,3,3,(int *)snake_sprite); - lcd.drawSprite(_xj,_yj,3,3,(int *)snake_sprite); - lcd.drawSprite(_xk,_yk,3,3,(int *)snake_sprite); - lcd.drawSprite(_xl,_yl,3,3,(int *)snake_sprite); - lcd.drawSprite(_xm,_ym,3,3,(int *)snake_sprite); - lcd.drawSprite(_xn,_yn,3,3,(int *)snake_sprite); + lcd.drawSprite(_x[0],_y[0],3,3,(int *)snake_sprite); //Function used to draw the sprite. + lcd.drawSprite(_x[1],_y[1],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[2],_y[2],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[3],_y[3],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[4],_y[4],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[5],_y[5],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[6],_y[6],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[7],_y[7],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[8],_y[8],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[9],_y[9],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[10],_y[10],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[11],_y[11],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[12],_y[12],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[13],_y[13],3,3,(int *)snake_sprite); + lcd.drawSprite(_x[14],_y[14],3,3,(int *)snake_sprite); } else if(length > 15) { lcd.clear(); lcd.printString("Level Complete",0,1); lcd.refresh(); - wait(1); + wait(2); lcd.clear(); - lcd.printString("Press Start",3,1); - lcd.printString("to Proceed",5,3); + lcd.printString("Press Start",10,1); + lcd.printString("to Proceed",12,3); lcd.refresh(); - int sound = 1000; + int sound = 1000; //helps to set max freq for random sound while ( pad.check_event(Gamepad::START_PRESSED) == false) { pad.leds_on(); pad.tone(rand()%sound,0.1); @@ -257,7 +257,6 @@ pad.leds_off(); wait(0.1); } - wait(1); lcd.clear(); char bufferlevel[14]; sprintf(bufferlevel,"%d",level); @@ -273,63 +272,63 @@ Vector2D Snake::get_pos(int length) { if(length == 1) { - Vector2D snakepos = {_x,_y}; //Obtains the snake position. + Vector2D snakepos = {_x[0],_y[0]}; //Obtains the snake position. return snakepos; } else if(length == 2) { - Vector2D snakepos = {_xa,_ya}; //Obtains the snake position. + Vector2D snakepos = {_x[1],_y[1]}; //Obtains the snake position. return snakepos; } else if(length==3) { - Vector2D snakepos = {_xb,_yb}; //Obtains the snake position. + Vector2D snakepos = {_x[2],_y[2]}; //Obtains the snake position. return snakepos; } else if(length==4) { - Vector2D snakepos = {_xc,_yc}; //Obtains the snake position. + Vector2D snakepos = {_x[3],_y[3]}; //Obtains the snake position. return snakepos; } else if(length==5) { - Vector2D snakepos = {_xd,_yd}; //Obtains the snake position. + Vector2D snakepos = {_x[4],_y[4]}; //Obtains the snake position. return snakepos; } else if(length==6) { - Vector2D snakepos = {_xe,_ye}; //Obtains the snake position. + Vector2D snakepos = {_x[5],_y[5]}; //Obtains the snake position. return snakepos; } else if(length==7) { - Vector2D snakepos = {_xf,_yf}; //Obtains the snake position. + Vector2D snakepos = {_x[6],_y[6]}; //Obtains the snake position. return snakepos; } else if(length==8) { - Vector2D snakepos = {_xg,_yg}; //Obtains the snake position. + Vector2D snakepos = {_x[7],_y[7]}; //Obtains the snake position. return snakepos; } else if(length==9) { - Vector2D snakepos = {_xh,_yh}; //Obtains the snake position. + Vector2D snakepos = {_x[8],_y[8]}; //Obtains the snake position. return snakepos; } else if(length==10) { - Vector2D snakepos = {_xi,_yi}; //Obtains the snake position. + Vector2D snakepos = {_x[9],_y[9]}; //Obtains the snake position. return snakepos; } else if(length==11) { - Vector2D snakepos = {_xj,_yj}; //Obtains the snake position. + Vector2D snakepos = {_x[10],_y[10]}; //Obtains the snake position. return snakepos; } else if(length==12) { - Vector2D snakepos = {_xk,_yk}; //Obtains the snake position. + Vector2D snakepos = {_x[11],_y[11]}; //Obtains the snake position. return snakepos; } else if(length==13) { - Vector2D snakepos = {_xl,_yl}; //Obtains the snake position. + Vector2D snakepos = {_x[12],_y[12]}; //Obtains the snake position. return snakepos; } else if(length == 14) { - Vector2D snakepos = {_xm,_ym}; //Obtains the snake position. + Vector2D snakepos = {_x[13],_y[13]}; //Obtains the snake position. return snakepos; } else if(length==15) { - Vector2D snakepos = {_xn,_yn}; //Obtains the snake position. + Vector2D snakepos = {_x[14],_y[14]}; //Obtains the snake position. return snakepos; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); @@ -341,64 +340,60 @@ Vector2D Snake::get_pos_before1(int length) //this sends data of following sprites. { - if(length == 1) { - Vector2D snakepos_b1 = {-20,-20}; //Obtains the snake position. - return snakepos_b1; - } - else if(length == 2) { - Vector2D snakepos_b1 = {_x,_y}; //Obtains the snake position. + if(length == 2) { + Vector2D snakepos_b1 = {_x[0],_y[0]}; //Obtains the snake position. return snakepos_b1; } else if(length==3) { - Vector2D snakepos_b1 = {_xa,_ya}; //Obtains the snake position. + Vector2D snakepos_b1 = {_x[1],_y[1]}; //Obtains the snake position. return snakepos_b1; } else if(length==4) { - Vector2D snakepos_b1 = {_xb,_yb}; //Obtains the snake position. + Vector2D snakepos_b1 = {_x[2],_y[2]}; //Obtains the snake position. return snakepos_b1; } else if(length==5) { - Vector2D snakepos_b1 = {_xc,_yc}; //Obtains the snake position. + Vector2D snakepos_b1 = {_x[3],_y[3]}; //Obtains the snake position. return snakepos_b1; } else if(length==6) { - Vector2D snakepos_b1 = {_xd,_yd}; //Obtains the snake position. + Vector2D snakepos_b1 = {_x[4],_y[4]}; //Obtains the snake position. return snakepos_b1; } else if(length==7) { - Vector2D snakepos_b1 = {_xe,_ye}; //Obtains the snake position. + Vector2D snakepos_b1 = {_x[5],_y[5]}; //Obtains the snake position. return snakepos_b1; } else if(length==8) { - Vector2D snakepos_b1 = {_xf,_yf}; //Obtains the snake position. + Vector2D snakepos_b1 = {_x[6],_y[6]}; //Obtains the snake position. return snakepos_b1; } else if(length==9) { - Vector2D snakepos_b1 = {_xg,_yg}; //Obtains the snake position. + Vector2D snakepos_b1 = {_x[7],_y[7]}; //Obtains the snake position. return snakepos_b1; } else if(length==10) { - Vector2D snakepos_b1 = {_xh,_yh}; //Obtains the snake position. + Vector2D snakepos_b1 = {_x[8],_y[8]}; //Obtains the snake position. return snakepos_b1; } else if(length==11) { - Vector2D snakepos_b1 = {_xi,_yi}; //Obtains the snake position. + Vector2D snakepos_b1 = {_x[9],_y[9]}; //Obtains the snake position. return snakepos_b1; } else if(length==12) { - Vector2D snakepos_b1 = {_xj,_yj}; //Obtains the snake position. + Vector2D snakepos_b1 = {_x[10],_y[10]}; //Obtains the snake position. return snakepos_b1; } else if(length==13) { - Vector2D snakepos_b1 = {_xk,_yk}; //Obtains the snake position. + Vector2D snakepos_b1 = {_x[11],_y[11]}; //Obtains the snake position. return snakepos_b1; } else if(length == 14) { - Vector2D snakepos_b1 = {_xl,_yl}; //Obtains the snake position. + Vector2D snakepos_b1 = {_x[12],_y[12]}; //Obtains the snake position. return snakepos_b1; } else if(length==15) { - Vector2D snakepos_b1 = {_xm,_ym}; //Obtains the snake position. + Vector2D snakepos_b1 = {_x[13],_y[13]}; //Obtains the snake position. return snakepos_b1; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); @@ -410,64 +405,56 @@ Vector2D Snake::get_pos_before2(int length) //this sends data of following sprites. { - if(length == 1) { - Vector2D snakepos_b2 = {-20,-20}; //Obtains the snake position. - return snakepos_b2; - } - else if(length == 2) { - Vector2D snakepos_b2 = {-20,-20}; //Obtains the snake position. - return snakepos_b2; - } - else if(length == 3) { - Vector2D snakepos_b2 = {_x,_y}; //Obtains the snake position. + if(length == 3) { + Vector2D snakepos_b2 = {_x[0],_y[0]}; //Obtains the snake position. return snakepos_b2; } else if(length==4) { - Vector2D snakepos_b2 = {_xa,_ya}; //Obtains the snake position. + Vector2D snakepos_b2 = {_x[1],_y[1]}; //Obtains the snake position. return snakepos_b2; } else if(length==5) { - Vector2D snakepos_b2 = {_xb,_yb}; //Obtains the snake position. + Vector2D snakepos_b2 = {_x[2],_y[2]}; //Obtains the snake position. return snakepos_b2; } else if(length==6) { - Vector2D snakepos_b2 = {_xc,_yc}; //Obtains the snake position. + Vector2D snakepos_b2 = {_x[3],_y[3]}; //Obtains the snake position. return snakepos_b2; } else if(length==7) { - Vector2D snakepos_b2 = {_xd,_yd}; //Obtains the snake position. + Vector2D snakepos_b2 = {_x[4],_y[4]}; //Obtains the snake position. return snakepos_b2; } else if(length==8) { - Vector2D snakepos_b2 = {_xe,_ye}; //Obtains the snake position. + Vector2D snakepos_b2 = {_x[5],_y[5]}; //Obtains the snake position. return snakepos_b2; } else if(length==9) { - Vector2D snakepos_b2 = {_xf,_yf}; //Obtains the snake position. + Vector2D snakepos_b2 = {_x[6],_y[6]}; //Obtains the snake position. return snakepos_b2; } else if(length==10) { - Vector2D snakepos_b2 = {_xg,_yg}; //Obtains the snake position. + Vector2D snakepos_b2 = {_x[7],_y[7]}; //Obtains the snake position. return snakepos_b2; } else if(length==11) { - Vector2D snakepos_b2 = {_xh,_yh}; //Obtains the snake position. + Vector2D snakepos_b2 = {_x[8],_y[8]}; //Obtains the snake position. return snakepos_b2; } else if(length==12) { - Vector2D snakepos_b2 = {_xi,_yi}; //Obtains the snake position. + Vector2D snakepos_b2 = {_x[9],_y[9]}; //Obtains the snake position. return snakepos_b2; } else if(length==13) { - Vector2D snakepos_b2 = {_xj,_yj}; //Obtains the snake position. + Vector2D snakepos_b2 = {_x[10],_y[10]}; //Obtains the snake position. return snakepos_b2; } else if(length==14) { - Vector2D snakepos_b2 = {_xk,_yk}; //Obtains the snake position. + Vector2D snakepos_b2 = {_x[11],_y[11]}; //Obtains the snake position. return snakepos_b2; } else if(length == 15) { - Vector2D snakepos_b2 = {_xl,_yl}; //Obtains the snake position. + Vector2D snakepos_b2 = {_x[12],_y[12]}; //Obtains the snake position. return snakepos_b2; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); @@ -479,64 +466,52 @@ Vector2D Snake::get_pos_before3(int length) //this sends data of following sprites. { - if(length == 1) { - Vector2D snakepos_b3 = {-20,-20}; //Obtains the snake position. - return snakepos_b3; - } - else if(length == 2) { - Vector2D snakepos_b3 = {-20,-20}; //Obtains the snake position. - return snakepos_b3; - } - else if(length == 3) { - Vector2D snakepos_b3 = {-20,-20}; //Obtains the snake position. - return snakepos_b3; - } - else if(length == 4) { - Vector2D snakepos_b3 = {_x,_y}; //Obtains the snake position. + if(length == 4) { + Vector2D snakepos_b3 = {_x[0],_y[0]}; //Obtains the snake position. return snakepos_b3; } else if(length==5) { - Vector2D snakepos_b3 = {_xa,_ya}; //Obtains the snake position. + Vector2D snakepos_b3 = {_x[1],_y[1]}; //Obtains the snake position. return snakepos_b3; } else if(length==6) { - Vector2D snakepos_b3 = {_xb,_yb}; //Obtains the snake position. + Vector2D snakepos_b3 = {_x[2],_y[2]}; //Obtains the snake position. return snakepos_b3; } else if(length==7) { - Vector2D snakepos_b3 = {_xc,_yc}; //Obtains the snake position. + Vector2D snakepos_b3 = {_x[3],_y[3]}; //Obtains the snake position. return snakepos_b3; } else if(length==8) { - Vector2D snakepos_b3 = {_xd,_yd}; //Obtains the snake position. + Vector2D snakepos_b3 = {_x[4],_y[4]}; //Obtains the snake position. return snakepos_b3; } else if(length==9) { - Vector2D snakepos_b3 = {_xe,_ye}; //Obtains the snake position. + Vector2D snakepos_b3 = {_x[5],_y[5]}; //Obtains the snake position. return snakepos_b3; } else if(length==10) { - Vector2D snakepos_b3 = {_xf,_yf}; //Obtains the snake position. + Vector2D snakepos_b3 = {_x[6],_y[6]}; //Obtains the snake position. return snakepos_b3; } else if(length==11) { - Vector2D snakepos_b3 = {_xg,_yg}; //Obtains the snake position. + Vector2D snakepos_b3 = {_x[7],_y[7]}; //Obtains the snake position. return snakepos_b3; } else if(length==12) { - Vector2D snakepos_b3 = {_xh,_yh}; //Obtains the snake position. + Vector2D snakepos_b3 = {_x[8],_y[8]}; //Obtains the snake position. return snakepos_b3; } else if(length==13) { - Vector2D snakepos_b3 = {_xi,_yi}; //Obtains the snake position. + Vector2D snakepos_b3 = {_x[9],_y[9]}; //Obtains the snake position. return snakepos_b3; } else if(length==14) { - Vector2D snakepos_b3 = {_xj,_yj}; //Obtains the snake position. + Vector2D snakepos_b3 = {_x[10],_y[10]}; //Obtains the snake position. return snakepos_b3; } else if(length==15) { - Vector2D snakepos_b3 = {_xk,_yk}; //Obtains the snake position. + Vector2D snakepos_b3 = {_x[11],_y[11]}; //Obtains the snake position. return snakepos_b3; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); @@ -548,64 +523,48 @@ Vector2D Snake::get_pos_before4(int length) //this sends data of following sprites. { - if(length == 1) { - Vector2D snakepos_b4 = {-20,-20}; //Obtains the snake position. - return snakepos_b4; - } - else if(length == 2) { - Vector2D snakepos_b4 = {-20,-20}; //Obtains the snake position. - return snakepos_b4; - } - else if(length == 3) { - Vector2D snakepos_b4 = {-20,-20}; //Obtains the snake position. - return snakepos_b4; - } - else if(length == 4) { - Vector2D snakepos_b4 = {-20,-20}; //Obtains the snake position. - return snakepos_b4; - } - else if(length == 5) { - Vector2D snakepos_b4 = {_x,_y}; //Obtains the snake position. + if(length == 5) { + Vector2D snakepos_b4 = {_x[0],_y[0]}; //Obtains the snake position. return snakepos_b4; } else if(length==6) { - Vector2D snakepos_b4 = {_xa,_ya}; //Obtains the snake position. + Vector2D snakepos_b4 = {_x[1],_y[1]}; //Obtains the snake position. return snakepos_b4; } else if(length==7) { - Vector2D snakepos_b4 = {_xb,_yb}; //Obtains the snake position. + Vector2D snakepos_b4 = {_x[2],_y[2]}; //Obtains the snake position. return snakepos_b4; } else if(length==8) { - Vector2D snakepos_b4 = {_xc,_yc}; //Obtains the snake position. + Vector2D snakepos_b4 = {_x[3],_y[3]}; //Obtains the snake position. return snakepos_b4; } else if(length==9) { - Vector2D snakepos_b4 = {_xd,_yd}; //Obtains the snake position. + Vector2D snakepos_b4 = {_x[4],_y[4]}; //Obtains the snake position. return snakepos_b4; } else if(length==10) { - Vector2D snakepos_b4 = {_xe,_ye}; //Obtains the snake position. + Vector2D snakepos_b4 = {_x[5],_y[5]}; //Obtains the snake position. return snakepos_b4; } else if(length==11) { - Vector2D snakepos_b4 = {_xf,_yf}; //Obtains the snake position. + Vector2D snakepos_b4 = {_x[6],_y[6]}; //Obtains the snake position. return snakepos_b4; } else if(length==12) { - Vector2D snakepos_b4 = {_xg,_yg}; //Obtains the snake position. + Vector2D snakepos_b4 = {_x[7],_y[7]}; //Obtains the snake position. return snakepos_b4; } else if(length==13) { - Vector2D snakepos_b4 = {_xh,_yh}; //Obtains the snake position. + Vector2D snakepos_b4 = {_x[8],_y[8]}; //Obtains the snake position. return snakepos_b4; } else if(length==14) { - Vector2D snakepos_b4 = {_xi,_yi}; //Obtains the snake position. + Vector2D snakepos_b4 = {_x[9],_y[9]}; //Obtains the snake position. return snakepos_b4; } else if(length==15) { - Vector2D snakepos_b4 = {_xj,_yj}; //Obtains the snake position. + Vector2D snakepos_b4 = {_x[10],_y[10]}; //Obtains the snake position. return snakepos_b4; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); @@ -617,64 +576,44 @@ Vector2D Snake::get_pos_before5(int length) //this sends data of following sprites. { - if(length == 1) { - Vector2D snakepos_b5 = {-20,-20}; //Obtains the snake position. - return snakepos_b5; - } - else if(length == 2) { - Vector2D snakepos_b5 = {-20,-20}; //Obtains the snake position. - return snakepos_b5; - } - else if(length == 3) { - Vector2D snakepos_b5 = {-20,-20}; //Obtains the snake position. - return snakepos_b5; - } - else if(length == 4) { - Vector2D snakepos_b5 = {-20,-20}; //Obtains the snake position. - return snakepos_b5; - } - else if(length == 5) { - Vector2D snakepos_b5 = {-20,-20}; //Obtains the snake position. - return snakepos_b5; - } - else if(length == 6) { - Vector2D snakepos_b5 = {_x,_y}; //Obtains the snake position. + if(length == 6) { + Vector2D snakepos_b5 = {_x[0],_y[0]}; //Obtains the snake position. return snakepos_b5; } else if(length==7) { - Vector2D snakepos_b5 = {_xa,_ya}; //Obtains the snake position. + Vector2D snakepos_b5 = {_x[1],_y[1]}; //Obtains the snake position. return snakepos_b5; } else if(length==8) { - Vector2D snakepos_b5 = {_xb,_yb}; //Obtains the snake position. + Vector2D snakepos_b5 = {_x[2],_y[2]}; //Obtains the snake position. return snakepos_b5; } else if(length==9) { - Vector2D snakepos_b5 = {_xc,_yc}; //Obtains the snake position. + Vector2D snakepos_b5 = {_x[3],_y[3]}; //Obtains the snake position. return snakepos_b5; } else if(length==10) { - Vector2D snakepos_b5 = {_xd,_yd}; //Obtains the snake position. + Vector2D snakepos_b5 = {_x[4],_y[4]}; //Obtains the snake position. return snakepos_b5; } else if(length==11) { - Vector2D snakepos_b5 = {_xe,_ye}; //Obtains the snake position. + Vector2D snakepos_b5 = {_x[5],_y[5]}; //Obtains the snake position. return snakepos_b5; } else if(length==12) { - Vector2D snakepos_b5 = {_xf,_yf}; //Obtains the snake position. + Vector2D snakepos_b5 = {_x[6],_y[6]}; //Obtains the snake position. return snakepos_b5; } else if(length==13) { - Vector2D snakepos_b5 = {_xg,_yg}; //Obtains the snake position. + Vector2D snakepos_b5 = {_x[7],_y[7]}; //Obtains the snake position. return snakepos_b5; } else if(length==14) { - Vector2D snakepos_b5 = {_xh,_yh}; //Obtains the snake position. + Vector2D snakepos_b5 = {_x[8],_y[8]}; //Obtains the snake position. return snakepos_b5; } else if(length==15) { - Vector2D snakepos_b5 = {_xi,_yi}; //Obtains the snake position. + Vector2D snakepos_b5 = {_x[9],_y[9]}; //Obtains the snake position. return snakepos_b5; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); @@ -686,64 +625,40 @@ Vector2D Snake::get_pos_before6(int length) //this sends data of following sprites. { - if(length == 1) { - Vector2D snakepos_b6 = {-20,-20}; //Obtains the snake position. - return snakepos_b6; - } - else if(length == 2) { - Vector2D snakepos_b6 = {-20,-20}; //Obtains the snake position. - return snakepos_b6; - } - else if(length == 3) { - Vector2D snakepos_b6 = {-20,-20}; //Obtains the snake position. - return snakepos_b6; - } - else if(length == 4) { - Vector2D snakepos_b6 = {-20,-20}; //Obtains the snake position. - return snakepos_b6; - } - else if(length == 5) { - Vector2D snakepos_b6 = {-20,-20}; //Obtains the snake position. - return snakepos_b6; - } - else if(length == 6) { - Vector2D snakepos_b6 = {-20,-20}; //Obtains the snake position. - return snakepos_b6; - } - else if(length == 7) { - Vector2D snakepos_b6 = {_x,_y}; //Obtains the snake position. + if(length == 7) { + Vector2D snakepos_b6 = {_x[0],_y[0]}; //Obtains the snake position. return snakepos_b6; } else if(length==8) { - Vector2D snakepos_b6 = {_xa,_ya}; //Obtains the snake position. + Vector2D snakepos_b6 = {_x[1],_y[1]}; //Obtains the snake position. return snakepos_b6; } else if(length==9) { - Vector2D snakepos_b6 = {_xb,_yb}; //Obtains the snake position. + Vector2D snakepos_b6 = {_x[2],_y[2]}; //Obtains the snake position. return snakepos_b6; } else if(length==10) { - Vector2D snakepos_b6 = {_xc,_yc}; //Obtains the snake position. + Vector2D snakepos_b6 = {_x[3],_y[3]}; //Obtains the snake position. return snakepos_b6; } else if(length==11) { - Vector2D snakepos_b6 = {_xd,_yd}; //Obtains the snake position. + Vector2D snakepos_b6 = {_x[4],_y[4]}; //Obtains the snake position. return snakepos_b6; } else if(length==12) { - Vector2D snakepos_b6 = {_xe,_ye}; //Obtains the snake position. + Vector2D snakepos_b6 = {_x[5],_y[5]}; //Obtains the snake position. return snakepos_b6; } else if(length==13) { - Vector2D snakepos_b6 = {_xf,_yf}; //Obtains the snake position. + Vector2D snakepos_b6 = {_x[6],_y[6]}; //Obtains the snake position. return snakepos_b6; } else if(length==14) { - Vector2D snakepos_b6 = {_xg,_yg}; //Obtains the snake position. + Vector2D snakepos_b6 = {_x[7],_y[7]}; //Obtains the snake position. return snakepos_b6; } else if(length==15) { - Vector2D snakepos_b6 = {_xh,_yh}; //Obtains the snake position. + Vector2D snakepos_b6 = {_x[8],_y[8]}; //Obtains the snake position. return snakepos_b6; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); @@ -755,64 +670,36 @@ Vector2D Snake::get_pos_before7(int length) //this sends data of following sprites. { - if(length == 1) { - Vector2D snakepos_b7 = {-20,-20}; //Obtains the snake position. - return snakepos_b7; - } - else if(length == 2) { - Vector2D snakepos_b7 = {-20,-20}; //Obtains the snake position. - return snakepos_b7; - } - else if(length == 3) { - Vector2D snakepos_b7 = {-20,-20}; //Obtains the snake position. - return snakepos_b7; - } - else if(length == 4) { - Vector2D snakepos_b7 = {-20,-20}; //Obtains the snake position. - return snakepos_b7; - } - else if(length == 5) { - Vector2D snakepos_b7 = {-20,-20}; //Obtains the snake position. - return snakepos_b7; - } - else if(length == 6) { - Vector2D snakepos_b7 = {-20,-20}; //Obtains the snake position. - return snakepos_b7; - } - else if(length == 7) { - Vector2D snakepos_b7 = {-20,-20}; //Obtains the snake position. - return snakepos_b7; - } - else if(length == 8) { - Vector2D snakepos_b7 = {_x,_y}; //Obtains the snake position. + if(length == 8) { + Vector2D snakepos_b7 = {_x[0],_y[0]}; //Obtains the snake position. return snakepos_b7; } else if(length==9) { - Vector2D snakepos_b7 = {_xa,_ya}; //Obtains the snake position. + Vector2D snakepos_b7 = {_x[1],_y[1]}; //Obtains the snake position. return snakepos_b7; } else if(length==10) { - Vector2D snakepos_b7 = {_xb,_yb}; //Obtains the snake position. + Vector2D snakepos_b7 = {_x[2],_y[2]}; //Obtains the snake position. return snakepos_b7; } else if(length==11) { - Vector2D snakepos_b7 = {_xc,_yc}; //Obtains the snake position. + Vector2D snakepos_b7 = {_x[3],_y[3]}; //Obtains the snake position. return snakepos_b7; } else if(length==12) { - Vector2D snakepos_b7 = {_xd,_yd}; //Obtains the snake position. + Vector2D snakepos_b7 = {_x[4],_y[4]}; //Obtains the snake position. return snakepos_b7; } else if(length==13) { - Vector2D snakepos_b7 = {_xe,_ye}; //Obtains the snake position. + Vector2D snakepos_b7 = {_x[5],_y[5]}; //Obtains the snake position. return snakepos_b7; } else if(length==14) { - Vector2D snakepos_b7 = {_xf,_yf}; //Obtains the snake position. + Vector2D snakepos_b7 = {_x[6],_y[6]}; //Obtains the snake position. return snakepos_b7; } else if(length==15) { - Vector2D snakepos_b7 = {_xg,_yg}; //Obtains the snake position. + Vector2D snakepos_b7 = {_x[7],_y[7]}; //Obtains the snake position. return snakepos_b7; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); @@ -824,64 +711,32 @@ Vector2D Snake::get_pos_before8(int length) //this sends data of following sprites. { - if(length == 1) { - Vector2D snakepos_b8 = {-20,-20}; //Obtains the snake position. - return snakepos_b8; - } - else if(length == 2) { - Vector2D snakepos_b8 = {-20,-20}; //Obtains the snake position. - return snakepos_b8; - } - else if(length == 3) { - Vector2D snakepos_b8 = {-20,-20}; //Obtains the snake position. - return snakepos_b8; - } - else if(length == 4) { - Vector2D snakepos_b8 = {-20,-20}; //Obtains the snake position. - return snakepos_b8; - } - else if(length == 5) { - Vector2D snakepos_b8 = {-20,-20}; //Obtains the snake position. - return snakepos_b8; - } - else if(length == 6) { - Vector2D snakepos_b8 = {-20,-20}; //Obtains the snake position. - return snakepos_b8; - } - else if(length == 7) { - Vector2D snakepos_b8 = {-20,-20}; //Obtains the snake position. - return snakepos_b8; - } - else if(length == 8) { - Vector2D snakepos_b8 = {-20,-20}; //Obtains the snake position. - return snakepos_b8; - } - else if(length == 9) { - Vector2D snakepos_b8 = {_x,_y}; //Obtains the snake position. + if(length == 9) { + Vector2D snakepos_b8 = {_x[0],_y[0]}; //Obtains the snake position. return snakepos_b8; } else if(length==10) { - Vector2D snakepos_b8 = {_xa,_ya}; //Obtains the snake position. + Vector2D snakepos_b8 = {_x[1],_y[1]}; //Obtains the snake position. return snakepos_b8; } else if(length==11) { - Vector2D snakepos_b8 = {_xb,_yb}; //Obtains the snake position. + Vector2D snakepos_b8 = {_x[2],_y[2]}; //Obtains the snake position. return snakepos_b8; } else if(length==12) { - Vector2D snakepos_b8 = {_xc,_yc}; //Obtains the snake position. + Vector2D snakepos_b8 = {_x[3],_y[3]}; //Obtains the snake position. return snakepos_b8; } else if(length==13) { - Vector2D snakepos_b8 = {_xd,_yd}; //Obtains the snake position. + Vector2D snakepos_b8 = {_x[4],_y[4]}; //Obtains the snake position. return snakepos_b8; } else if(length==14) { - Vector2D snakepos_b8 = {_xe,_ye}; //Obtains the snake position. + Vector2D snakepos_b8 = {_x[5],_y[5]}; //Obtains the snake position. return snakepos_b8; } else if(length==15) { - Vector2D snakepos_b8 = {_xf,_yf}; //Obtains the snake position. + Vector2D snakepos_b8 = {_x[6],_y[6]}; //Obtains the snake position. return snakepos_b8; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); @@ -893,64 +748,28 @@ Vector2D Snake::get_pos_before9(int length) //this sends data of following sprites. { - if(length == 1) { - Vector2D snakepos_b9 = {-20,-20}; //Obtains the snake position. - return snakepos_b9; - } - else if(length == 2) { - Vector2D snakepos_b9 = {-20,-20}; //Obtains the snake position. - return snakepos_b9; - } - else if(length == 3) { - Vector2D snakepos_b9 = {-20,-20}; //Obtains the snake position. - return snakepos_b9; - } - else if(length == 4) { - Vector2D snakepos_b9 = {-20,-20}; //Obtains the snake position. - return snakepos_b9; - } - else if(length == 5) { - Vector2D snakepos_b9 = {-20,-20}; //Obtains the snake position. - return snakepos_b9; - } - else if(length == 6) { - Vector2D snakepos_b9 = {-20,-20}; //Obtains the snake position. - return snakepos_b9; - } - else if(length == 7) { - Vector2D snakepos_b9 = {-20,-20}; //Obtains the snake position. - return snakepos_b9; - } - else if(length == 8) { - Vector2D snakepos_b9 = {-20,-20}; //Obtains the snake position. - return snakepos_b9; - } - else if(length == 9) { - Vector2D snakepos_b9 = {-20,-20}; //Obtains the snake position. - return snakepos_b9; - } - else if(length == 10) { - Vector2D snakepos_b9 = {_x,_y}; //Obtains the snake position. + if(length == 10) { + Vector2D snakepos_b9 = {_x[0],_y[0]}; //Obtains the snake position. return snakepos_b9; } else if(length==11) { - Vector2D snakepos_b9 = {_xa,_ya}; //Obtains the snake position. + Vector2D snakepos_b9 = {_x[1],_y[1]}; //Obtains the snake position. return snakepos_b9; } else if(length==12) { - Vector2D snakepos_b9 = {_xb,_yb}; //Obtains the snake position. + Vector2D snakepos_b9 = {_x[2],_y[2]}; //Obtains the snake position. return snakepos_b9; } else if(length==13) { - Vector2D snakepos_b9 = {_xc,_yc}; //Obtains the snake position. + Vector2D snakepos_b9 = {_x[3],_y[3]}; //Obtains the snake position. return snakepos_b9; } else if(length==14) { - Vector2D snakepos_b9 = {_xd,_yd}; //Obtains the snake position. + Vector2D snakepos_b9 = {_x[4],_y[4]}; //Obtains the snake position. return snakepos_b9; } else if(length==15) { - Vector2D snakepos_b9 = {_xe,_ye}; //Obtains the snake position. + Vector2D snakepos_b9 = {_x[5],_y[5]}; //Obtains the snake position. return snakepos_b9; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); @@ -962,64 +781,24 @@ Vector2D Snake::get_pos_before10(int length) //this sends data of following sprites. { - if(length == 1) { - Vector2D snakepos_b10 = {-20,-20}; //Obtains the snake position. - return snakepos_b10; - } - else if(length == 2) { - Vector2D snakepos_b10 = {-20,-20}; //Obtains the snake position. - return snakepos_b10; - } - else if(length == 3) { - Vector2D snakepos_b10 = {-20,-20}; //Obtains the snake position. - return snakepos_b10; - } - else if(length == 4) { - Vector2D snakepos_b10 = {-20,-20}; //Obtains the snake position. - return snakepos_b10; - } - else if(length == 5) { - Vector2D snakepos_b10 = {-20,-20}; //Obtains the snake position. - return snakepos_b10; - } - else if(length == 6) { - Vector2D snakepos_b10 = {-20,-20}; //Obtains the snake position. - return snakepos_b10; - } - else if(length == 7) { - Vector2D snakepos_b10 = {-20,-20}; //Obtains the snake position. - return snakepos_b10; - } - else if(length == 8) { - Vector2D snakepos_b10 = {-20,-20}; //Obtains the snake position. - return snakepos_b10; - } - else if(length == 9) { - Vector2D snakepos_b10 = {-20,-20}; //Obtains the snake position. - return snakepos_b10; - } - else if(length == 10) { - Vector2D snakepos_b10 = {-20,-20}; //Obtains the snake position. - return snakepos_b10; - } - else if(length == 11) { - Vector2D snakepos_b10 = {_x,_y}; //Obtains the snake position. + if(length == 11) { + Vector2D snakepos_b10 = {_x[0],_y[0]}; //Obtains the snake position. return snakepos_b10; } else if(length==12) { - Vector2D snakepos_b10 = {_xa,_ya}; //Obtains the snake position. + Vector2D snakepos_b10 = {_x[1],_y[1]}; //Obtains the snake position. return snakepos_b10; } else if(length==13) { - Vector2D snakepos_b10 = {_xb,_yb}; //Obtains the snake position. + Vector2D snakepos_b10 = {_x[2],_y[2]}; //Obtains the snake position. return snakepos_b10; } else if(length==14) { - Vector2D snakepos_b10 = {_xc,_yc}; //Obtains the snake position. + Vector2D snakepos_b10 = {_x[3],_y[3]}; //Obtains the snake position. return snakepos_b10; } else if(length==15) { - Vector2D snakepos_b10 = {_xd,_yd}; //Obtains the snake position. + Vector2D snakepos_b10 = {_x[4],_y[4]}; //Obtains the snake position. return snakepos_b10; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); @@ -1031,64 +810,20 @@ Vector2D Snake::get_pos_before11(int length) //this sends data of following sprites. { - if(length == 1) { - Vector2D snakepos_b11 = {-20,-20}; //Obtains the snake position. - return snakepos_b11; - } - else if(length == 2) { - Vector2D snakepos_b11 = {-20,-20}; //Obtains the snake position. - return snakepos_b11; - } - else if(length == 3) { - Vector2D snakepos_b11 = {-20,-20}; //Obtains the snake position. - return snakepos_b11; - } - else if(length == 4) { - Vector2D snakepos_b11 = {-20,-20}; //Obtains the snake position. - return snakepos_b11; - } - else if(length == 5) { - Vector2D snakepos_b11 = {-20,-20}; //Obtains the snake position. - return snakepos_b11; - } - else if(length == 6) { - Vector2D snakepos_b11 = {-20,-20}; //Obtains the snake position. - return snakepos_b11; - } - else if(length == 7) { - Vector2D snakepos_b11 = {-20,-20}; //Obtains the snake position. - return snakepos_b11; - } - else if(length == 8) { - Vector2D snakepos_b11 = {-20,-20}; //Obtains the snake position. - return snakepos_b11; - } - else if(length == 9) { - Vector2D snakepos_b11 = {-20,-20}; //Obtains the snake position. - return snakepos_b11; - } - else if(length == 10) { - Vector2D snakepos_b11 = {-20,-20}; //Obtains the snake position. - return snakepos_b11; - } - else if(length == 11) { - Vector2D snakepos_b11 = {-20,-20}; //Obtains the snake position. - return snakepos_b11; - } - else if(length == 12) { - Vector2D snakepos_b11 = {_x,_y}; //Obtains the snake position. + if(length == 12) { + Vector2D snakepos_b11 = {_x[0],_y[0]}; //Obtains the snake position. return snakepos_b11; } else if(length==13) { - Vector2D snakepos_b11 = {_xa,_ya}; //Obtains the snake position. + Vector2D snakepos_b11 = {_x[1],_y[1]}; //Obtains the snake position. return snakepos_b11; } else if(length==14) { - Vector2D snakepos_b11 = {_xb,_yb}; //Obtains the snake position. + Vector2D snakepos_b11 = {_x[2],_y[2]}; //Obtains the snake position. return snakepos_b11; } else if(length==15) { - Vector2D snakepos_b11 = {_xc,_yc}; //Obtains the snake position. + Vector2D snakepos_b11 = {_x[3],_y[3]}; //Obtains the snake position. return snakepos_b11; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); @@ -1100,64 +835,16 @@ Vector2D Snake::get_pos_before12(int length) //this sends data of following sprites. { - if(length == 1) { - Vector2D snakepos_b12 = {-20,-20}; //Obtains the snake position. - return snakepos_b12; - } - else if(length == 2) { - Vector2D snakepos_b12 = {-20,-20}; //Obtains the snake position. - return snakepos_b12; - } - else if(length == 3) { - Vector2D snakepos_b12 = {-20,-20}; //Obtains the snake position. - return snakepos_b12; - } - else if(length == 4) { - Vector2D snakepos_b12 = {-20,-20}; //Obtains the snake position. - return snakepos_b12; - } - else if(length == 5) { - Vector2D snakepos_b12 = {-20,-20}; //Obtains the snake position. - return snakepos_b12; - } - else if(length == 6) { - Vector2D snakepos_b12 = {-20,-20}; //Obtains the snake position. - return snakepos_b12; - } - else if(length == 7) { - Vector2D snakepos_b12 = {-20,-20}; //Obtains the snake position. - return snakepos_b12; - } - else if(length == 8) { - Vector2D snakepos_b12 = {-20,-20}; //Obtains the snake position. - return snakepos_b12; - } - else if(length == 9) { - Vector2D snakepos_b12 = {-20,-20}; //Obtains the snake position. - return snakepos_b12; - } - else if(length == 10) { - Vector2D snakepos_b12 = {-20,-20}; //Obtains the snake position. - return snakepos_b12; - } - else if(length == 11) { - Vector2D snakepos_b12 = {-20,-20}; //Obtains the snake position. - return snakepos_b12; - } - else if(length == 12) { - Vector2D snakepos_b12 = {-20,-20}; //Obtains the snake position. - return snakepos_b12; - } - else if(length == 13) { - Vector2D snakepos_b12 = {_x,_y}; //Obtains the snake position. + if(length == 13) { + Vector2D snakepos_b12 = {_x[0],_y[0]}; //Obtains the snake position. return snakepos_b12; } else if(length==14) { - Vector2D snakepos_b12 = {_xa,_ya}; //Obtains the snake position. + Vector2D snakepos_b12 = {_x[1],_y[1]}; //Obtains the snake position. return snakepos_b12; } else if(length==15) { - Vector2D snakepos_b12 = {_xb,_yb}; //Obtains the snake position. + Vector2D snakepos_b12 = {_x[2],_y[2]}; //Obtains the snake position. return snakepos_b12; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); @@ -1169,64 +856,12 @@ Vector2D Snake::get_pos_before13(int length) //this sends data of following sprites. { - if(length == 1) { - Vector2D snakepos_b13 = {-20,-20}; //Obtains the snake position. - return snakepos_b13; - } - else if(length == 2) { - Vector2D snakepos_b13 = {-20,-20}; //Obtains the snake position. - return snakepos_b13; - } - else if(length == 3) { - Vector2D snakepos_b13 = {-20,-20}; //Obtains the snake position. - return snakepos_b13; - } - else if(length == 4) { - Vector2D snakepos_b13 = {-20,-20}; //Obtains the snake position. - return snakepos_b13; - } - else if(length == 5) { - Vector2D snakepos_b13 = {-20,-20}; //Obtains the snake position. - return snakepos_b13; - } - else if(length == 6) { - Vector2D snakepos_b13 = {-20,-20}; //Obtains the snake position. - return snakepos_b13; - } - else if(length == 7) { - Vector2D snakepos_b13 = {-20,-20}; //Obtains the snake position. - return snakepos_b13; - } - else if(length == 8) { - Vector2D snakepos_b13 = {-20,-20}; //Obtains the snake position. - return snakepos_b13; - } - else if(length == 9) { - Vector2D snakepos_b13 = {-20,-20}; //Obtains the snake position. - return snakepos_b13; - } - else if(length == 10) { - Vector2D snakepos_b13 = {-20,-20}; //Obtains the snake position. - return snakepos_b13; - } - else if(length == 11) { - Vector2D snakepos_b13 = {-20,-20}; //Obtains the snake position. - return snakepos_b13; - } - else if(length == 12) { - Vector2D snakepos_b13 = {-20,-20}; //Obtains the snake position. - return snakepos_b13; - } - else if(length == 13) { - Vector2D snakepos_b13 = {-20,-20}; //Obtains the snake position. - return snakepos_b13; - } - else if(length == 14) { - Vector2D snakepos_b13 = {_x,_y}; //Obtains the snake position. + if(length == 14) { + Vector2D snakepos_b13 = {_x[0],_y[0]}; //Obtains the snake position. return snakepos_b13; } else if(length==15) { - Vector2D snakepos_b13 = {_xa,_ya}; //Obtains the snake position. + Vector2D snakepos_b13 = {_x[1],_y[1]}; //Obtains the snake position. return snakepos_b13; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); @@ -1238,71 +873,15 @@ Vector2D Snake::get_pos_before14(int length) //this sends data of following sprites. { - if(length == 1) { - Vector2D snakepos_b14 = {-20,-20}; //Obtains the snake position. - return snakepos_b14; - } - else if(length == 2) { - Vector2D snakepos_b14 = {-20,-20}; //Obtains the snake position. - return snakepos_b14; - } - else if(length == 3) { - Vector2D snakepos_b14 = {-20,-20}; //Obtains the snake position. - return snakepos_b14; - } - else if(length == 4) { - Vector2D snakepos_b14 = {-20,-20}; //Obtains the snake position. - return snakepos_b14; - } - else if(length == 5) { - Vector2D snakepos_b14 = {-20,-20}; //Obtains the snake position. - return snakepos_b14; - } - else if(length == 6) { - Vector2D snakepos_b14 = {-20,-20}; //Obtains the snake position. - return snakepos_b14; - } - else if(length == 7) { - Vector2D snakepos_b14 = {-20,-20}; //Obtains the snake position. + if(length==15) { + Vector2D snakepos_b14 = {_x[0],_y[0]}; //Obtains the snake position. return snakepos_b14; } - else if(length == 8) { - Vector2D snakepos_b14 = {-20,-20}; //Obtains the snake position. - return snakepos_b14; - } - else if(length == 9) { - Vector2D snakepos_b14 = {-20,-20}; //Obtains the snake position. - return snakepos_b14; - } - else if(length == 10) { - Vector2D snakepos_b14 = {-20,-20}; //Obtains the snake position. - return snakepos_b14; - } - else if(length == 11) { - Vector2D snakepos_b14 = {-20,-20}; //Obtains the snake position. - return snakepos_b14; - } - else if(length == 12) { - Vector2D snakepos_b14 = {-20,-20}; //Obtains the snake position. - return snakepos_b14; - } - else if(length == 13) { - Vector2D snakepos_b14 = {-20,-20}; //Obtains the snake position. - return snakepos_b14; - } - else if(length == 14) { - Vector2D snakepos_b14 = {-20,-20}; //Obtains the snake position. - return snakepos_b14; - } - else if(length==15) { - Vector2D snakepos_b14 = {_x,_y}; //Obtains the snake position. - return snakepos_b14; - } - //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); else { Vector2D snakepos_b14 = {-20,-20}; //Obtains the snake position. return snakepos_b14; } + //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); } @@ -1310,394 +889,394 @@ void Snake::update(Direction d,float mag,int length, int speed, int* b0_to_b14) { _speed = speed; //Speed changes depending on how much you push the joystick.(As Of Now) - b0 = b0_to_b14[0]; - b1 = b0_to_b14[1]; - b2 = b0_to_b14[2]; - b3 = b0_to_b14[3]; - b4 = b0_to_b14[4]; - b5 = b0_to_b14[5]; - b6 = b0_to_b14[6]; - b7 = b0_to_b14[7]; - b8 = b0_to_b14[8]; - b9 = b0_to_b14[9]; - b10 = b0_to_b14[10]; - b11 = b0_to_b14[11]; - b12 = b0_to_b14[12]; - b13 = b0_to_b14[13]; - b14 = b0_to_b14[14]; + b[0] = b0_to_b14[0]; + b[1] = b0_to_b14[1]; + b[2] = b0_to_b14[2]; + b[3] = b0_to_b14[3]; + b[4] = b0_to_b14[4]; + b[5] = b0_to_b14[5]; + b[6] = b0_to_b14[6]; + b[7] = b0_to_b14[7]; + b[8] = b0_to_b14[8]; + b[9] = b0_to_b14[9]; + b[10] = b0_to_b14[10]; + b[11] = b0_to_b14[11]; + b[12] = b0_to_b14[12]; + b[13] = b0_to_b14[13]; + b[14] = b0_to_b14[14]; if(length > 1) { - if ((_x > _xa)&&(b1 == 1)&&(b0 == 1)) { - _x-=_speed; + if ((_x[0] > _x[1])&&(b[1] == 1)&&(b[0] == 1)) { + _x[0]-=_speed; } - if ((_x < _xa)&&(b1 == 1)&&(b0 == 1)) { - _x+=_speed; + if ((_x[0] < _x[1])&&(b[1] == 1)&&(b[0] == 1)) { + _x[0]+=_speed; + } + } + if(length > 2) { + if ((_x[1] > _x[2])&&(b[2] == 1)&&(b[1] == 1)) { + _x[1]-=_speed; } - if(length > 2) { - if ((_xa > _xb)&&(b2 == 1)&&(b1 == 1)) { - _xa-=_speed; + if ((_x[1] < _x[2])&&(b[2] == 1)&&(b[1] == 1)) { + _x[1]+=_speed; + } + } + if(length > 3) { + if ((_x[2] > _x[3])&&(b[3] == 1)&&(b[2] == 1)) { + _x[2]-=_speed; } - if ((_xa < _xb)&&(b2 == 1)&&(b1 == 1)) { - _xa+=_speed; + if ((_x[2] < _x[3])&&(b[3] == 1)&&(b[2] == 1)) { + _x[2]+=_speed; } - if(length > 3) { - if ((_xb > _xc)&&(b3 == 1)&&(b2 == 1)) { - _xb-=_speed; - } - if ((_xb < _xc)&&(b3 == 1)&&(b2 == 1)) { - _xb+=_speed; - } - if(length > 4) { - if ((_xc > _xd)&&(b4 == 1)&&(b3 == 1)) { - _xc-=_speed; - } - if ((_xc < _xd)&&(b4 == 1)&&(b3 == 1)) { - _xc+=_speed; - } - if(length > 5) { - if ((_xd > _xe)&&(b5 == 1)&&(b4 == 1)) { - _xd-=_speed; - } - if ((_xd < _xe)&&(b5 == 1)&&(b4 == 1)) { - _xd+=_speed; - } - if(length > 6) { - if ((_xe > _xf)&&(b6 == 1)&&(b5 == 1)) { - _xe-=_speed; - } - if ((_xe < _xf)&&(b6 == 1)&&(b5 == 1)) { - _xe+=_speed; - } - if(length > 7) { - if ((_xf > _xg)&&(b7 == 1)&&(b6 == 1)) { - _xf-=_speed; - } - if ((_xf < _xg)&&(b7 == 1)&&(b6 == 1)) { - _xf+=_speed; - } - if(length > 8) { - if ((_xg > _xh)&&(b8 == 1)&&(b7 == 1)) { - _xg-=_speed; - } - if ((_xg < _xh)&&(b8 == 1)&&(b7 == 1)) { - _xg+=_speed; - } - if(length > 9) { - if ((_xh > _xi)&&(b9 == 1)&&(b8 == 1)) { - _xh-=_speed; - } - if ((_xh < _xi)&&(b9 == 1)&&(b8 == 1)) { - _xh+=_speed; - } - if(length > 10) { - if ((_xi > _xj)&&(b10 == 1)&&(b9 == 1)) { - _xi-=_speed; - } - if ((_xi < _xj)&&(b10 == 1)&&(b9 == 1)) { - _xi+=_speed; - } - if(length > 11) { - if ((_xj > _xk)&&(b11 == 1)&&(b10 == 1)) { - _xj-=_speed; - } - if ((_xj < _xk)&&(b11 == 1)&&(b10 == 1)) { - _xj+=_speed; - } - if(length > 12) { - if ((_xk > _xl)&&(b12 == 1)&&(b11 == 1)) { - _xk-=_speed; - } - if ((_xk < _xl)&&(b12 == 1)&&(b11 == 1)) { - _xk+=_speed; - } - if(length > 13) { - if ((_xl > _xm)&&(b13 == 1)&&(b12 == 1)) { - _xl-=_speed; - } - if ((_xl < _xm)&&(b13 == 1)&&(b12 == 1)) { - _xl+=_speed; - } - if(length > 14) { - if ((_xm > _xn)&&(b14 == 1)&&(b13 == 1)) { - _xm-=_speed; - } - if ((_xm < _xn)&&(b14 == 1)&&(b13 == 1)) { - _xm+=_speed; - - } - } - } - } - } - } - } - } - } - } - } - } - } + } + if(length > 4) { + if ((_x[3] > _x[4])&&(b[4] == 1)&&(b[3] == 1)) { + _x[3]-=_speed; + } + if ((_x[3] < _x[4])&&(b[4] == 1)&&(b[3] == 1)) { + _x[3]+=_speed; + } + } + if(length > 5) { + if ((_x[4] > _x[5])&&(b[5] == 1)&&(b[4] == 1)) { + _x[4]-=_speed; + } + if ((_x[4] < _x[5])&&(b[5] == 1)&&(b[4] == 1)) { + _x[4]+=_speed; + } + } + if(length > 6) { + if ((_x[5] > _x[6])&&(b[6] == 1)&&(b[5] == 1)) { + _x[5]-=_speed; + } + if ((_x[5] < _x[6])&&(b[6] == 1)&&(b[5] == 1)) { + _x[5]+=_speed; + } + } + if(length > 7) { + if ((_x[6] > _x[7])&&(b[7] == 1)&&(b[6] == 1)) { + _x[6]-=_speed; + } + if ((_x[6] < _x[7])&&(b[7] == 1)&&(b[6] == 1)) { + _x[6]+=_speed; + } + } + if(length > 8) { + if ((_x[7] > _x[8])&&(b[8] == 1)&&(b[7] == 1)) { + _x[7]-=_speed; + } + if ((_x[7] < _x[8])&&(b[8] == 1)&&(b[7] == 1)) { + _x[7]+=_speed; + } + } + if(length > 9) { + if ((_x[8] > _x[9])&&(b[9] == 1)&&(b[8] == 1)) { + _x[8]-=_speed; + } + if ((_x[8] < _x[9])&&(b[9] == 1)&&(b[8] == 1)) { + _x[8]+=_speed; + } + } + if(length > 10) { + if ((_x[9] > _x[10])&&(b[10] == 1)&&(b[9] == 1)) { + _x[9]-=_speed; + } + if ((_x[9] < _x[10])&&(b[10] == 1)&&(b[9] == 1)) { + _x[9]+=_speed; + } + } + if(length > 11) { + if ((_x[10] > _x[11])&&(b[11] == 1)&&(b[10] == 1)) { + _x[10]-=_speed; + } + if ((_x[10] < _x[11])&&(b[11] == 1)&&(b[10] == 1)) { + _x[10]+=_speed; + } + } + if(length > 12) { + if ((_x[11] > _x[12])&&(b[12] == 1)&&(b[11] == 1)) { + _x[11]-=_speed; + } + if ((_x[11] < _x[12])&&(b[12] == 1)&&(b[11] == 1)) { + _x[11]+=_speed; + } + } + if(length > 13) { + if ((_x[12] > _x[13])&&(b[13] == 1)&&(b[12] == 1)) { + _x[12]-=_speed; + } + if ((_x[12] < _x[13])&&(b[13] == 1)&&(b[12] == 1)) { + _x[12]+=_speed; + } + } + if(length > 14) { + if ((_x[13] > _x[14])&&(b[14] == 1)&&(b[13] == 1)) { + _x[13]-=_speed; + } + if ((_x[13] < _x[14])&&(b[14] == 1)&&(b[13] == 1)) { + _x[13]+=_speed; } } - if((length == 15)&&(b14 == 1)) { + + if((length == 15)&&(b[14] == 1)) { if (d == E) { - _xn+= _speed; + _x[14]+= _speed; } if (d == W) { - _xn-= _speed; + _x[14]-= _speed; } } - if((length == 14)&&(b13 == 1)) { + if((length == 14)&&(b[13] == 1)) { if (d == E) { - _xm+= _speed; + _x[13]+= _speed; } if (d == W) { - _xm-= _speed; + _x[13]-= _speed; } } - if((length == 13)&&(b12 == 1)) { + if((length == 13)&&(b[12] == 1)) { if (d == E) { - _xl+= _speed; + _x[12]+= _speed; } if (d == W) { - _xl-= _speed; + _x[12]-= _speed; } } - if((length == 12)&&(b11 == 1)) { + if((length == 12)&&(b[11] == 1)) { if (d == E) { - _xk+= _speed; + _x[11]+= _speed; } if (d == W) { - _xk-= _speed; + _x[11]-= _speed; } } - if((length == 11)&&(b10 == 1)) { + if((length == 11)&&(b[10] == 1)) { if (d == E) { - _xj+= _speed; + _x[10]+= _speed; } if (d == W) { - _xj-= _speed; + _x[10]-= _speed; } } - if((length == 10)&&(b9 == 1)) { + if((length == 10)&&(b[9] == 1)) { if (d == E) { - _xi+= _speed; + _x[9]+= _speed; } if (d == W) { - _xi-= _speed; + _x[9]-= _speed; } } - if((length == 9)&&(b8 == 1)) { + if((length == 9)&&(b[8] == 1)) { if (d == E) { - _xh+= _speed; + _x[8]+= _speed; } if (d == W) { - _xh-= _speed; + _x[8]-= _speed; } } - if((length == 8)&&(b7 == 1)) { + if((length == 8)&&(b[7] == 1)) { if (d == E) { - _xg+= _speed; + _x[7]+= _speed; } if (d == W) { - _xg-= _speed; + _x[7]-= _speed; } } - if((length == 7)&&(b6 == 1)) { + if((length == 7)&&(b[6] == 1)) { if (d == E) { - _xf+= _speed; + _x[6]+= _speed; } if (d == W) { - _xf-= _speed; + _x[6]-= _speed; } } - if((length == 6)&&(b5 == 1)) { + if((length == 6)&&(b[5] == 1)) { if (d == E) { - _xe+= _speed; + _x[5]+= _speed; } if (d == W) { - _xe-= _speed; + _x[5]-= _speed; } } - if((length == 5)&&(b4 == 1)) { + if((length == 5)&&(b[4] == 1)) { if (d == E) { - _xd+= _speed; + _x[4]+= _speed; } if (d == W) { - _xd-= _speed; + _x[4]-= _speed; } } - if((length == 4)&&(b3 == 1)) { + if((length == 4)&&(b[3] == 1)) { if (d == E) { - _xc+= _speed; + _x[3]+= _speed; } if (d == W) { - _xc-= _speed; + _x[3]-= _speed; } } - if((length == 3)&&(b2 == 1)) { + if((length == 3)&&(b[2] == 1)) { if (d == E) { - _xb+= _speed; + _x[2]+= _speed; } if (d == W) { - _xb-= _speed; + _x[2]-= _speed; } } - if((length == 2)&&(b1 == 1)) { + if((length == 2)&&(b[1] == 1)) { if (d == E) { - _xa+= _speed; + _x[1]+= _speed; } if (d == W) { - _xa-= _speed; + _x[1]-= _speed; } } - if((length == 1)&&(b0 == 1)) { + if((length == 1)&&(b[0] == 1)) { if (d == E) { - _x+= _speed; + _x[0]+= _speed; } if (d == W) { - _x-= _speed; + _x[0]-= _speed; } } // the following makes sure that when the length is increased, the snake stays where it was when it ate food. if(length < 2) { - _xa = _x; + _x[1] = _x[0]; } else if(length < 3) { - _xb = _xa; + _x[2] = _x[1]; } else if(length < 4) { - _xc = _xb; + _x[3] = _x[2]; } else if(length < 5) { - _xd = _xc; + _x[4] = _x[3]; } else if(length < 6) { - _xe = _xd; + _x[5] = _x[4]; } else if(length < 7) { - _xf = _xe; + _x[6] = _x[5]; } else if(length < 8) { - _xg = _xf; + _x[7] = _x[6]; } else if(length < 9) { - _xh = _xg; + _x[8] = _x[7]; } else if(length < 10) { - _xi = _xh; + _x[9] = _x[8]; } else if(length < 11) { - _xj = _xi; + _x[10] = _x[9]; } else if(length < 12) { - _xk = _xj; + _x[11] = _x[10]; } else if(length < 13) { - _xl = _xk; + _x[12] = _x[11]; } else if(length < 14) { - _xm = _xl; + _x[13] = _x[12]; } else if(length < 15) { - _xn = _xm; + _x[14] = _x[13]; } //Limits set so that the sprite does not travel off the screen. - if (_y <= 0) { - _y = 0; + if (_y[0] <= 0) { + _y[0] = 0; } - if (_x <= 0) { - _x = 0; + if (_x[0] <= 0) { + _x[0] = 0; } - if (_xa <= 0) { - _xa = 0; + if (_x[1] <= 0) { + _x[1] = 0; } - if (_xb <= 0) { - _xb = 0; + if (_x[2] <= 0) { + _x[2] = 0; } - if (_xc <= 0) { - _xc = 0; + if (_x[3] <= 0) { + _x[3] = 0; } - if (_xd <= 0) { - _xd = 0; + if (_x[4] <= 0) { + _x[4] = 0; } - if (_xe <= 0) { - _xe = 0; + if (_x[5] <= 0) { + _x[5] = 0; } - if (_xf <= 0) { - _xf = 0; + if (_x[6] <= 0) { + _x[6] = 0; } - if (_xg <= 0) { - _xg = 0; + if (_x[7] <= 0) { + _x[7] = 0; } - if (_xh <= 0) { - _xh = 0; + if (_x[8] <= 0) { + _x[8] = 0; } - if (_xi <= 0) { - _xi = 0; + if (_x[9] <= 0) { + _x[9] = 0; } - if (_xj <= 0) { - _xj = 0; + if (_x[10] <= 0) { + _x[10] = 0; } - if (_xk <= 0) { - _xk = 0; + if (_x[11] <= 0) { + _x[11] = 0; } - if (_xl <= 0) { - _xl = 0; + if (_x[12] <= 0) { + _x[12] = 0; } - if (_xm <= 0) { - _xm = 0; + if (_x[13] <= 0) { + _x[13] = 0; } - if (_xn <= 0) { - _xn = 0; + if (_x[14] <= 0) { + _x[14] = 0; } - if (_x > 81) { - _x = 81; + if (_x[0] > 81) { + _x[0] = 81; } - if (_xa > 81) { - _xa = 81; + if (_x[1] > 81) { + _x[1] = 81; } - if (_xb > 81) { - _xb = 81; + if (_x[2] > 81) { + _x[2] = 81; } - if (_xc > 81) { - _xc = 81; + if (_x[3] > 81) { + _x[3] = 81; } - if (_xd > 81) { - _xd = 81; + if (_x[4] > 81) { + _x[4] = 81; } - if (_xe > 81) { - _xe = 81; + if (_x[5] > 81) { + _x[5] = 81; } - if (_xf > 81) { - _xf = 81; + if (_x[6] > 81) { + _x[6] = 81; } - if (_xg > 81) { - _xg = 81; + if (_x[7] > 81) { + _x[7] = 81; } - if (_xh > 81) { - _xh = 81; + if (_x[8] > 81) { + _x[8] = 81; } - if (_xi > 81) { - _xi = 81; + if (_x[9] > 81) { + _x[9] = 81; } - if (_xj > 81) { - _xj = 81; + if (_x[10] > 81) { + _x[10] = 81; } - if (_xk > 81) { - _xk = 81; + if (_x[11] > 81) { + _x[11] = 81; } - if (_xl > 81) { - _xl = 81; + if (_x[12] > 81) { + _x[12] = 81; } - if (_xm > 81) { - _xm = 81; + if (_x[13] > 81) { + _x[13] = 81; } - if (_xn > 81) { - _xn = 81; + if (_x[14] > 81) { + _x[14] = 81; } }