Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Committer:
AhmedPlaymaker
Date:
Sun Apr 14 10:24:59 2019 +0000
Revision:
29:c6358c39a70e
Parent:
28:d2c621d67e3b
Child:
32:3a3bdeffdf62
Minor performance improvements, Start screen class needs to be re organized

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AhmedPlaymaker 7:48ba87cd79b5 1 #include "SnakevsBlock.h"
AhmedPlaymaker 7:48ba87cd79b5 2
AhmedPlaymaker 7:48ba87cd79b5 3 SnakevsBlock::SnakevsBlock()
AhmedPlaymaker 7:48ba87cd79b5 4 {
AhmedPlaymaker 7:48ba87cd79b5 5
AhmedPlaymaker 7:48ba87cd79b5 6 }
AhmedPlaymaker 7:48ba87cd79b5 7
AhmedPlaymaker 7:48ba87cd79b5 8 SnakevsBlock::~SnakevsBlock()
AhmedPlaymaker 7:48ba87cd79b5 9 {
AhmedPlaymaker 7:48ba87cd79b5 10
AhmedPlaymaker 7:48ba87cd79b5 11 }
AhmedPlaymaker 7:48ba87cd79b5 12
AhmedPlaymaker 7:48ba87cd79b5 13 void SnakevsBlock::init()
AhmedPlaymaker 7:48ba87cd79b5 14 {
AhmedPlaymaker 7:48ba87cd79b5 15 //The snake length configuration and all the other initial information passing will be done here
AhmedPlaymaker 12:1e601b176437 16 length = 3;
AhmedPlaymaker 19:05cc9f801468 17 level = 1;
AhmedPlaymaker 12:1e601b176437 18 foodbuff = 0;
AhmedPlaymaker 12:1e601b176437 19 send=0;
AhmedPlaymaker 13:9785f2404045 20 speed = 1;
AhmedPlaymaker 20:1e6338403427 21 blockgap = 500;
AhmedPlaymaker 19:05cc9f801468 22 blockbuff = 0;
AhmedPlaymaker 22:ee698f66146f 23 for(int i=0; i<=14; i++) {
AhmedPlaymaker 22:ee698f66146f 24 b[i] = 1;
AhmedPlaymaker 22:ee698f66146f 25 }
AhmedPlaymaker 25:e827f1a8fadc 26 _s.init();
AhmedPlaymaker 25:e827f1a8fadc 27 _f.init();
AhmedPlaymaker 25:e827f1a8fadc 28 _ff.init();
AhmedPlaymaker 25:e827f1a8fadc 29 _fff.init();
AhmedPlaymaker 25:e827f1a8fadc 30 _b.init();
AhmedPlaymaker 7:48ba87cd79b5 31 }
AhmedPlaymaker 7:48ba87cd79b5 32
AhmedPlaymaker 7:48ba87cd79b5 33
AhmedPlaymaker 7:48ba87cd79b5 34
AhmedPlaymaker 7:48ba87cd79b5 35 void SnakevsBlock::read_input(Gamepad &pad)
AhmedPlaymaker 7:48ba87cd79b5 36 {
AhmedPlaymaker 7:48ba87cd79b5 37 _d = pad.get_direction(); //Obtains Direction pushed towards on Joystick.
AhmedPlaymaker 7:48ba87cd79b5 38 _mag = pad.get_mag(); //Obtains Magnitude of Joystick.
AhmedPlaymaker 7:48ba87cd79b5 39 }
AhmedPlaymaker 7:48ba87cd79b5 40
AhmedPlaymaker 27:3b4775a0d0bb 41 void SnakevsBlock::draw(N5110 &lcd, Gamepad &pad) {
AhmedPlaymaker 20:1e6338403427 42 length = _s.draw(pad, lcd, length, level); //Draws the Snake. //Make these snake buffs relative to the snake drops which in turn relate to the game speed
AhmedPlaymaker 9:d1d79d4ee673 43 if(foodbuff >=0) {
AhmedPlaymaker 25:e827f1a8fadc 44 _f.draw(lcd, blockgap, blockbuff); //Draws the first food.
AhmedPlaymaker 9:d1d79d4ee673 45 if(foodbuff >=50) {
AhmedPlaymaker 25:e827f1a8fadc 46 _ff.draw(lcd, blockgap, blockbuff); //Draws the second food.
AhmedPlaymaker 9:d1d79d4ee673 47 if(foodbuff >=80) {
AhmedPlaymaker 25:e827f1a8fadc 48 _fff.draw(lcd, blockgap, blockbuff); //Draws the third food.
AhmedPlaymaker 9:d1d79d4ee673 49 }
AhmedPlaymaker 9:d1d79d4ee673 50 }
AhmedPlaymaker 9:d1d79d4ee673 51 foodbuff +=1;
AhmedPlaymaker 9:d1d79d4ee673 52 }
AhmedPlaymaker 16:7b474f873683 53 if(foodbuff >=8) {
AhmedPlaymaker 19:05cc9f801468 54 send = _b.draw(lcd, length, blocknum, srn, blockgap);
AhmedPlaymaker 19:05cc9f801468 55 }
AhmedPlaymaker 19:05cc9f801468 56 if(foodbuff == 8) {
AhmedPlaymaker 19:05cc9f801468 57 blockbuff = 0;
AhmedPlaymaker 13:9785f2404045 58 }
AhmedPlaymaker 7:48ba87cd79b5 59 //Code to print length on game screen.
AhmedPlaymaker 7:48ba87cd79b5 60 char bufferscore[14];
AhmedPlaymaker 7:48ba87cd79b5 61 sprintf(bufferscore,"%d",length);
AhmedPlaymaker 25:e827f1a8fadc 62 lcd.printString(bufferscore,1,0);
AhmedPlaymaker 7:48ba87cd79b5 63 }
AhmedPlaymaker 7:48ba87cd79b5 64
AhmedPlaymaker 7:48ba87cd79b5 65
AhmedPlaymaker 25:e827f1a8fadc 66 int SnakevsBlock::update(Gamepad &pad) //Updates objects on screen.
AhmedPlaymaker 7:48ba87cd79b5 67 {
AhmedPlaymaker 18:b391caa5754c 68 CheckSnakeBlockCollision(pad); //Function checks for when the snake collides with any of the blocks.
AhmedPlaymaker 12:1e601b176437 69 CheckSnakeFoodCollision(pad); //Function checks for when the snake collides with it's food.
AhmedPlaymaker 13:9785f2404045 70 CheckSnakeBlockSidesCollision(pad, _d); //Function checks for when the snake collides with any of the blocks' sides.
AhmedPlaymaker 22:ee698f66146f 71 _s.update(_d,_mag, length, speed, b); //_d is the direction of joystick and b controls thew motion of a section of the snake relative to obstruction
AhmedPlaymaker 9:d1d79d4ee673 72 _f.update();
AhmedPlaymaker 9:d1d79d4ee673 73 _ff.update();
AhmedPlaymaker 9:d1d79d4ee673 74 _fff.update();
AhmedPlaymaker 12:1e601b176437 75 _b.update(blocknum, srn, send);
AhmedPlaymaker 19:05cc9f801468 76 blockbuff++;
AhmedPlaymaker 19:05cc9f801468 77 if(blockbuff == blockgap) { //change this while changing the block drop gap
AhmedPlaymaker 19:05cc9f801468 78 blockbuff = 0;
AhmedPlaymaker 19:05cc9f801468 79 }
AhmedPlaymaker 21:e41126528cc6 80 if(length >= 11) { //to make it easier to react to sudden happenings
AhmedPlaymaker 20:1e6338403427 81 speed = 2;
AhmedPlaymaker 20:1e6338403427 82 }
AhmedPlaymaker 20:1e6338403427 83 else {
AhmedPlaymaker 20:1e6338403427 84 speed = 1;
AhmedPlaymaker 20:1e6338403427 85 }
AhmedPlaymaker 21:e41126528cc6 86 if(length > 15) { //to make progressive levels harder
AhmedPlaymaker 20:1e6338403427 87 blockgap -= 20;
AhmedPlaymaker 19:05cc9f801468 88 level += 1;
AhmedPlaymaker 16:7b474f873683 89 }
AhmedPlaymaker 25:e827f1a8fadc 90 if(pad.check_event(Gamepad::BACK_PRESSED)){ //Waits for Back button to be pressed.
AhmedPlaymaker 25:e827f1a8fadc 91 back = 1;
AhmedPlaymaker 25:e827f1a8fadc 92 //add some warning here and use A as the button to confirm
AhmedPlaymaker 25:e827f1a8fadc 93 SnakevsBlock::init();
AhmedPlaymaker 25:e827f1a8fadc 94 }
AhmedPlaymaker 25:e827f1a8fadc 95 else {
AhmedPlaymaker 25:e827f1a8fadc 96 back = 0;
AhmedPlaymaker 25:e827f1a8fadc 97 }
AhmedPlaymaker 25:e827f1a8fadc 98 return back;
AhmedPlaymaker 7:48ba87cd79b5 99 }
AhmedPlaymaker 7:48ba87cd79b5 100
AhmedPlaymaker 7:48ba87cd79b5 101 void SnakevsBlock::get_pos()
AhmedPlaymaker 7:48ba87cd79b5 102 {
AhmedPlaymaker 9:d1d79d4ee673 103 Vector2D snake_pos = _s.get_pos(length);
AhmedPlaymaker 7:48ba87cd79b5 104 //printf("player pos = %f %f \n", player_pos.x, player_pos.y); //top left of player sprite
AhmedPlaymaker 7:48ba87cd79b5 105 // 81.000000 0.000000 top right
AhmedPlaymaker 7:48ba87cd79b5 106 // 0.000000 0.000000 is top left
AhmedPlaymaker 7:48ba87cd79b5 107 // 81.000000 45.000000 bottom right
AhmedPlaymaker 7:48ba87cd79b5 108 snakex = snake_pos.x;
AhmedPlaymaker 7:48ba87cd79b5 109 snakey = snake_pos.y;
AhmedPlaymaker 7:48ba87cd79b5 110 //printf("snakexy in GAME = %d %d \n", snakex, snakey);
AhmedPlaymaker 7:48ba87cd79b5 111 }
AhmedPlaymaker 7:48ba87cd79b5 112
AhmedPlaymaker 9:d1d79d4ee673 113
AhmedPlaymaker 27:3b4775a0d0bb 114 void SnakevsBlock::CheckSnakeFoodCollision(Gamepad &pad) {
AhmedPlaymaker 9:d1d79d4ee673 115 //Obtains all required coordinates.
AhmedPlaymaker 29:c6358c39a70e 116 Vector2D food_pos[3];
AhmedPlaymaker 29:c6358c39a70e 117 food_pos[0] = _f.get_pos();
AhmedPlaymaker 29:c6358c39a70e 118 food_pos[1] = _ff.get_pos();
AhmedPlaymaker 29:c6358c39a70e 119 food_pos[2] = _fff.get_pos();
AhmedPlaymaker 9:d1d79d4ee673 120 Vector2D snake_pos = _s.get_pos(length);
AhmedPlaymaker 9:d1d79d4ee673 121 //If statements check if the snake sprite has collided with any
AhmedPlaymaker 9:d1d79d4ee673 122 //of the three food sprites, if so then the food location is reset and
AhmedPlaymaker 9:d1d79d4ee673 123 //length of the snake is increased using the length variable.
AhmedPlaymaker 29:c6358c39a70e 124 for(int y=0; y<=2; y++) { //this loop automatically detects each combination of collision in the y postion
AhmedPlaymaker 29:c6358c39a70e 125 for(int x=0; x<=2; x++) { //this loop automatically detects each combination of collision in the x postion
AhmedPlaymaker 29:c6358c39a70e 126 for(int food_sr=0; food_sr<=2; food_sr++) { //this loop automatically detects which food we are interacting with.
AhmedPlaymaker 29:c6358c39a70e 127 if (
AhmedPlaymaker 29:c6358c39a70e 128 ((snake_pos.y + y == food_pos[food_sr].y) ||
AhmedPlaymaker 29:c6358c39a70e 129 (snake_pos.y + y == food_pos[food_sr].y + 1) ||
AhmedPlaymaker 29:c6358c39a70e 130 (snake_pos.y + y == food_pos[food_sr].y + 2)) &&
AhmedPlaymaker 29:c6358c39a70e 131 ((snake_pos.x + x == food_pos[food_sr].x) ||
AhmedPlaymaker 29:c6358c39a70e 132 (snake_pos.x + x == food_pos[food_sr].x + 1) ||
AhmedPlaymaker 29:c6358c39a70e 133 (snake_pos.x + x == food_pos[food_sr].x + 2))
AhmedPlaymaker 29:c6358c39a70e 134 ) {
AhmedPlaymaker 29:c6358c39a70e 135 //printf("snake feast working \n");
AhmedPlaymaker 29:c6358c39a70e 136 //audio feedback
AhmedPlaymaker 29:c6358c39a70e 137 pad.tone(1000.0,0.1);
AhmedPlaymaker 29:c6358c39a70e 138 food_pos[food_sr].x = rand() % 82;
AhmedPlaymaker 29:c6358c39a70e 139 if((blockbuff>=11)&&(blockbuff<=blockgap-11)) { //this makes sure that the snake food appears seperated from the block
AhmedPlaymaker 29:c6358c39a70e 140 food_pos[food_sr].y = -2;
AhmedPlaymaker 29:c6358c39a70e 141 }
AhmedPlaymaker 29:c6358c39a70e 142 length+=1;
AhmedPlaymaker 29:c6358c39a70e 143 }
AhmedPlaymaker 25:e827f1a8fadc 144 }
AhmedPlaymaker 25:e827f1a8fadc 145 }
AhmedPlaymaker 9:d1d79d4ee673 146 }
AhmedPlaymaker 29:c6358c39a70e 147 _f.set_pos(food_pos[0]);
AhmedPlaymaker 29:c6358c39a70e 148 _ff.set_pos(food_pos[1]);
AhmedPlaymaker 29:c6358c39a70e 149 _fff.set_pos(food_pos[2]);
AhmedPlaymaker 29:c6358c39a70e 150 }
AhmedPlaymaker 12:1e601b176437 151
AhmedPlaymaker 12:1e601b176437 152 void SnakevsBlock::CheckSnakeBlockCollision(Gamepad &pad)
AhmedPlaymaker 12:1e601b176437 153 {
AhmedPlaymaker 12:1e601b176437 154 //Obtains all required coordinates.
AhmedPlaymaker 12:1e601b176437 155 Vector2D b_pos = _b.get_pos();
AhmedPlaymaker 12:1e601b176437 156 int *b_number;
AhmedPlaymaker 12:1e601b176437 157 b_number = _b.get_number();
AhmedPlaymaker 12:1e601b176437 158 Vector2D snake_pos = _s.get_pos(length);
AhmedPlaymaker 12:1e601b176437 159 //If statements check if the snake sprite has collided with any
AhmedPlaymaker 12:1e601b176437 160 //of the blocks which are a maximum of 5, if so then the snake length reduces and the block number reduces
AhmedPlaymaker 12:1e601b176437 161 //the block has to move slower and come down after every 2/3 iterations(dependent on the snake size.(think about this)
AhmedPlaymaker 29:c6358c39a70e 162 for(int block=0; block<=83; block+=1) { //this loop automatically detects for each section of block and each combination of collision
AhmedPlaymaker 29:c6358c39a70e 163 if ((snake_pos.y == b_pos.y + 10) && (snake_pos.x + 1 == b_pos.x + block)) {
AhmedPlaymaker 29:c6358c39a70e 164 //printf("snake collision working \n");
AhmedPlaymaker 29:c6358c39a70e 165 //audio feedback
AhmedPlaymaker 29:c6358c39a70e 166 if(blocknum > 0) {b_pos.y = 0;} //change this to speed y = 0 when length = 10.
AhmedPlaymaker 29:c6358c39a70e 167 srn = CheckBlock(block); //this tells us which of the 5 blocks we are colliding with
AhmedPlaymaker 29:c6358c39a70e 168 blocknum = b_number[srn];
AhmedPlaymaker 29:c6358c39a70e 169 ImplementCollision(pad);
AhmedPlaymaker 12:1e601b176437 170 }
AhmedPlaymaker 26:3495f7b0ede7 171 }
AhmedPlaymaker 27:3b4775a0d0bb 172 }
AhmedPlaymaker 29:c6358c39a70e 173
AhmedPlaymaker 29:c6358c39a70e 174 int SnakevsBlock::CheckBlock(int block) {
AhmedPlaymaker 29:c6358c39a70e 175 int srn;
AhmedPlaymaker 29:c6358c39a70e 176 if((block>=0)&&(block<=18)) {srn = 0;}
AhmedPlaymaker 29:c6358c39a70e 177 if((block>=19)&&(block<=34)) {srn = 1;}
AhmedPlaymaker 29:c6358c39a70e 178 if((block>=35)&&(block<=50)) {srn = 2;}
AhmedPlaymaker 29:c6358c39a70e 179 if((block>=51)&&(block<=66)) {srn = 3;}
AhmedPlaymaker 29:c6358c39a70e 180 if((block>=67)&&(block<=83)) {srn = 4;}
AhmedPlaymaker 29:c6358c39a70e 181 return srn;
AhmedPlaymaker 29:c6358c39a70e 182 }
AhmedPlaymaker 27:3b4775a0d0bb 183
AhmedPlaymaker 27:3b4775a0d0bb 184 void SnakevsBlock::ImplementCollision(Gamepad &pad) {
AhmedPlaymaker 27:3b4775a0d0bb 185 send=1;
AhmedPlaymaker 27:3b4775a0d0bb 186 blocknum-=1;
AhmedPlaymaker 29:c6358c39a70e 187 speed = 2;
AhmedPlaymaker 27:3b4775a0d0bb 188 if(blocknum >= 0) { // to make sure that snake doesn't decrease in length if number on the block is less than 1;
AhmedPlaymaker 27:3b4775a0d0bb 189 length-=1;
AhmedPlaymaker 27:3b4775a0d0bb 190 pad.tone(1000.0,0.1);
AhmedPlaymaker 29:c6358c39a70e 191 wait(0.04);
AhmedPlaymaker 12:1e601b176437 192 }
AhmedPlaymaker 13:9785f2404045 193 }
AhmedPlaymaker 13:9785f2404045 194
AhmedPlaymaker 13:9785f2404045 195 void SnakevsBlock::CheckSnakeBlockSidesCollision(Gamepad &pad, Direction d)
AhmedPlaymaker 13:9785f2404045 196 {
AhmedPlaymaker 26:3495f7b0ede7 197 //Obtains all required coordinates for checking block sides and snake collision.
AhmedPlaymaker 13:9785f2404045 198 Vector2D b_pos = _b.get_pos();
AhmedPlaymaker 24:1c118b071430 199 snake_pos[0] = _s.get_pos(length);
AhmedPlaymaker 24:1c118b071430 200 snake_pos[1] = _s.get_pos_before1(length);
AhmedPlaymaker 24:1c118b071430 201 snake_pos[2] = _s.get_pos_before2(length);
AhmedPlaymaker 24:1c118b071430 202 snake_pos[3] = _s.get_pos_before3(length);
AhmedPlaymaker 24:1c118b071430 203 snake_pos[4] = _s.get_pos_before4(length);
AhmedPlaymaker 24:1c118b071430 204 snake_pos[5] = _s.get_pos_before5(length);
AhmedPlaymaker 24:1c118b071430 205 snake_pos[6] = _s.get_pos_before6(length);
AhmedPlaymaker 24:1c118b071430 206 snake_pos[7] = _s.get_pos_before7(length);
AhmedPlaymaker 24:1c118b071430 207 snake_pos[8] = _s.get_pos_before8(length);
AhmedPlaymaker 24:1c118b071430 208 snake_pos[9] = _s.get_pos_before9(length);
AhmedPlaymaker 24:1c118b071430 209 snake_pos[10] = _s.get_pos_before10(length);
AhmedPlaymaker 24:1c118b071430 210 snake_pos[11] = _s.get_pos_before11(length);
AhmedPlaymaker 24:1c118b071430 211 snake_pos[12] = _s.get_pos_before12(length);
AhmedPlaymaker 24:1c118b071430 212 snake_pos[13] = _s.get_pos_before13(length);
AhmedPlaymaker 24:1c118b071430 213 snake_pos[14] = _s.get_pos_before14(length);
AhmedPlaymaker 13:9785f2404045 214
AhmedPlaymaker 13:9785f2404045 215 //If statements check if the snake sprite has collided with any
AhmedPlaymaker 13:9785f2404045 216 //of the blocks' sides and then stop the snake moving in x axis
AhmedPlaymaker 13:9785f2404045 217
AhmedPlaymaker 24:1c118b071430 218 speed = 1;
AhmedPlaymaker 24:1c118b071430 219 for(int i=0; i<=14; i++) {
AhmedPlaymaker 24:1c118b071430 220 b[i] = 1;
AhmedPlaymaker 24:1c118b071430 221 }
AhmedPlaymaker 23:592345a70329 222
AhmedPlaymaker 23:592345a70329 223 for(int i=0; i<=14; i++) {
AhmedPlaymaker 26:3495f7b0ede7 224 for(int a=0; a<=10; a++) {
AhmedPlaymaker 26:3495f7b0ede7 225 if (
AhmedPlaymaker 26:3495f7b0ede7 226 (snake_pos[i].y == b_pos.y + a) ||
AhmedPlaymaker 26:3495f7b0ede7 227 (snake_pos[i].y + 1 == b_pos.y + a) ||
AhmedPlaymaker 26:3495f7b0ede7 228 (snake_pos[i].y + 2 == b_pos.y + a)) {
AhmedPlaymaker 26:3495f7b0ede7 229
AhmedPlaymaker 26:3495f7b0ede7 230 //For West side of walls
AhmedPlaymaker 26:3495f7b0ede7 231 if(
AhmedPlaymaker 26:3495f7b0ede7 232 (((snake_pos[i].x == b_pos.x + 4) || //W
AhmedPlaymaker 26:3495f7b0ede7 233 (snake_pos[i].x == b_pos.x + 36) || //W
AhmedPlaymaker 26:3495f7b0ede7 234 (snake_pos[i].x == b_pos.x + 68) || //W
AhmedPlaymaker 26:3495f7b0ede7 235 (snake_pos[i].x + 1 == b_pos.x + 4) || //W
AhmedPlaymaker 26:3495f7b0ede7 236 (snake_pos[i].x + 1 == b_pos.x + 36) || //W
AhmedPlaymaker 26:3495f7b0ede7 237 (snake_pos[i].x + 1 == b_pos.x + 68) || //W
AhmedPlaymaker 26:3495f7b0ede7 238 (snake_pos[i].x == b_pos.x + 20) || //W
AhmedPlaymaker 26:3495f7b0ede7 239 (snake_pos[i].x == b_pos.x + 52) || //W
AhmedPlaymaker 26:3495f7b0ede7 240 (snake_pos[i].x == b_pos.x + 84) || //W
AhmedPlaymaker 26:3495f7b0ede7 241 (snake_pos[i].x + 1 == b_pos.x + 20) || //W
AhmedPlaymaker 26:3495f7b0ede7 242 (snake_pos[i].x + 1 == b_pos.x + 52) || //W
AhmedPlaymaker 26:3495f7b0ede7 243 (snake_pos[i].x + 1 == b_pos.x + 84))&&(d != E)&&(length > i)) //W
AhmedPlaymaker 26:3495f7b0ede7 244 ) {
AhmedPlaymaker 26:3495f7b0ede7 245 //code makes sure that the colliding part doesn't move in x axis.
AhmedPlaymaker 26:3495f7b0ede7 246 for(int snake_beed_num=0; snake_beed_num<=15; snake_beed_num++) {
AhmedPlaymaker 26:3495f7b0ede7 247 if(length == snake_beed_num + i) {
AhmedPlaymaker 26:3495f7b0ede7 248 b[snake_beed_num - 1] = 0;
AhmedPlaymaker 26:3495f7b0ede7 249 }
AhmedPlaymaker 25:e827f1a8fadc 250 }
AhmedPlaymaker 24:1c118b071430 251 }
AhmedPlaymaker 26:3495f7b0ede7 252
AhmedPlaymaker 26:3495f7b0ede7 253 //for East side of walls
AhmedPlaymaker 26:3495f7b0ede7 254 else if (
AhmedPlaymaker 26:3495f7b0ede7 255 (((snake_pos[i].x + 1 == b_pos.x + 18) || //E
AhmedPlaymaker 26:3495f7b0ede7 256 (snake_pos[i].x + 1 == b_pos.x + 50) || //E
AhmedPlaymaker 26:3495f7b0ede7 257 (snake_pos[i].x + 1 == b_pos.x + 82) || //E
AhmedPlaymaker 26:3495f7b0ede7 258 (snake_pos[i].x + 2 == b_pos.x + 18) || //E
AhmedPlaymaker 26:3495f7b0ede7 259 (snake_pos[i].x + 2 == b_pos.x + 50) || //E
AhmedPlaymaker 26:3495f7b0ede7 260 (snake_pos[i].x + 2 == b_pos.x + 82) || //E
AhmedPlaymaker 26:3495f7b0ede7 261 (snake_pos[i].x + 1 == b_pos.x + 2) || //E
AhmedPlaymaker 26:3495f7b0ede7 262 (snake_pos[i].x + 1 == b_pos.x + 34) || //E
AhmedPlaymaker 26:3495f7b0ede7 263 (snake_pos[i].x + 1 == b_pos.x + 66) || //E
AhmedPlaymaker 26:3495f7b0ede7 264 (snake_pos[i].x + 2 == b_pos.x + 2) || //E
AhmedPlaymaker 26:3495f7b0ede7 265 (snake_pos[i].x + 2 == b_pos.x + 34) || //E
AhmedPlaymaker 26:3495f7b0ede7 266 (snake_pos[i].x + 2 == b_pos.x + 66))&&(d != W)) //E
AhmedPlaymaker 26:3495f7b0ede7 267 ) {
AhmedPlaymaker 26:3495f7b0ede7 268 //add some code that it doesn't move through
AhmedPlaymaker 26:3495f7b0ede7 269 speed = 0;
AhmedPlaymaker 26:3495f7b0ede7 270 }
AhmedPlaymaker 25:e827f1a8fadc 271 }
AhmedPlaymaker 24:1c118b071430 272 }
AhmedPlaymaker 15:f4d069da093d 273 }
AhmedPlaymaker 22:ee698f66146f 274 }