Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Committer:
AhmedPlaymaker
Date:
Tue Apr 02 17:06:22 2019 +0000
Revision:
12:1e601b176437
Parent:
9:d1d79d4ee673
Child:
13:9785f2404045
Completed the snake and block collision function, the blocks decrease in number as the snake collides while the snake decreases in length

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AhmedPlaymaker 7:48ba87cd79b5 1 #include "Snake.h"
AhmedPlaymaker 7:48ba87cd79b5 2
AhmedPlaymaker 7:48ba87cd79b5 3 Snake::Snake()
AhmedPlaymaker 7:48ba87cd79b5 4 {
AhmedPlaymaker 7:48ba87cd79b5 5
AhmedPlaymaker 7:48ba87cd79b5 6 }
AhmedPlaymaker 7:48ba87cd79b5 7
AhmedPlaymaker 7:48ba87cd79b5 8 Snake::~Snake()
AhmedPlaymaker 7:48ba87cd79b5 9 {
AhmedPlaymaker 7:48ba87cd79b5 10
AhmedPlaymaker 7:48ba87cd79b5 11 }
AhmedPlaymaker 7:48ba87cd79b5 12
AhmedPlaymaker 7:48ba87cd79b5 13 //The Snake Sprite.
AhmedPlaymaker 8:890b986b16a4 14 int snake_sprite[3][3] = {
AhmedPlaymaker 8:890b986b16a4 15 {0,1,0},
AhmedPlaymaker 8:890b986b16a4 16 {1,0,1},
AhmedPlaymaker 8:890b986b16a4 17 {0,1,0},
AhmedPlaymaker 9:d1d79d4ee673 18 };
AhmedPlaymaker 7:48ba87cd79b5 19
AhmedPlaymaker 7:48ba87cd79b5 20 int m = 0; //Variable used to allow a starting location for the player.
AhmedPlaymaker 7:48ba87cd79b5 21
AhmedPlaymaker 7:48ba87cd79b5 22
AhmedPlaymaker 7:48ba87cd79b5 23 void Snake::init()
AhmedPlaymaker 7:48ba87cd79b5 24 {
AhmedPlaymaker 7:48ba87cd79b5 25
AhmedPlaymaker 7:48ba87cd79b5 26 _speed = 0.15;// change this according to the options selected
AhmedPlaymaker 7:48ba87cd79b5 27
AhmedPlaymaker 7:48ba87cd79b5 28 }
AhmedPlaymaker 7:48ba87cd79b5 29
AhmedPlaymaker 7:48ba87cd79b5 30
AhmedPlaymaker 8:890b986b16a4 31 void Snake::draw(N5110 &lcd, int length)
AhmedPlaymaker 7:48ba87cd79b5 32 {
AhmedPlaymaker 7:48ba87cd79b5 33 if(m == 0){
AhmedPlaymaker 7:48ba87cd79b5 34 _x = WIDTH/2; //Spawns player sprite near the middle of the screen.
AhmedPlaymaker 8:890b986b16a4 35 _xa = _x;
AhmedPlaymaker 9:d1d79d4ee673 36 _xb = _xa;
AhmedPlaymaker 9:d1d79d4ee673 37 _xc = _xb;
AhmedPlaymaker 9:d1d79d4ee673 38 _xd = _xc;
AhmedPlaymaker 9:d1d79d4ee673 39 _xe = _xd;
AhmedPlaymaker 9:d1d79d4ee673 40 _xf = _xe;
AhmedPlaymaker 9:d1d79d4ee673 41 _xg = _xf;
AhmedPlaymaker 9:d1d79d4ee673 42 _xh = _xg;
AhmedPlaymaker 9:d1d79d4ee673 43 _xi = _xh;
AhmedPlaymaker 9:d1d79d4ee673 44 _xj = _xi;
AhmedPlaymaker 9:d1d79d4ee673 45 _xk = _xj;
AhmedPlaymaker 9:d1d79d4ee673 46 _xl = _xk;
AhmedPlaymaker 9:d1d79d4ee673 47 _xm = _xl;
AhmedPlaymaker 9:d1d79d4ee673 48 _xn = _xm;
AhmedPlaymaker 7:48ba87cd79b5 49 _y = HEIGHT - 3;
AhmedPlaymaker 7:48ba87cd79b5 50 m = m+1;
AhmedPlaymaker 7:48ba87cd79b5 51 }
AhmedPlaymaker 7:48ba87cd79b5 52 //printf("SPRITE %d %d \n", _x, _y);
AhmedPlaymaker 8:890b986b16a4 53 if(length == 0) {
AhmedPlaymaker 12:1e601b176437 54 NVIC_SystemReset(); //Software Reset. //change this condition to loosing screen.
AhmedPlaymaker 8:890b986b16a4 55 }
AhmedPlaymaker 8:890b986b16a4 56 if(length == 1) {
AhmedPlaymaker 8:890b986b16a4 57 lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
AhmedPlaymaker 8:890b986b16a4 58 }
AhmedPlaymaker 8:890b986b16a4 59 if(length == 2) {
AhmedPlaymaker 8:890b986b16a4 60 lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
AhmedPlaymaker 8:890b986b16a4 61 lcd.drawSprite(_xa,_y-3,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 62 }
AhmedPlaymaker 8:890b986b16a4 63 if(length == 3) {
AhmedPlaymaker 8:890b986b16a4 64 lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
AhmedPlaymaker 8:890b986b16a4 65 lcd.drawSprite(_xa,_y-3,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 66 lcd.drawSprite(_xb,_y-6,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 67 }
AhmedPlaymaker 8:890b986b16a4 68 if(length == 4) {
AhmedPlaymaker 8:890b986b16a4 69 lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
AhmedPlaymaker 8:890b986b16a4 70 lcd.drawSprite(_xa,_y-3,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 71 lcd.drawSprite(_xb,_y-6,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 72 lcd.drawSprite(_xc,_y-9,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 73 }
AhmedPlaymaker 8:890b986b16a4 74 if(length == 5) {
AhmedPlaymaker 8:890b986b16a4 75 lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
AhmedPlaymaker 8:890b986b16a4 76 lcd.drawSprite(_xa,_y-3,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 77 lcd.drawSprite(_xb,_y-6,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 78 lcd.drawSprite(_xc,_y-9,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 79 lcd.drawSprite(_xd,_y-12,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 80 }
AhmedPlaymaker 8:890b986b16a4 81 if(length == 6) {
AhmedPlaymaker 8:890b986b16a4 82 lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
AhmedPlaymaker 8:890b986b16a4 83 lcd.drawSprite(_xa,_y-3,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 84 lcd.drawSprite(_xb,_y-6,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 85 lcd.drawSprite(_xc,_y-9,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 86 lcd.drawSprite(_xd,_y-12,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 87 lcd.drawSprite(_xe,_y-15,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 88 }
AhmedPlaymaker 8:890b986b16a4 89 if(length == 7) {
AhmedPlaymaker 8:890b986b16a4 90 lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
AhmedPlaymaker 8:890b986b16a4 91 lcd.drawSprite(_xa,_y-3,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 92 lcd.drawSprite(_xb,_y-6,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 93 lcd.drawSprite(_xc,_y-9,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 94 lcd.drawSprite(_xd,_y-12,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 95 lcd.drawSprite(_xe,_y-15,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 96 lcd.drawSprite(_xf,_y-18,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 97 }
AhmedPlaymaker 8:890b986b16a4 98 if(length == 8) {
AhmedPlaymaker 8:890b986b16a4 99 lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
AhmedPlaymaker 8:890b986b16a4 100 lcd.drawSprite(_xa,_y-3,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 101 lcd.drawSprite(_xb,_y-6,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 102 lcd.drawSprite(_xc,_y-9,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 103 lcd.drawSprite(_xd,_y-12,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 104 lcd.drawSprite(_xe,_y-15,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 105 lcd.drawSprite(_xf,_y-18,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 106 lcd.drawSprite(_xg,_y-21,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 107 }
AhmedPlaymaker 8:890b986b16a4 108 if(length == 9) {
AhmedPlaymaker 8:890b986b16a4 109 lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
AhmedPlaymaker 8:890b986b16a4 110 lcd.drawSprite(_xa,_y-3,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 111 lcd.drawSprite(_xb,_y-6,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 112 lcd.drawSprite(_xc,_y-9,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 113 lcd.drawSprite(_xd,_y-12,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 114 lcd.drawSprite(_xe,_y-15,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 115 lcd.drawSprite(_xf,_y-18,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 116 lcd.drawSprite(_xg,_y-21,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 117 lcd.drawSprite(_xh,_y-24,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 118 }
AhmedPlaymaker 8:890b986b16a4 119 if(length == 10) {
AhmedPlaymaker 8:890b986b16a4 120 lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
AhmedPlaymaker 8:890b986b16a4 121 lcd.drawSprite(_xa,_y-3,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 122 lcd.drawSprite(_xb,_y-6,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 123 lcd.drawSprite(_xc,_y-9,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 124 lcd.drawSprite(_xd,_y-12,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 125 lcd.drawSprite(_xe,_y-15,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 126 lcd.drawSprite(_xf,_y-18,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 127 lcd.drawSprite(_xg,_y-21,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 128 lcd.drawSprite(_xh,_y-24,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 129 lcd.drawSprite(_xi,_y-27,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 130 }
AhmedPlaymaker 8:890b986b16a4 131 if(length == 11) {
AhmedPlaymaker 8:890b986b16a4 132 lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
AhmedPlaymaker 8:890b986b16a4 133 lcd.drawSprite(_xa,_y-3,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 134 lcd.drawSprite(_xb,_y-6,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 135 lcd.drawSprite(_xc,_y-9,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 136 lcd.drawSprite(_xd,_y-12,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 137 lcd.drawSprite(_xe,_y-15,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 138 lcd.drawSprite(_xf,_y-18,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 139 lcd.drawSprite(_xg,_y-21,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 140 lcd.drawSprite(_xh,_y-24,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 141 lcd.drawSprite(_xi,_y-27,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 142 lcd.drawSprite(_xj,_y-30,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 143 }
AhmedPlaymaker 8:890b986b16a4 144 if(length == 12) {
AhmedPlaymaker 8:890b986b16a4 145 lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
AhmedPlaymaker 8:890b986b16a4 146 lcd.drawSprite(_xa,_y-3,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 147 lcd.drawSprite(_xb,_y-6,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 148 lcd.drawSprite(_xc,_y-9,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 149 lcd.drawSprite(_xd,_y-12,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 150 lcd.drawSprite(_xe,_y-15,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 151 lcd.drawSprite(_xf,_y-18,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 152 lcd.drawSprite(_xg,_y-21,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 153 lcd.drawSprite(_xh,_y-24,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 154 lcd.drawSprite(_xi,_y-27,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 155 lcd.drawSprite(_xj,_y-30,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 156 lcd.drawSprite(_xk,_y-33,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 157 }
AhmedPlaymaker 8:890b986b16a4 158 if(length == 13) {
AhmedPlaymaker 8:890b986b16a4 159 lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
AhmedPlaymaker 8:890b986b16a4 160 lcd.drawSprite(_xa,_y-3,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 161 lcd.drawSprite(_xb,_y-6,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 162 lcd.drawSprite(_xc,_y-9,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 163 lcd.drawSprite(_xd,_y-12,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 164 lcd.drawSprite(_xe,_y-15,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 165 lcd.drawSprite(_xf,_y-18,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 166 lcd.drawSprite(_xg,_y-21,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 167 lcd.drawSprite(_xh,_y-24,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 168 lcd.drawSprite(_xi,_y-27,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 169 lcd.drawSprite(_xj,_y-30,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 170 lcd.drawSprite(_xk,_y-33,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 171 lcd.drawSprite(_xl,_y-36,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 172 }
AhmedPlaymaker 8:890b986b16a4 173 if(length == 14) {
AhmedPlaymaker 8:890b986b16a4 174 lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
AhmedPlaymaker 8:890b986b16a4 175 lcd.drawSprite(_xa,_y-3,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 176 lcd.drawSprite(_xb,_y-6,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 177 lcd.drawSprite(_xc,_y-9,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 178 lcd.drawSprite(_xd,_y-12,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 179 lcd.drawSprite(_xe,_y-15,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 180 lcd.drawSprite(_xf,_y-18,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 181 lcd.drawSprite(_xg,_y-21,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 182 lcd.drawSprite(_xh,_y-24,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 183 lcd.drawSprite(_xi,_y-27,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 184 lcd.drawSprite(_xj,_y-30,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 185 lcd.drawSprite(_xk,_y-33,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 186 lcd.drawSprite(_xl,_y-36,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 187 lcd.drawSprite(_xm,_y-39,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 188 }
AhmedPlaymaker 8:890b986b16a4 189 if(length == 15) {
AhmedPlaymaker 8:890b986b16a4 190 lcd.drawSprite(_x,_y,3,3,(int *)snake_sprite); //Function used to draw the sprite.
AhmedPlaymaker 8:890b986b16a4 191 lcd.drawSprite(_xa,_y-3,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 192 lcd.drawSprite(_xb,_y-6,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 193 lcd.drawSprite(_xc,_y-9,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 194 lcd.drawSprite(_xd,_y-12,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 195 lcd.drawSprite(_xe,_y-15,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 196 lcd.drawSprite(_xf,_y-18,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 197 lcd.drawSprite(_xg,_y-21,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 198 lcd.drawSprite(_xh,_y-24,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 199 lcd.drawSprite(_xi,_y-27,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 200 lcd.drawSprite(_xj,_y-30,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 201 lcd.drawSprite(_xk,_y-33,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 202 lcd.drawSprite(_xl,_y-36,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 203 lcd.drawSprite(_xm,_y-39,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 204 lcd.drawSprite(_xn,_y-42,3,3,(int *)snake_sprite);
AhmedPlaymaker 8:890b986b16a4 205 }
AhmedPlaymaker 7:48ba87cd79b5 206 }
AhmedPlaymaker 7:48ba87cd79b5 207
AhmedPlaymaker 7:48ba87cd79b5 208
AhmedPlaymaker 7:48ba87cd79b5 209
AhmedPlaymaker 9:d1d79d4ee673 210 Vector2D Snake::get_pos(int length)
AhmedPlaymaker 7:48ba87cd79b5 211 {
AhmedPlaymaker 9:d1d79d4ee673 212 if(length == 1) {
AhmedPlaymaker 9:d1d79d4ee673 213 Vector2D snakepos = {_x,_y}; //Obtains the snake position.
AhmedPlaymaker 9:d1d79d4ee673 214 return snakepos;
AhmedPlaymaker 9:d1d79d4ee673 215 }
AhmedPlaymaker 9:d1d79d4ee673 216
AhmedPlaymaker 9:d1d79d4ee673 217 else if(length == 2) {
AhmedPlaymaker 9:d1d79d4ee673 218 Vector2D snakepos = {_xa,(_y-3)}; //Obtains the snake position.
AhmedPlaymaker 9:d1d79d4ee673 219 return snakepos;
AhmedPlaymaker 9:d1d79d4ee673 220 }
AhmedPlaymaker 9:d1d79d4ee673 221 else if(length==3) {
AhmedPlaymaker 9:d1d79d4ee673 222 Vector2D snakepos = {_xb,(_y-6)}; //Obtains the snake position.
AhmedPlaymaker 9:d1d79d4ee673 223 return snakepos;
AhmedPlaymaker 9:d1d79d4ee673 224 }
AhmedPlaymaker 9:d1d79d4ee673 225 else if(length==4) {
AhmedPlaymaker 9:d1d79d4ee673 226 Vector2D snakepos = {_xc,(_y-9)}; //Obtains the snake position.
AhmedPlaymaker 9:d1d79d4ee673 227 return snakepos;
AhmedPlaymaker 9:d1d79d4ee673 228 }
AhmedPlaymaker 9:d1d79d4ee673 229 else if(length==5) {
AhmedPlaymaker 9:d1d79d4ee673 230 Vector2D snakepos = {_xd,(_y-12)}; //Obtains the snake position.
AhmedPlaymaker 9:d1d79d4ee673 231 return snakepos;
AhmedPlaymaker 9:d1d79d4ee673 232 }
AhmedPlaymaker 9:d1d79d4ee673 233 else if(length==6) {
AhmedPlaymaker 9:d1d79d4ee673 234 Vector2D snakepos = {_xe,(_y-15)}; //Obtains the snake position.
AhmedPlaymaker 9:d1d79d4ee673 235 return snakepos;
AhmedPlaymaker 9:d1d79d4ee673 236 }
AhmedPlaymaker 9:d1d79d4ee673 237 else if(length==7) {
AhmedPlaymaker 9:d1d79d4ee673 238 Vector2D snakepos = {_xf,(_y-18)}; //Obtains the snake position.
AhmedPlaymaker 9:d1d79d4ee673 239 return snakepos;
AhmedPlaymaker 9:d1d79d4ee673 240 }
AhmedPlaymaker 9:d1d79d4ee673 241 else if(length==8) {
AhmedPlaymaker 9:d1d79d4ee673 242 Vector2D snakepos = {_xg,(_y-21)}; //Obtains the snake position.
AhmedPlaymaker 9:d1d79d4ee673 243 return snakepos;
AhmedPlaymaker 9:d1d79d4ee673 244 }
AhmedPlaymaker 9:d1d79d4ee673 245 else if(length==9) {
AhmedPlaymaker 9:d1d79d4ee673 246 Vector2D snakepos = {_xh,(_y-24)}; //Obtains the snake position.
AhmedPlaymaker 9:d1d79d4ee673 247 return snakepos;
AhmedPlaymaker 9:d1d79d4ee673 248 }
AhmedPlaymaker 9:d1d79d4ee673 249 else if(length==10) {
AhmedPlaymaker 9:d1d79d4ee673 250 Vector2D snakepos = {_xi,(_y-27)}; //Obtains the snake position.
AhmedPlaymaker 9:d1d79d4ee673 251 return snakepos;
AhmedPlaymaker 9:d1d79d4ee673 252 }
AhmedPlaymaker 9:d1d79d4ee673 253 else if(length==11) {
AhmedPlaymaker 9:d1d79d4ee673 254 Vector2D snakepos = {_xj,(_y-30)}; //Obtains the snake position.
AhmedPlaymaker 9:d1d79d4ee673 255 return snakepos;
AhmedPlaymaker 9:d1d79d4ee673 256 }
AhmedPlaymaker 9:d1d79d4ee673 257 else if(length==12) {
AhmedPlaymaker 9:d1d79d4ee673 258 Vector2D snakepos = {_xk,(_y-33)}; //Obtains the snake position.
AhmedPlaymaker 9:d1d79d4ee673 259 return snakepos;
AhmedPlaymaker 9:d1d79d4ee673 260 }
AhmedPlaymaker 9:d1d79d4ee673 261 else if(length==13) {
AhmedPlaymaker 9:d1d79d4ee673 262 Vector2D snakepos = {_xl,(_y-36)}; //Obtains the snake position.
AhmedPlaymaker 9:d1d79d4ee673 263 return snakepos;
AhmedPlaymaker 9:d1d79d4ee673 264 }
AhmedPlaymaker 9:d1d79d4ee673 265 else if(length == 14) {
AhmedPlaymaker 9:d1d79d4ee673 266 Vector2D snakepos = {_xm,(_y-39)}; //Obtains the snake position.
AhmedPlaymaker 9:d1d79d4ee673 267 return snakepos;
AhmedPlaymaker 9:d1d79d4ee673 268 }
AhmedPlaymaker 9:d1d79d4ee673 269 else if(length==15) {
AhmedPlaymaker 9:d1d79d4ee673 270 Vector2D snakepos = {_xn,(_y-42)}; //Obtains the snake position.
AhmedPlaymaker 9:d1d79d4ee673 271 return snakepos;
AhmedPlaymaker 9:d1d79d4ee673 272 }
AhmedPlaymaker 7:48ba87cd79b5 273 //printf("snakepos from player = %f %f \n", snakepos.x, snakepos.y);
AhmedPlaymaker 9:d1d79d4ee673 274 return {0,0};
AhmedPlaymaker 7:48ba87cd79b5 275 }
AhmedPlaymaker 7:48ba87cd79b5 276
AhmedPlaymaker 7:48ba87cd79b5 277
AhmedPlaymaker 8:890b986b16a4 278 void Snake::update(Direction d,float mag,int length)
AhmedPlaymaker 7:48ba87cd79b5 279 {
AhmedPlaymaker 8:890b986b16a4 280 _speed = 1; //Speed changes depending on how much you push the joystick.(As Of Now)
AhmedPlaymaker 8:890b986b16a4 281
AhmedPlaymaker 8:890b986b16a4 282 if(length > 1) {
AhmedPlaymaker 8:890b986b16a4 283 if (_x > _xa) {
AhmedPlaymaker 8:890b986b16a4 284 _x-=_speed;
AhmedPlaymaker 8:890b986b16a4 285 }
AhmedPlaymaker 8:890b986b16a4 286 if (_x < _xa) {
AhmedPlaymaker 8:890b986b16a4 287 _x+=_speed;
AhmedPlaymaker 8:890b986b16a4 288 }
AhmedPlaymaker 8:890b986b16a4 289 if(length > 2) {
AhmedPlaymaker 8:890b986b16a4 290 if (_xa > _xb) {
AhmedPlaymaker 8:890b986b16a4 291 _xa-=_speed;
AhmedPlaymaker 8:890b986b16a4 292 }
AhmedPlaymaker 8:890b986b16a4 293 if (_xa < _xb) {
AhmedPlaymaker 8:890b986b16a4 294 _xa+=_speed;
AhmedPlaymaker 8:890b986b16a4 295 }
AhmedPlaymaker 8:890b986b16a4 296 if(length > 3) {
AhmedPlaymaker 8:890b986b16a4 297 if (_xb > _xc) {
AhmedPlaymaker 8:890b986b16a4 298 _xb-=_speed;
AhmedPlaymaker 8:890b986b16a4 299 }
AhmedPlaymaker 8:890b986b16a4 300 if (_xb < _xc) {
AhmedPlaymaker 8:890b986b16a4 301 _xb+=_speed;
AhmedPlaymaker 8:890b986b16a4 302 }
AhmedPlaymaker 8:890b986b16a4 303 if(length > 4) {
AhmedPlaymaker 8:890b986b16a4 304 if (_xc > _xd) {
AhmedPlaymaker 8:890b986b16a4 305 _xc-=_speed;
AhmedPlaymaker 8:890b986b16a4 306 }
AhmedPlaymaker 8:890b986b16a4 307 if (_xc < _xd) {
AhmedPlaymaker 8:890b986b16a4 308 _xc+=_speed;
AhmedPlaymaker 8:890b986b16a4 309 }
AhmedPlaymaker 8:890b986b16a4 310 if(length > 5) {
AhmedPlaymaker 8:890b986b16a4 311 if (_xd > _xe) {
AhmedPlaymaker 8:890b986b16a4 312 _xd-=_speed;
AhmedPlaymaker 8:890b986b16a4 313 }
AhmedPlaymaker 8:890b986b16a4 314 if (_xd < _xe) {
AhmedPlaymaker 8:890b986b16a4 315 _xd+=_speed;
AhmedPlaymaker 8:890b986b16a4 316 }
AhmedPlaymaker 8:890b986b16a4 317 if(length > 6) {
AhmedPlaymaker 8:890b986b16a4 318 if (_xe > _xf) {
AhmedPlaymaker 8:890b986b16a4 319 _xe-=_speed;
AhmedPlaymaker 8:890b986b16a4 320 }
AhmedPlaymaker 8:890b986b16a4 321 if (_xe < _xf) {
AhmedPlaymaker 8:890b986b16a4 322 _xe+=_speed;
AhmedPlaymaker 8:890b986b16a4 323 }
AhmedPlaymaker 8:890b986b16a4 324 if(length > 7) {
AhmedPlaymaker 8:890b986b16a4 325 if (_xf > _xg) {
AhmedPlaymaker 8:890b986b16a4 326 _xf-=_speed;
AhmedPlaymaker 8:890b986b16a4 327 }
AhmedPlaymaker 8:890b986b16a4 328 if (_xf < _xg) {
AhmedPlaymaker 8:890b986b16a4 329 _xf+=_speed;
AhmedPlaymaker 8:890b986b16a4 330 }
AhmedPlaymaker 8:890b986b16a4 331 if(length > 8) {
AhmedPlaymaker 8:890b986b16a4 332 if (_xg > _xh) {
AhmedPlaymaker 8:890b986b16a4 333 _xg-=_speed;
AhmedPlaymaker 8:890b986b16a4 334 }
AhmedPlaymaker 8:890b986b16a4 335 if (_xg < _xh) {
AhmedPlaymaker 8:890b986b16a4 336 _xg+=_speed;
AhmedPlaymaker 8:890b986b16a4 337 }
AhmedPlaymaker 8:890b986b16a4 338 if(length > 9) {
AhmedPlaymaker 8:890b986b16a4 339 if (_xh > _xi) {
AhmedPlaymaker 8:890b986b16a4 340 _xh-=_speed;
AhmedPlaymaker 8:890b986b16a4 341 }
AhmedPlaymaker 8:890b986b16a4 342 if (_xh < _xi) {
AhmedPlaymaker 8:890b986b16a4 343 _xh+=_speed;
AhmedPlaymaker 8:890b986b16a4 344 }
AhmedPlaymaker 8:890b986b16a4 345 if(length > 10) {
AhmedPlaymaker 8:890b986b16a4 346 if (_xi > _xj) {
AhmedPlaymaker 8:890b986b16a4 347 _xi-=_speed;
AhmedPlaymaker 8:890b986b16a4 348 }
AhmedPlaymaker 8:890b986b16a4 349 if (_xi < _xj) {
AhmedPlaymaker 8:890b986b16a4 350 _xi+=_speed;
AhmedPlaymaker 8:890b986b16a4 351 }
AhmedPlaymaker 8:890b986b16a4 352 if(length > 11) {
AhmedPlaymaker 8:890b986b16a4 353 if (_xj > _xk) {
AhmedPlaymaker 8:890b986b16a4 354 _xj-=_speed;
AhmedPlaymaker 8:890b986b16a4 355 }
AhmedPlaymaker 8:890b986b16a4 356 if (_xj < _xk) {
AhmedPlaymaker 8:890b986b16a4 357 _xj+=_speed;
AhmedPlaymaker 8:890b986b16a4 358 }
AhmedPlaymaker 8:890b986b16a4 359 if(length > 12) {
AhmedPlaymaker 8:890b986b16a4 360 if (_xk > _xl) {
AhmedPlaymaker 8:890b986b16a4 361 _xk-=_speed;
AhmedPlaymaker 8:890b986b16a4 362 }
AhmedPlaymaker 8:890b986b16a4 363 if (_xk < _xl) {
AhmedPlaymaker 8:890b986b16a4 364 _xk+=_speed;
AhmedPlaymaker 8:890b986b16a4 365 }
AhmedPlaymaker 8:890b986b16a4 366 if(length > 13) {
AhmedPlaymaker 8:890b986b16a4 367 if (_xl > _xm) {
AhmedPlaymaker 8:890b986b16a4 368 _xl-=_speed;
AhmedPlaymaker 8:890b986b16a4 369 }
AhmedPlaymaker 8:890b986b16a4 370 if (_xl < _xm) {
AhmedPlaymaker 8:890b986b16a4 371 _xl+=_speed;
AhmedPlaymaker 8:890b986b16a4 372 }
AhmedPlaymaker 8:890b986b16a4 373 if(length > 14) {
AhmedPlaymaker 8:890b986b16a4 374 if (_xm > _xn) {
AhmedPlaymaker 8:890b986b16a4 375 _xm-=_speed;
AhmedPlaymaker 8:890b986b16a4 376 }
AhmedPlaymaker 8:890b986b16a4 377 if (_xm < _xn) {
AhmedPlaymaker 8:890b986b16a4 378 _xm+=_speed;
AhmedPlaymaker 8:890b986b16a4 379 }
AhmedPlaymaker 8:890b986b16a4 380 }
AhmedPlaymaker 8:890b986b16a4 381 }
AhmedPlaymaker 8:890b986b16a4 382 }
AhmedPlaymaker 8:890b986b16a4 383 }
AhmedPlaymaker 8:890b986b16a4 384 }
AhmedPlaymaker 8:890b986b16a4 385 }
AhmedPlaymaker 8:890b986b16a4 386 }
AhmedPlaymaker 8:890b986b16a4 387 }
AhmedPlaymaker 8:890b986b16a4 388 }
AhmedPlaymaker 8:890b986b16a4 389 }
AhmedPlaymaker 8:890b986b16a4 390 }
AhmedPlaymaker 8:890b986b16a4 391 }
AhmedPlaymaker 8:890b986b16a4 392 }
AhmedPlaymaker 8:890b986b16a4 393 }
AhmedPlaymaker 7:48ba87cd79b5 394
AhmedPlaymaker 7:48ba87cd79b5 395 // Diagonal speeds are /2 to prevent player from going double the speed.
AhmedPlaymaker 8:890b986b16a4 396 if(length == 15) {
AhmedPlaymaker 8:890b986b16a4 397 if (d == E) {
AhmedPlaymaker 8:890b986b16a4 398 _xn+= _speed;
AhmedPlaymaker 8:890b986b16a4 399 }
AhmedPlaymaker 8:890b986b16a4 400 if (d == W) {
AhmedPlaymaker 8:890b986b16a4 401 _xn-= _speed;
AhmedPlaymaker 8:890b986b16a4 402 }
AhmedPlaymaker 8:890b986b16a4 403 }
AhmedPlaymaker 8:890b986b16a4 404 if(length == 14) {
AhmedPlaymaker 8:890b986b16a4 405 if (d == E) {
AhmedPlaymaker 8:890b986b16a4 406 _xm+= _speed;
AhmedPlaymaker 8:890b986b16a4 407 }
AhmedPlaymaker 8:890b986b16a4 408 if (d == W) {
AhmedPlaymaker 8:890b986b16a4 409 _xm-= _speed;
AhmedPlaymaker 8:890b986b16a4 410 }
AhmedPlaymaker 8:890b986b16a4 411 }
AhmedPlaymaker 8:890b986b16a4 412 if(length == 13) {
AhmedPlaymaker 8:890b986b16a4 413 if (d == E) {
AhmedPlaymaker 8:890b986b16a4 414 _xl+= _speed;
AhmedPlaymaker 8:890b986b16a4 415 }
AhmedPlaymaker 8:890b986b16a4 416 if (d == W) {
AhmedPlaymaker 8:890b986b16a4 417 _xl-= _speed;
AhmedPlaymaker 8:890b986b16a4 418 }
AhmedPlaymaker 8:890b986b16a4 419 }
AhmedPlaymaker 8:890b986b16a4 420 if(length == 12) {
AhmedPlaymaker 8:890b986b16a4 421 if (d == E) {
AhmedPlaymaker 8:890b986b16a4 422 _xk+= _speed;
AhmedPlaymaker 8:890b986b16a4 423 }
AhmedPlaymaker 8:890b986b16a4 424 if (d == W) {
AhmedPlaymaker 8:890b986b16a4 425 _xk-= _speed;
AhmedPlaymaker 8:890b986b16a4 426 }
AhmedPlaymaker 8:890b986b16a4 427 }
AhmedPlaymaker 8:890b986b16a4 428 if(length == 11) {
AhmedPlaymaker 8:890b986b16a4 429 if (d == E) {
AhmedPlaymaker 8:890b986b16a4 430 _xj+= _speed;
AhmedPlaymaker 8:890b986b16a4 431 }
AhmedPlaymaker 8:890b986b16a4 432 if (d == W) {
AhmedPlaymaker 8:890b986b16a4 433 _xj-= _speed;
AhmedPlaymaker 8:890b986b16a4 434 }
AhmedPlaymaker 8:890b986b16a4 435 }
AhmedPlaymaker 8:890b986b16a4 436 if(length == 10) {
AhmedPlaymaker 8:890b986b16a4 437 if (d == E) {
AhmedPlaymaker 8:890b986b16a4 438 _xi+= _speed;
AhmedPlaymaker 8:890b986b16a4 439 }
AhmedPlaymaker 8:890b986b16a4 440 if (d == W) {
AhmedPlaymaker 8:890b986b16a4 441 _xi-= _speed;
AhmedPlaymaker 8:890b986b16a4 442 }
AhmedPlaymaker 8:890b986b16a4 443 }
AhmedPlaymaker 8:890b986b16a4 444 if(length == 9) {
AhmedPlaymaker 8:890b986b16a4 445 if (d == E) {
AhmedPlaymaker 8:890b986b16a4 446 _xh+= _speed;
AhmedPlaymaker 8:890b986b16a4 447 }
AhmedPlaymaker 8:890b986b16a4 448 if (d == W) {
AhmedPlaymaker 8:890b986b16a4 449 _xh-= _speed;
AhmedPlaymaker 8:890b986b16a4 450 }
AhmedPlaymaker 7:48ba87cd79b5 451 }
AhmedPlaymaker 8:890b986b16a4 452 if(length == 8) {
AhmedPlaymaker 8:890b986b16a4 453 if (d == E) {
AhmedPlaymaker 8:890b986b16a4 454 _xg+= _speed;
AhmedPlaymaker 8:890b986b16a4 455 }
AhmedPlaymaker 8:890b986b16a4 456 if (d == W) {
AhmedPlaymaker 8:890b986b16a4 457 _xg-= _speed;
AhmedPlaymaker 8:890b986b16a4 458 }
AhmedPlaymaker 8:890b986b16a4 459 }
AhmedPlaymaker 8:890b986b16a4 460 if(length == 7) {
AhmedPlaymaker 8:890b986b16a4 461 if (d == E) {
AhmedPlaymaker 8:890b986b16a4 462 _xf+= _speed;
AhmedPlaymaker 8:890b986b16a4 463 }
AhmedPlaymaker 8:890b986b16a4 464 if (d == W) {
AhmedPlaymaker 8:890b986b16a4 465 _xf-= _speed;
AhmedPlaymaker 8:890b986b16a4 466 }
AhmedPlaymaker 8:890b986b16a4 467 }
AhmedPlaymaker 8:890b986b16a4 468 if(length == 6) {
AhmedPlaymaker 8:890b986b16a4 469 if (d == E) {
AhmedPlaymaker 8:890b986b16a4 470 _xe+= _speed;
AhmedPlaymaker 8:890b986b16a4 471 }
AhmedPlaymaker 8:890b986b16a4 472 if (d == W) {
AhmedPlaymaker 8:890b986b16a4 473 _xe-= _speed;
AhmedPlaymaker 8:890b986b16a4 474 }
AhmedPlaymaker 8:890b986b16a4 475 }
AhmedPlaymaker 8:890b986b16a4 476 if(length == 5) {
AhmedPlaymaker 8:890b986b16a4 477 if (d == E) {
AhmedPlaymaker 8:890b986b16a4 478 _xd+= _speed;
AhmedPlaymaker 8:890b986b16a4 479 }
AhmedPlaymaker 8:890b986b16a4 480 if (d == W) {
AhmedPlaymaker 8:890b986b16a4 481 _xd-= _speed;
AhmedPlaymaker 8:890b986b16a4 482 }
AhmedPlaymaker 8:890b986b16a4 483 }
AhmedPlaymaker 8:890b986b16a4 484 if(length == 4) {
AhmedPlaymaker 8:890b986b16a4 485 if (d == E) {
AhmedPlaymaker 8:890b986b16a4 486 _xc+= _speed;
AhmedPlaymaker 8:890b986b16a4 487 }
AhmedPlaymaker 8:890b986b16a4 488 if (d == W) {
AhmedPlaymaker 8:890b986b16a4 489 _xc-= _speed;
AhmedPlaymaker 8:890b986b16a4 490 }
AhmedPlaymaker 8:890b986b16a4 491 }
AhmedPlaymaker 8:890b986b16a4 492 if(length == 3) {
AhmedPlaymaker 8:890b986b16a4 493 if (d == E) {
AhmedPlaymaker 8:890b986b16a4 494 _xb+= _speed;
AhmedPlaymaker 8:890b986b16a4 495 }
AhmedPlaymaker 8:890b986b16a4 496 if (d == W) {
AhmedPlaymaker 8:890b986b16a4 497 _xb-= _speed;
AhmedPlaymaker 8:890b986b16a4 498 }
AhmedPlaymaker 8:890b986b16a4 499 }
AhmedPlaymaker 8:890b986b16a4 500 if(length == 2) {
AhmedPlaymaker 8:890b986b16a4 501 if (d == E) {
AhmedPlaymaker 8:890b986b16a4 502 _xa+= _speed;
AhmedPlaymaker 8:890b986b16a4 503 }
AhmedPlaymaker 8:890b986b16a4 504 if (d == W) {
AhmedPlaymaker 8:890b986b16a4 505 _xa-= _speed;
AhmedPlaymaker 8:890b986b16a4 506 }
AhmedPlaymaker 8:890b986b16a4 507 }
AhmedPlaymaker 8:890b986b16a4 508 if(length == 1) {
AhmedPlaymaker 8:890b986b16a4 509 if (d == E) {
AhmedPlaymaker 8:890b986b16a4 510 _x+= _speed;
AhmedPlaymaker 8:890b986b16a4 511 }
AhmedPlaymaker 8:890b986b16a4 512 if (d == W) {
AhmedPlaymaker 8:890b986b16a4 513 _x-= _speed;
AhmedPlaymaker 8:890b986b16a4 514 }
AhmedPlaymaker 7:48ba87cd79b5 515 }
AhmedPlaymaker 7:48ba87cd79b5 516
AhmedPlaymaker 9:d1d79d4ee673 517 // the following makes sure that when the length is increased, the snake stays where it was when it ate food.
AhmedPlaymaker 7:48ba87cd79b5 518
AhmedPlaymaker 9:d1d79d4ee673 519 if(length < 2) {
AhmedPlaymaker 9:d1d79d4ee673 520 _xa = _x;
AhmedPlaymaker 9:d1d79d4ee673 521 }
AhmedPlaymaker 9:d1d79d4ee673 522 else if(length < 3) {
AhmedPlaymaker 9:d1d79d4ee673 523 _xb = _xa;
AhmedPlaymaker 9:d1d79d4ee673 524 }
AhmedPlaymaker 9:d1d79d4ee673 525 else if(length < 4) {
AhmedPlaymaker 9:d1d79d4ee673 526 _xc = _xb;
AhmedPlaymaker 9:d1d79d4ee673 527 }
AhmedPlaymaker 9:d1d79d4ee673 528 else if(length < 5) {
AhmedPlaymaker 9:d1d79d4ee673 529 _xd = _xc;
AhmedPlaymaker 9:d1d79d4ee673 530 }
AhmedPlaymaker 9:d1d79d4ee673 531 else if(length < 6) {
AhmedPlaymaker 9:d1d79d4ee673 532 _xe = _xd;
AhmedPlaymaker 9:d1d79d4ee673 533 }
AhmedPlaymaker 9:d1d79d4ee673 534 else if(length < 7) {
AhmedPlaymaker 9:d1d79d4ee673 535 _xf = _xe;
AhmedPlaymaker 9:d1d79d4ee673 536 }
AhmedPlaymaker 9:d1d79d4ee673 537 else if(length < 8) {
AhmedPlaymaker 9:d1d79d4ee673 538 _xg = _xf;
AhmedPlaymaker 9:d1d79d4ee673 539 }
AhmedPlaymaker 9:d1d79d4ee673 540 else if(length < 9) {
AhmedPlaymaker 9:d1d79d4ee673 541 _xh = _xg;
AhmedPlaymaker 9:d1d79d4ee673 542 }
AhmedPlaymaker 9:d1d79d4ee673 543 else if(length < 10) {
AhmedPlaymaker 9:d1d79d4ee673 544 _xi = _xh;
AhmedPlaymaker 9:d1d79d4ee673 545 }
AhmedPlaymaker 9:d1d79d4ee673 546 else if(length < 11) {
AhmedPlaymaker 9:d1d79d4ee673 547 _xj = _xi;
AhmedPlaymaker 9:d1d79d4ee673 548 }
AhmedPlaymaker 9:d1d79d4ee673 549 else if(length < 12) {
AhmedPlaymaker 9:d1d79d4ee673 550 _xk = _xj;
AhmedPlaymaker 9:d1d79d4ee673 551 }
AhmedPlaymaker 9:d1d79d4ee673 552 else if(length < 13) {
AhmedPlaymaker 9:d1d79d4ee673 553 _xl = _xk;
AhmedPlaymaker 9:d1d79d4ee673 554 }
AhmedPlaymaker 9:d1d79d4ee673 555 else if(length < 14) {
AhmedPlaymaker 9:d1d79d4ee673 556 _xm = _xl;
AhmedPlaymaker 9:d1d79d4ee673 557 }
AhmedPlaymaker 9:d1d79d4ee673 558 else if(length < 15) {
AhmedPlaymaker 9:d1d79d4ee673 559 _xn = _xm;
AhmedPlaymaker 9:d1d79d4ee673 560 }
AhmedPlaymaker 9:d1d79d4ee673 561
AhmedPlaymaker 7:48ba87cd79b5 562 //Limits set so that the sprite does not travel off the screen.
AhmedPlaymaker 7:48ba87cd79b5 563 if (_y <= 0) {
AhmedPlaymaker 7:48ba87cd79b5 564 _y = 0;
AhmedPlaymaker 7:48ba87cd79b5 565 }
AhmedPlaymaker 7:48ba87cd79b5 566 if (_x <= 0) {
AhmedPlaymaker 7:48ba87cd79b5 567 _x = 0;
AhmedPlaymaker 7:48ba87cd79b5 568 }
AhmedPlaymaker 8:890b986b16a4 569 if (_xa <= 0) {
AhmedPlaymaker 8:890b986b16a4 570 _xa = 0;
AhmedPlaymaker 8:890b986b16a4 571 }
AhmedPlaymaker 8:890b986b16a4 572 if (_xb <= 0) {
AhmedPlaymaker 8:890b986b16a4 573 _xb = 0;
AhmedPlaymaker 8:890b986b16a4 574 }
AhmedPlaymaker 8:890b986b16a4 575 if (_xc <= 0) {
AhmedPlaymaker 8:890b986b16a4 576 _xc = 0;
AhmedPlaymaker 8:890b986b16a4 577 }
AhmedPlaymaker 8:890b986b16a4 578 if (_xd <= 0) {
AhmedPlaymaker 8:890b986b16a4 579 _xd = 0;
AhmedPlaymaker 8:890b986b16a4 580 }
AhmedPlaymaker 8:890b986b16a4 581 if (_xe <= 0) {
AhmedPlaymaker 8:890b986b16a4 582 _xe = 0;
AhmedPlaymaker 8:890b986b16a4 583 }
AhmedPlaymaker 8:890b986b16a4 584 if (_xf <= 0) {
AhmedPlaymaker 8:890b986b16a4 585 _xf = 0;
AhmedPlaymaker 8:890b986b16a4 586 }
AhmedPlaymaker 8:890b986b16a4 587 if (_xg <= 0) {
AhmedPlaymaker 8:890b986b16a4 588 _xg = 0;
AhmedPlaymaker 8:890b986b16a4 589 }
AhmedPlaymaker 8:890b986b16a4 590 if (_xh <= 0) {
AhmedPlaymaker 8:890b986b16a4 591 _xh = 0;
AhmedPlaymaker 8:890b986b16a4 592 }
AhmedPlaymaker 8:890b986b16a4 593 if (_xi <= 0) {
AhmedPlaymaker 8:890b986b16a4 594 _xi = 0;
AhmedPlaymaker 8:890b986b16a4 595 }
AhmedPlaymaker 8:890b986b16a4 596 if (_xj <= 0) {
AhmedPlaymaker 8:890b986b16a4 597 _xj = 0;
AhmedPlaymaker 8:890b986b16a4 598 }
AhmedPlaymaker 8:890b986b16a4 599 if (_xk <= 0) {
AhmedPlaymaker 8:890b986b16a4 600 _xk = 0;
AhmedPlaymaker 8:890b986b16a4 601 }
AhmedPlaymaker 8:890b986b16a4 602 if (_xl <= 0) {
AhmedPlaymaker 8:890b986b16a4 603 _xl = 0;
AhmedPlaymaker 8:890b986b16a4 604 }
AhmedPlaymaker 8:890b986b16a4 605 if (_xm <= 0) {
AhmedPlaymaker 8:890b986b16a4 606 _xm = 0;
AhmedPlaymaker 8:890b986b16a4 607 }
AhmedPlaymaker 8:890b986b16a4 608 if (_xn <= 0) {
AhmedPlaymaker 8:890b986b16a4 609 _xn = 0;
AhmedPlaymaker 7:48ba87cd79b5 610 }
AhmedPlaymaker 8:890b986b16a4 611 if (_x > 81) {
AhmedPlaymaker 8:890b986b16a4 612 _x = 81;
AhmedPlaymaker 8:890b986b16a4 613 }
AhmedPlaymaker 8:890b986b16a4 614 if (_xa > 81) {
AhmedPlaymaker 8:890b986b16a4 615 _xa = 81;
AhmedPlaymaker 8:890b986b16a4 616 }
AhmedPlaymaker 8:890b986b16a4 617 if (_xb > 81) {
AhmedPlaymaker 8:890b986b16a4 618 _xb = 81;
AhmedPlaymaker 8:890b986b16a4 619 }
AhmedPlaymaker 8:890b986b16a4 620 if (_xc > 81) {
AhmedPlaymaker 8:890b986b16a4 621 _xc = 81;
AhmedPlaymaker 8:890b986b16a4 622 }
AhmedPlaymaker 8:890b986b16a4 623 if (_xd > 81) {
AhmedPlaymaker 8:890b986b16a4 624 _xd = 81;
AhmedPlaymaker 8:890b986b16a4 625 }
AhmedPlaymaker 8:890b986b16a4 626 if (_xe > 81) {
AhmedPlaymaker 8:890b986b16a4 627 _xe = 81;
AhmedPlaymaker 8:890b986b16a4 628 }
AhmedPlaymaker 8:890b986b16a4 629 if (_xf > 81) {
AhmedPlaymaker 8:890b986b16a4 630 _xf = 81;
AhmedPlaymaker 7:48ba87cd79b5 631 }
AhmedPlaymaker 8:890b986b16a4 632 if (_xg > 81) {
AhmedPlaymaker 8:890b986b16a4 633 _xg = 81;
AhmedPlaymaker 8:890b986b16a4 634 }
AhmedPlaymaker 8:890b986b16a4 635 if (_xh > 81) {
AhmedPlaymaker 8:890b986b16a4 636 _xh = 81;
AhmedPlaymaker 8:890b986b16a4 637 }
AhmedPlaymaker 8:890b986b16a4 638 if (_xi > 81) {
AhmedPlaymaker 8:890b986b16a4 639 _xi = 81;
AhmedPlaymaker 8:890b986b16a4 640 }
AhmedPlaymaker 8:890b986b16a4 641 if (_xj > 81) {
AhmedPlaymaker 8:890b986b16a4 642 _xj = 81;
AhmedPlaymaker 8:890b986b16a4 643 }
AhmedPlaymaker 8:890b986b16a4 644 if (_xk > 81) {
AhmedPlaymaker 8:890b986b16a4 645 _xk = 81;
AhmedPlaymaker 8:890b986b16a4 646 }
AhmedPlaymaker 8:890b986b16a4 647 if (_xl > 81) {
AhmedPlaymaker 8:890b986b16a4 648 _xl = 81;
AhmedPlaymaker 8:890b986b16a4 649 }
AhmedPlaymaker 8:890b986b16a4 650 if (_xm > 81) {
AhmedPlaymaker 8:890b986b16a4 651 _xm = 81;
AhmedPlaymaker 8:890b986b16a4 652 }
AhmedPlaymaker 8:890b986b16a4 653 if (_xn > 81) {
AhmedPlaymaker 8:890b986b16a4 654 _xn = 81;
AhmedPlaymaker 8:890b986b16a4 655 }
AhmedPlaymaker 7:48ba87cd79b5 656 }
AhmedPlaymaker 7:48ba87cd79b5 657