Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
Snake/Snake.cpp
- Committer:
- AhmedPlaymaker
- Date:
- 2019-04-08
- Revision:
- 18:b391caa5754c
- Parent:
- 17:54e13faeaf64
- Child:
- 19:05cc9f801468
File content as of revision 18:b391caa5754c:
#include "Snake.h" Snake::Snake() { } Snake::~Snake() { } //The Snake Sprite. int snake_sprite[3][3] = { {0,1,0}, {1,0,1}, {0,1,0}, }; int m = 0; //Variable used to allow a starting location for the player. void Snake::init() { _speed = 1;// change this according to the options selected } int Snake::draw(Gamepad &pad, N5110 &lcd, int length) { 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; m = m+1; } //printf("SPRITE %d %d \n", _x, _y); if(length == 0) { 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. } else if(length == 1) { lcd.drawSprite(_x,_y,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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } else if(length > 15) { lcd.clear(); lcd.printString("Level Complete",0,1); lcd.refresh(); wait(1); length = 3; } return length; } /* //helps to set the position automatically when we want to restrict it's movement when coliding with lines. void Snake::set_pos(Vector2D s) { if(length == 1) { _fx = s.x; _fy = s.y; } else if(length == 2) { _xa = s.x; _ya = s.y; } else if(length==3) { _xb = s.x; _yb = s.y; } else if(length==4) { _xc = s.x; _yc = s.y; } else if(length==5) { _xd = s.x; _yd = s.y; } else if(length==6) { _xe = s.x; _ye = s.y; } else if(length==7) { _xf = s.x; _yf = s.y; } else if(length==8) { _xg = s.x; _yg = s.y; } else if(length==9) { _xh = s.x; _yh = s.y; } else if(length==10) { _xi = s.x; _yi = s.y; } else if(length==11) { _xj = s.x; _yj = s.y; } else if(length==12) { _xk = s.x; _yk = s.y; } else if(length==13) { _xl = s.x; _yl = s.y; } else if(length == 14) { _xm = s.x; _ym = s.y; } else if(length==15) { _xn = s.x; _yn = s.y; } } */ Vector2D Snake::get_pos(int length) { if(length == 1) { Vector2D snakepos = {_x,_y}; //Obtains the snake position. return snakepos; } else if(length == 2) { Vector2D snakepos = {_xa,_ya}; //Obtains the snake position. return snakepos; } else if(length==3) { Vector2D snakepos = {_xb,_yb}; //Obtains the snake position. return snakepos; } else if(length==4) { Vector2D snakepos = {_xc,_yc}; //Obtains the snake position. return snakepos; } else if(length==5) { Vector2D snakepos = {_xd,_yd}; //Obtains the snake position. return snakepos; } else if(length==6) { Vector2D snakepos = {_xe,_ye}; //Obtains the snake position. return snakepos; } else if(length==7) { Vector2D snakepos = {_xf,_yf}; //Obtains the snake position. return snakepos; } else if(length==8) { Vector2D snakepos = {_xg,_yg}; //Obtains the snake position. return snakepos; } else if(length==9) { Vector2D snakepos = {_xh,_yh}; //Obtains the snake position. return snakepos; } else if(length==10) { Vector2D snakepos = {_xi,_yi}; //Obtains the snake position. return snakepos; } else if(length==11) { Vector2D snakepos = {_xj,_yj}; //Obtains the snake position. return snakepos; } else if(length==12) { Vector2D snakepos = {_xk,_yk}; //Obtains the snake position. return snakepos; } else if(length==13) { Vector2D snakepos = {_xl,_yl}; //Obtains the snake position. return snakepos; } else if(length == 14) { Vector2D snakepos = {_xm,_ym}; //Obtains the snake position. return snakepos; } else if(length==15) { Vector2D snakepos = {_xn,_yn}; //Obtains the snake position. return snakepos; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); else { Vector2D snakepos = {-20,-20}; //Obtains the snake position. return snakepos; } } 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. return snakepos_b1; } else if(length==3) { Vector2D snakepos_b1 = {_xa,_ya}; //Obtains the snake position. return snakepos_b1; } else if(length==4) { Vector2D snakepos_b1 = {_xb,_yb}; //Obtains the snake position. return snakepos_b1; } else if(length==5) { Vector2D snakepos_b1 = {_xc,_yc}; //Obtains the snake position. return snakepos_b1; } else if(length==6) { Vector2D snakepos_b1 = {_xd,_yd}; //Obtains the snake position. return snakepos_b1; } else if(length==7) { Vector2D snakepos_b1 = {_xe,_ye}; //Obtains the snake position. return snakepos_b1; } else if(length==8) { Vector2D snakepos_b1 = {_xf,_yf}; //Obtains the snake position. return snakepos_b1; } else if(length==9) { Vector2D snakepos_b1 = {_xg,_yg}; //Obtains the snake position. return snakepos_b1; } else if(length==10) { Vector2D snakepos_b1 = {_xh,_yh}; //Obtains the snake position. return snakepos_b1; } else if(length==11) { Vector2D snakepos_b1 = {_xi,_yi}; //Obtains the snake position. return snakepos_b1; } else if(length==12) { Vector2D snakepos_b1 = {_xj,_yj}; //Obtains the snake position. return snakepos_b1; } else if(length==13) { Vector2D snakepos_b1 = {_xk,_yk}; //Obtains the snake position. return snakepos_b1; } else if(length == 14) { Vector2D snakepos_b1 = {_xl,_yl}; //Obtains the snake position. return snakepos_b1; } else if(length==15) { Vector2D snakepos_b1 = {_xm,_ym}; //Obtains the snake position. return snakepos_b1; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); else { Vector2D snakepos_b1 = {-20,-20}; //Obtains the snake position. return snakepos_b1; } } 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. return snakepos_b2; } else if(length==4) { Vector2D snakepos_b2 = {_xa,_ya}; //Obtains the snake position. return snakepos_b2; } else if(length==5) { Vector2D snakepos_b2 = {_xb,_yb}; //Obtains the snake position. return snakepos_b2; } else if(length==6) { Vector2D snakepos_b2 = {_xc,_yc}; //Obtains the snake position. return snakepos_b2; } else if(length==7) { Vector2D snakepos_b2 = {_xd,_yd}; //Obtains the snake position. return snakepos_b2; } else if(length==8) { Vector2D snakepos_b2 = {_xe,_ye}; //Obtains the snake position. return snakepos_b2; } else if(length==9) { Vector2D snakepos_b2 = {_xf,_yf}; //Obtains the snake position. return snakepos_b2; } else if(length==10) { Vector2D snakepos_b2 = {_xg,_yg}; //Obtains the snake position. return snakepos_b2; } else if(length==11) { Vector2D snakepos_b2 = {_xh,_yh}; //Obtains the snake position. return snakepos_b2; } else if(length==12) { Vector2D snakepos_b2 = {_xi,_yi}; //Obtains the snake position. return snakepos_b2; } else if(length==13) { Vector2D snakepos_b2 = {_xj,_yj}; //Obtains the snake position. return snakepos_b2; } else if(length==14) { Vector2D snakepos_b2 = {_xk,_yk}; //Obtains the snake position. return snakepos_b2; } else if(length == 15) { Vector2D snakepos_b2 = {_xl,_yl}; //Obtains the snake position. return snakepos_b2; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); else { Vector2D snakepos_b2 = {-20,-20}; //Obtains the snake position. return snakepos_b2; } } 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. return snakepos_b3; } else if(length==5) { Vector2D snakepos_b3 = {_xa,_ya}; //Obtains the snake position. return snakepos_b3; } else if(length==6) { Vector2D snakepos_b3 = {_xb,_yb}; //Obtains the snake position. return snakepos_b3; } else if(length==7) { Vector2D snakepos_b3 = {_xc,_yc}; //Obtains the snake position. return snakepos_b3; } else if(length==8) { Vector2D snakepos_b3 = {_xd,_yd}; //Obtains the snake position. return snakepos_b3; } else if(length==9) { Vector2D snakepos_b3 = {_xe,_ye}; //Obtains the snake position. return snakepos_b3; } else if(length==10) { Vector2D snakepos_b3 = {_xf,_yf}; //Obtains the snake position. return snakepos_b3; } else if(length==11) { Vector2D snakepos_b3 = {_xg,_yg}; //Obtains the snake position. return snakepos_b3; } else if(length==12) { Vector2D snakepos_b3 = {_xh,_yh}; //Obtains the snake position. return snakepos_b3; } else if(length==13) { Vector2D snakepos_b3 = {_xi,_yi}; //Obtains the snake position. return snakepos_b3; } else if(length==14) { Vector2D snakepos_b3 = {_xj,_yj}; //Obtains the snake position. return snakepos_b3; } else if(length==15) { Vector2D snakepos_b3 = {_xk,_yk}; //Obtains the snake position. return snakepos_b3; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); else { Vector2D snakepos_b3 = {-20,-20}; //Obtains the snake position. return snakepos_b3; } } 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. return snakepos_b4; } else if(length==6) { Vector2D snakepos_b4 = {_xa,_ya}; //Obtains the snake position. return snakepos_b4; } else if(length==7) { Vector2D snakepos_b4 = {_xb,_yb}; //Obtains the snake position. return snakepos_b4; } else if(length==8) { Vector2D snakepos_b4 = {_xc,_yc}; //Obtains the snake position. return snakepos_b4; } else if(length==9) { Vector2D snakepos_b4 = {_xd,_yd}; //Obtains the snake position. return snakepos_b4; } else if(length==10) { Vector2D snakepos_b4 = {_xe,_ye}; //Obtains the snake position. return snakepos_b4; } else if(length==11) { Vector2D snakepos_b4 = {_xf,_yf}; //Obtains the snake position. return snakepos_b4; } else if(length==12) { Vector2D snakepos_b4 = {_xg,_yg}; //Obtains the snake position. return snakepos_b4; } else if(length==13) { Vector2D snakepos_b4 = {_xh,_yh}; //Obtains the snake position. return snakepos_b4; } else if(length==14) { Vector2D snakepos_b4 = {_xi,_yi}; //Obtains the snake position. return snakepos_b4; } else if(length==15) { Vector2D snakepos_b4 = {_xj,_yj}; //Obtains the snake position. return snakepos_b4; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); else { Vector2D snakepos_b4 = {-20,-20}; //Obtains the snake position. return snakepos_b4; } } 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. return snakepos_b5; } else if(length==7) { Vector2D snakepos_b5 = {_xa,_ya}; //Obtains the snake position. return snakepos_b5; } else if(length==8) { Vector2D snakepos_b5 = {_xb,_yb}; //Obtains the snake position. return snakepos_b5; } else if(length==9) { Vector2D snakepos_b5 = {_xc,_yc}; //Obtains the snake position. return snakepos_b5; } else if(length==10) { Vector2D snakepos_b5 = {_xd,_yd}; //Obtains the snake position. return snakepos_b5; } else if(length==11) { Vector2D snakepos_b5 = {_xe,_ye}; //Obtains the snake position. return snakepos_b5; } else if(length==12) { Vector2D snakepos_b5 = {_xf,_yf}; //Obtains the snake position. return snakepos_b5; } else if(length==13) { Vector2D snakepos_b5 = {_xg,_yg}; //Obtains the snake position. return snakepos_b5; } else if(length==14) { Vector2D snakepos_b5 = {_xh,_yh}; //Obtains the snake position. return snakepos_b5; } else if(length==15) { Vector2D snakepos_b5 = {_xi,_yi}; //Obtains the snake position. return snakepos_b5; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); else { Vector2D snakepos_b5 = {-20,-20}; //Obtains the snake position. return snakepos_b5; } } 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. return snakepos_b6; } else if(length==8) { Vector2D snakepos_b6 = {_xa,_ya}; //Obtains the snake position. return snakepos_b6; } else if(length==9) { Vector2D snakepos_b6 = {_xb,_yb}; //Obtains the snake position. return snakepos_b6; } else if(length==10) { Vector2D snakepos_b6 = {_xc,_yc}; //Obtains the snake position. return snakepos_b6; } else if(length==11) { Vector2D snakepos_b6 = {_xd,_yd}; //Obtains the snake position. return snakepos_b6; } else if(length==12) { Vector2D snakepos_b6 = {_xe,_ye}; //Obtains the snake position. return snakepos_b6; } else if(length==13) { Vector2D snakepos_b6 = {_xf,_yf}; //Obtains the snake position. return snakepos_b6; } else if(length==14) { Vector2D snakepos_b6 = {_xg,_yg}; //Obtains the snake position. return snakepos_b6; } else if(length==15) { Vector2D snakepos_b6 = {_xh,_yh}; //Obtains the snake position. return snakepos_b6; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); else { Vector2D snakepos_b6 = {-20,-20}; //Obtains the snake position. return snakepos_b6; } } 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. return snakepos_b7; } else if(length==9) { Vector2D snakepos_b7 = {_xa,_ya}; //Obtains the snake position. return snakepos_b7; } else if(length==10) { Vector2D snakepos_b7 = {_xb,_yb}; //Obtains the snake position. return snakepos_b7; } else if(length==11) { Vector2D snakepos_b7 = {_xc,_yc}; //Obtains the snake position. return snakepos_b7; } else if(length==12) { Vector2D snakepos_b7 = {_xd,_yd}; //Obtains the snake position. return snakepos_b7; } else if(length==13) { Vector2D snakepos_b7 = {_xe,_ye}; //Obtains the snake position. return snakepos_b7; } else if(length==14) { Vector2D snakepos_b7 = {_xf,_yf}; //Obtains the snake position. return snakepos_b7; } else if(length==15) { Vector2D snakepos_b7 = {_xg,_yg}; //Obtains the snake position. return snakepos_b7; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); else { Vector2D snakepos_b7 = {-20,-20}; //Obtains the snake position. return snakepos_b7; } } 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. return snakepos_b8; } else if(length==10) { Vector2D snakepos_b8 = {_xa,_ya}; //Obtains the snake position. return snakepos_b8; } else if(length==11) { Vector2D snakepos_b8 = {_xb,_yb}; //Obtains the snake position. return snakepos_b8; } else if(length==12) { Vector2D snakepos_b8 = {_xc,_yc}; //Obtains the snake position. return snakepos_b8; } else if(length==13) { Vector2D snakepos_b8 = {_xd,_yd}; //Obtains the snake position. return snakepos_b8; } else if(length==14) { Vector2D snakepos_b8 = {_xe,_ye}; //Obtains the snake position. return snakepos_b8; } else if(length==15) { Vector2D snakepos_b8 = {_xf,_yf}; //Obtains the snake position. return snakepos_b8; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); else { Vector2D snakepos_b8 = {-20,-20}; //Obtains the snake position. return snakepos_b8; } } 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. return snakepos_b9; } else if(length==11) { Vector2D snakepos_b9 = {_xa,_ya}; //Obtains the snake position. return snakepos_b9; } else if(length==12) { Vector2D snakepos_b9 = {_xb,_yb}; //Obtains the snake position. return snakepos_b9; } else if(length==13) { Vector2D snakepos_b9 = {_xc,_yc}; //Obtains the snake position. return snakepos_b9; } else if(length==14) { Vector2D snakepos_b9 = {_xd,_yd}; //Obtains the snake position. return snakepos_b9; } else if(length==15) { Vector2D snakepos_b9 = {_xe,_ye}; //Obtains the snake position. return snakepos_b9; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); else { Vector2D snakepos_b9 = {-20,-20}; //Obtains the snake position. return snakepos_b9; } } 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. return snakepos_b10; } else if(length==12) { Vector2D snakepos_b10 = {_xa,_ya}; //Obtains the snake position. return snakepos_b10; } else if(length==13) { Vector2D snakepos_b10 = {_xb,_yb}; //Obtains the snake position. return snakepos_b10; } else if(length==14) { Vector2D snakepos_b10 = {_xc,_yc}; //Obtains the snake position. return snakepos_b10; } else if(length==15) { Vector2D snakepos_b10 = {_xd,_yd}; //Obtains the snake position. return snakepos_b10; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); else { Vector2D snakepos_b10 = {-20,-20}; //Obtains the snake position. return snakepos_b10; } } 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. return snakepos_b11; } else if(length==13) { Vector2D snakepos_b11 = {_xa,_ya}; //Obtains the snake position. return snakepos_b11; } else if(length==14) { Vector2D snakepos_b11 = {_xb,_yb}; //Obtains the snake position. return snakepos_b11; } else if(length==15) { Vector2D snakepos_b11 = {_xc,_yc}; //Obtains the snake position. return snakepos_b11; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); else { Vector2D snakepos_b11 = {-20,-20}; //Obtains the snake position. return snakepos_b11; } } 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. return snakepos_b12; } else if(length==14) { Vector2D snakepos_b12 = {_xa,_ya}; //Obtains the snake position. return snakepos_b12; } else if(length==15) { Vector2D snakepos_b12 = {_xb,_yb}; //Obtains the snake position. return snakepos_b12; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); else { Vector2D snakepos_b12 = {-20,-20}; //Obtains the snake position. return snakepos_b12; } } 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. return snakepos_b13; } else if(length==15) { Vector2D snakepos_b13 = {_xa,_ya}; //Obtains the snake position. return snakepos_b13; } //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y); else { Vector2D snakepos_b13 = {-20,-20}; //Obtains the snake position. return snakepos_b13; } } 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. 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; } } 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]; if(length > 1) { if ((_x > _xa)&&(b1 == 1)&&(b0 == 1)) { _x-=_speed; } if ((_x < _xa)&&(b1 == 1)&&(b0 == 1)) { _x+=_speed; } if(length > 2) { if ((_xa > _xb)&&(b2 == 1)&&(b1 == 1)) { _xa-=_speed; } if ((_xa < _xb)&&(b2 == 1)&&(b1 == 1)) { _xa+=_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 == 15)&&(b14 == 1)) { if (d == E) { _xn+= _speed; } if (d == W) { _xn-= _speed; } } if((length == 14)&&(b13 == 1)) { if (d == E) { _xm+= _speed; } if (d == W) { _xm-= _speed; } } if((length == 13)&&(b12 == 1)) { if (d == E) { _xl+= _speed; } if (d == W) { _xl-= _speed; } } if((length == 12)&&(b11 == 1)) { if (d == E) { _xk+= _speed; } if (d == W) { _xk-= _speed; } } if((length == 11)&&(b10 == 1)) { if (d == E) { _xj+= _speed; } if (d == W) { _xj-= _speed; } } if((length == 10)&&(b9 == 1)) { if (d == E) { _xi+= _speed; } if (d == W) { _xi-= _speed; } } if((length == 9)&&(b8 == 1)) { if (d == E) { _xh+= _speed; } if (d == W) { _xh-= _speed; } } if((length == 8)&&(b7 == 1)) { if (d == E) { _xg+= _speed; } if (d == W) { _xg-= _speed; } } if((length == 7)&&(b6 == 1)) { if (d == E) { _xf+= _speed; } if (d == W) { _xf-= _speed; } } if((length == 6)&&(b5 == 1)) { if (d == E) { _xe+= _speed; } if (d == W) { _xe-= _speed; } } if((length == 5)&&(b4 == 1)) { if (d == E) { _xd+= _speed; } if (d == W) { _xd-= _speed; } } if((length == 4)&&(b3 == 1)) { if (d == E) { _xc+= _speed; } if (d == W) { _xc-= _speed; } } if((length == 3)&&(b2 == 1)) { if (d == E) { _xb+= _speed; } if (d == W) { _xb-= _speed; } } if((length == 2)&&(b1 == 1)) { if (d == E) { _xa+= _speed; } if (d == W) { _xa-= _speed; } } if((length == 1)&&(b0 == 1)) { if (d == E) { _x+= _speed; } if (d == W) { _x-= _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; } else if(length < 3) { _xb = _xa; } else if(length < 4) { _xc = _xb; } else if(length < 5) { _xd = _xc; } else if(length < 6) { _xe = _xd; } else if(length < 7) { _xf = _xe; } else if(length < 8) { _xg = _xf; } else if(length < 9) { _xh = _xg; } else if(length < 10) { _xi = _xh; } else if(length < 11) { _xj = _xi; } else if(length < 12) { _xk = _xj; } else if(length < 13) { _xl = _xk; } else if(length < 14) { _xm = _xl; } else if(length < 15) { _xn = _xm; } //Limits set so that the sprite does not travel off the screen. if (_y <= 0) { _y = 0; } if (_x <= 0) { _x = 0; } if (_xa <= 0) { _xa = 0; } if (_xb <= 0) { _xb = 0; } if (_xc <= 0) { _xc = 0; } if (_xd <= 0) { _xd = 0; } if (_xe <= 0) { _xe = 0; } if (_xf <= 0) { _xf = 0; } if (_xg <= 0) { _xg = 0; } if (_xh <= 0) { _xh = 0; } if (_xi <= 0) { _xi = 0; } if (_xj <= 0) { _xj = 0; } if (_xk <= 0) { _xk = 0; } if (_xl <= 0) { _xl = 0; } if (_xm <= 0) { _xm = 0; } if (_xn <= 0) { _xn = 0; } if (_x > 81) { _x = 81; } if (_xa > 81) { _xa = 81; } if (_xb > 81) { _xb = 81; } if (_xc > 81) { _xc = 81; } if (_xd > 81) { _xd = 81; } if (_xe > 81) { _xe = 81; } if (_xf > 81) { _xf = 81; } if (_xg > 81) { _xg = 81; } if (_xh > 81) { _xh = 81; } if (_xi > 81) { _xi = 81; } if (_xj > 81) { _xj = 81; } if (_xk > 81) { _xk = 81; } if (_xl > 81) { _xl = 81; } if (_xm > 81) { _xm = 81; } if (_xn > 81) { _xn = 81; } }