Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Snake/Snake.cpp
- Committer:
- AhmedPlaymaker
- Date:
- 2019-04-03
- Revision:
- 13:9785f2404045
- Parent:
- 12:1e601b176437
- Child:
- 16:7b474f873683
File content as of revision 13:9785f2404045:
#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 = 0.15;// change this according to the options selected
}
void Snake::draw(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;
m = m+1;
}
//printf("SPRITE %d %d \n", _x, _y);
if(length == 0) {
NVIC_SystemReset(); //Software Reset. //change this condition to loosing screen.
}
if(length == 1) {
lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
}
if(length == 2) {
lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite);
}
if(length == 3) {
lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite);
lcd.drawSprite(_xb,_yb,3,3,(int *)snake_sprite);
}
if(length == 4) {
lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite);
lcd.drawSprite(_xb,_yb,3,3,(int *)snake_sprite);
lcd.drawSprite(_xc,_yc,3,3,(int *)snake_sprite);
}
if(length == 5) {
lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
lcd.drawSprite(_xa,_ya,3,3,(int *)snake_sprite);
lcd.drawSprite(_xb,_yb,3,3,(int *)snake_sprite);
lcd.drawSprite(_xc,_yc,3,3,(int *)snake_sprite);
lcd.drawSprite(_xd,_yd,3,3,(int *)snake_sprite);
}
if(length == 6) {
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
}
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;
}
}
Vector2D Snake::get_pos_before15(int length) //this sends data of following sprites.
{
if(length == 1) {
Vector2D snakepos_b15 = {-20,-20}; //Obtains the snake position.
return snakepos_b15;
}
else if(length == 2) {
Vector2D snakepos_b15 = {-20,-20}; //Obtains the snake position.
return snakepos_b15;
}
else if(length == 3) {
Vector2D snakepos_b15 = {-20,-20}; //Obtains the snake position.
return snakepos_b15;
}
else if(length == 4) {
Vector2D snakepos_b15 = {-20,-20}; //Obtains the snake position.
return snakepos_b15;
}
else if(length == 5) {
Vector2D snakepos_b15 = {-20,-20}; //Obtains the snake position.
return snakepos_b15;
}
else if(length == 6) {
Vector2D snakepos_b15 = {-20,-20}; //Obtains the snake position.
return snakepos_b15;
}
else if(length == 7) {
Vector2D snakepos_b15 = {-20,-20}; //Obtains the snake position.
return snakepos_b15;
}
else if(length == 8) {
Vector2D snakepos_b15 = {-20,-20}; //Obtains the snake position.
return snakepos_b15;
}
else if(length == 9) {
Vector2D snakepos_b15 = {-20,-20}; //Obtains the snake position.
return snakepos_b15;
}
else if(length == 10) {
Vector2D snakepos_b15 = {-20,-20}; //Obtains the snake position.
return snakepos_b15;
}
else if(length == 11) {
Vector2D snakepos_b15 = {-20,-20}; //Obtains the snake position.
return snakepos_b15;
}
else if(length == 12) {
Vector2D snakepos_b15 = {-20,-20}; //Obtains the snake position.
return snakepos_b15;
}
else if(length == 13) {
Vector2D snakepos_b15 = {-20,-20}; //Obtains the snake position.
return snakepos_b15;
}
else if(length == 14) {
Vector2D snakepos_b15 = {-20,-20}; //Obtains the snake position.
return snakepos_b15;
}
else if(length == 15) {
Vector2D snakepos_b15 = {-20,-20}; //Obtains the snake position.
return snakepos_b15;
}
//printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y);
else {
Vector2D snakepos_b15 = {-20,-20}; //Obtains the snake position.
return snakepos_b15;
}
}
void Snake::update(Direction d,float mag,int length, int speed)
{
_speed = speed; //Speed changes depending on how much you push the joystick.(As Of Now)
if(length > 1) {
if (_x > _xa) {
_x-=_speed;
}
if (_x < _xa) {
_x+=_speed;
}
if(length > 2) {
if (_xa > _xb) {
_xa-=_speed;
}
if (_xa < _xb) {
_xa+=_speed;
}
if(length > 3) {
if (_xb > _xc) {
_xb-=_speed;
}
if (_xb < _xc) {
_xb+=_speed;
}
if(length > 4) {
if (_xc > _xd) {
_xc-=_speed;
}
if (_xc < _xd) {
_xc+=_speed;
}
if(length > 5) {
if (_xd > _xe) {
_xd-=_speed;
}
if (_xd < _xe) {
_xd+=_speed;
}
if(length > 6) {
if (_xe > _xf) {
_xe-=_speed;
}
if (_xe < _xf) {
_xe+=_speed;
}
if(length > 7) {
if (_xf > _xg) {
_xf-=_speed;
}
if (_xf < _xg) {
_xf+=_speed;
}
if(length > 8) {
if (_xg > _xh) {
_xg-=_speed;
}
if (_xg < _xh) {
_xg+=_speed;
}
if(length > 9) {
if (_xh > _xi) {
_xh-=_speed;
}
if (_xh < _xi) {
_xh+=_speed;
}
if(length > 10) {
if (_xi > _xj) {
_xi-=_speed;
}
if (_xi < _xj) {
_xi+=_speed;
}
if(length > 11) {
if (_xj > _xk) {
_xj-=_speed;
}
if (_xj < _xk) {
_xj+=_speed;
}
if(length > 12) {
if (_xk > _xl) {
_xk-=_speed;
}
if (_xk < _xl) {
_xk+=_speed;
}
if(length > 13) {
if (_xl > _xm) {
_xl-=_speed;
}
if (_xl < _xm) {
_xl+=_speed;
}
if(length > 14) {
if (_xm > _xn) {
_xm-=_speed;
}
if (_xm < _xn) {
_xm+=_speed;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
// Diagonal speeds are /2 to prevent player from going double the speed.
if(length == 15) {
if (d == E) {
_xn+= _speed;
}
if (d == W) {
_xn-= _speed;
}
}
if(length == 14) {
if (d == E) {
_xm+= _speed;
}
if (d == W) {
_xm-= _speed;
}
}
if(length == 13) {
if (d == E) {
_xl+= _speed;
}
if (d == W) {
_xl-= _speed;
}
}
if(length == 12) {
if (d == E) {
_xk+= _speed;
}
if (d == W) {
_xk-= _speed;
}
}
if(length == 11) {
if (d == E) {
_xj+= _speed;
}
if (d == W) {
_xj-= _speed;
}
}
if(length == 10) {
if (d == E) {
_xi+= _speed;
}
if (d == W) {
_xi-= _speed;
}
}
if(length == 9) {
if (d == E) {
_xh+= _speed;
}
if (d == W) {
_xh-= _speed;
}
}
if(length == 8) {
if (d == E) {
_xg+= _speed;
}
if (d == W) {
_xg-= _speed;
}
}
if(length == 7) {
if (d == E) {
_xf+= _speed;
}
if (d == W) {
_xf-= _speed;
}
}
if(length == 6) {
if (d == E) {
_xe+= _speed;
}
if (d == W) {
_xe-= _speed;
}
}
if(length == 5) {
if (d == E) {
_xd+= _speed;
}
if (d == W) {
_xd-= _speed;
}
}
if(length == 4) {
if (d == E) {
_xc+= _speed;
}
if (d == W) {
_xc-= _speed;
}
}
if(length == 3) {
if (d == E) {
_xb+= _speed;
}
if (d == W) {
_xb-= _speed;
}
}
if(length == 2) {
if (d == E) {
_xa+= _speed;
}
if (d == W) {
_xa-= _speed;
}
}
if(length == 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;
}
}