Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Committer:
AhmedPlaymaker
Date:
Mon Apr 15 13:58:09 2019 +0000
Revision:
32:3a3bdeffdf62
Parent:
29:c6358c39a70e
Child:
33:249cf423fb18
Some weird error of the joystick misbehaving occurs by fixing the program bouncing regularly

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 32:3a3bdeffdf62 22 blockbuff = -50;
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 32:3a3bdeffdf62 71 _s.update(pad.get_direction(),_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 > 15) { //to make progressive levels harder
AhmedPlaymaker 20:1e6338403427 81 blockgap -= 20;
AhmedPlaymaker 19:05cc9f801468 82 level += 1;
AhmedPlaymaker 16:7b474f873683 83 }
AhmedPlaymaker 25:e827f1a8fadc 84 if(pad.check_event(Gamepad::BACK_PRESSED)){ //Waits for Back button to be pressed.
AhmedPlaymaker 25:e827f1a8fadc 85 back = 1;
AhmedPlaymaker 25:e827f1a8fadc 86 //add some warning here and use A as the button to confirm
AhmedPlaymaker 25:e827f1a8fadc 87 SnakevsBlock::init();
AhmedPlaymaker 25:e827f1a8fadc 88 }
AhmedPlaymaker 25:e827f1a8fadc 89 else {
AhmedPlaymaker 25:e827f1a8fadc 90 back = 0;
AhmedPlaymaker 25:e827f1a8fadc 91 }
AhmedPlaymaker 25:e827f1a8fadc 92 return back;
AhmedPlaymaker 7:48ba87cd79b5 93 }
AhmedPlaymaker 7:48ba87cd79b5 94
AhmedPlaymaker 7:48ba87cd79b5 95 void SnakevsBlock::get_pos()
AhmedPlaymaker 7:48ba87cd79b5 96 {
AhmedPlaymaker 9:d1d79d4ee673 97 Vector2D snake_pos = _s.get_pos(length);
AhmedPlaymaker 7:48ba87cd79b5 98 //printf("player pos = %f %f \n", player_pos.x, player_pos.y); //top left of player sprite
AhmedPlaymaker 7:48ba87cd79b5 99 // 81.000000 0.000000 top right
AhmedPlaymaker 7:48ba87cd79b5 100 // 0.000000 0.000000 is top left
AhmedPlaymaker 7:48ba87cd79b5 101 // 81.000000 45.000000 bottom right
AhmedPlaymaker 7:48ba87cd79b5 102 snakex = snake_pos.x;
AhmedPlaymaker 7:48ba87cd79b5 103 snakey = snake_pos.y;
AhmedPlaymaker 7:48ba87cd79b5 104 //printf("snakexy in GAME = %d %d \n", snakex, snakey);
AhmedPlaymaker 7:48ba87cd79b5 105 }
AhmedPlaymaker 7:48ba87cd79b5 106
AhmedPlaymaker 9:d1d79d4ee673 107
AhmedPlaymaker 27:3b4775a0d0bb 108 void SnakevsBlock::CheckSnakeFoodCollision(Gamepad &pad) {
AhmedPlaymaker 32:3a3bdeffdf62 109 //Obtains all required coordinates.
AhmedPlaymaker 32:3a3bdeffdf62 110 Vector2D food_pos[3];
AhmedPlaymaker 32:3a3bdeffdf62 111 food_pos[0] = _f.get_pos();
AhmedPlaymaker 32:3a3bdeffdf62 112 food_pos[1] = _ff.get_pos();
AhmedPlaymaker 32:3a3bdeffdf62 113 food_pos[2] = _fff.get_pos();
AhmedPlaymaker 32:3a3bdeffdf62 114 Vector2D snake_pos = _s.get_pos(length);
AhmedPlaymaker 32:3a3bdeffdf62 115 //If statements check if the snake sprite has collided with any
AhmedPlaymaker 32:3a3bdeffdf62 116 //of the three food sprites, if so then the food location is reset and
AhmedPlaymaker 32:3a3bdeffdf62 117 //length of the snake is increased using the length variable.
AhmedPlaymaker 29:c6358c39a70e 118 for(int y=0; y<=2; y++) { //this loop automatically detects each combination of collision in the y postion
AhmedPlaymaker 29:c6358c39a70e 119 for(int x=0; x<=2; x++) { //this loop automatically detects each combination of collision in the x postion
AhmedPlaymaker 29:c6358c39a70e 120 for(int food_sr=0; food_sr<=2; food_sr++) { //this loop automatically detects which food we are interacting with.
AhmedPlaymaker 29:c6358c39a70e 121 if (
AhmedPlaymaker 29:c6358c39a70e 122 ((snake_pos.y + y == food_pos[food_sr].y) ||
AhmedPlaymaker 29:c6358c39a70e 123 (snake_pos.y + y == food_pos[food_sr].y + 1) ||
AhmedPlaymaker 29:c6358c39a70e 124 (snake_pos.y + y == food_pos[food_sr].y + 2)) &&
AhmedPlaymaker 29:c6358c39a70e 125 ((snake_pos.x + x == food_pos[food_sr].x) ||
AhmedPlaymaker 29:c6358c39a70e 126 (snake_pos.x + x == food_pos[food_sr].x + 1) ||
AhmedPlaymaker 29:c6358c39a70e 127 (snake_pos.x + x == food_pos[food_sr].x + 2))
AhmedPlaymaker 29:c6358c39a70e 128 ) {
AhmedPlaymaker 29:c6358c39a70e 129 //printf("snake feast working \n");
AhmedPlaymaker 29:c6358c39a70e 130 //audio feedback
AhmedPlaymaker 29:c6358c39a70e 131 pad.tone(1000.0,0.1);
AhmedPlaymaker 29:c6358c39a70e 132 food_pos[food_sr].x = rand() % 82;
AhmedPlaymaker 29:c6358c39a70e 133 if((blockbuff>=11)&&(blockbuff<=blockgap-11)) { //this makes sure that the snake food appears seperated from the block
AhmedPlaymaker 29:c6358c39a70e 134 food_pos[food_sr].y = -2;
AhmedPlaymaker 29:c6358c39a70e 135 }
AhmedPlaymaker 29:c6358c39a70e 136 length+=1;
AhmedPlaymaker 29:c6358c39a70e 137 }
AhmedPlaymaker 25:e827f1a8fadc 138 }
AhmedPlaymaker 25:e827f1a8fadc 139 }
AhmedPlaymaker 9:d1d79d4ee673 140 }
AhmedPlaymaker 29:c6358c39a70e 141 _f.set_pos(food_pos[0]);
AhmedPlaymaker 29:c6358c39a70e 142 _ff.set_pos(food_pos[1]);
AhmedPlaymaker 29:c6358c39a70e 143 _fff.set_pos(food_pos[2]);
AhmedPlaymaker 29:c6358c39a70e 144 }
AhmedPlaymaker 12:1e601b176437 145
AhmedPlaymaker 12:1e601b176437 146 void SnakevsBlock::CheckSnakeBlockCollision(Gamepad &pad)
AhmedPlaymaker 12:1e601b176437 147 {
AhmedPlaymaker 12:1e601b176437 148 //Obtains all required coordinates.
AhmedPlaymaker 12:1e601b176437 149 Vector2D b_pos = _b.get_pos();
AhmedPlaymaker 12:1e601b176437 150 int *b_number;
AhmedPlaymaker 12:1e601b176437 151 b_number = _b.get_number();
AhmedPlaymaker 12:1e601b176437 152 Vector2D snake_pos = _s.get_pos(length);
AhmedPlaymaker 12:1e601b176437 153 //If statements check if the snake sprite has collided with any
AhmedPlaymaker 12:1e601b176437 154 //of the blocks which are a maximum of 5, if so then the snake length reduces and the block number reduces
AhmedPlaymaker 12:1e601b176437 155 //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 156 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 157 if ((snake_pos.y == b_pos.y + 10) && (snake_pos.x + 1 == b_pos.x + block)) {
AhmedPlaymaker 29:c6358c39a70e 158 //printf("snake collision working \n");
AhmedPlaymaker 29:c6358c39a70e 159 //audio feedback
AhmedPlaymaker 29:c6358c39a70e 160 if(blocknum > 0) {b_pos.y = 0;} //change this to speed y = 0 when length = 10.
AhmedPlaymaker 29:c6358c39a70e 161 srn = CheckBlock(block); //this tells us which of the 5 blocks we are colliding with
AhmedPlaymaker 29:c6358c39a70e 162 blocknum = b_number[srn];
AhmedPlaymaker 29:c6358c39a70e 163 ImplementCollision(pad);
AhmedPlaymaker 12:1e601b176437 164 }
AhmedPlaymaker 26:3495f7b0ede7 165 }
AhmedPlaymaker 27:3b4775a0d0bb 166 }
AhmedPlaymaker 29:c6358c39a70e 167
AhmedPlaymaker 29:c6358c39a70e 168 int SnakevsBlock::CheckBlock(int block) {
AhmedPlaymaker 29:c6358c39a70e 169 int srn;
AhmedPlaymaker 29:c6358c39a70e 170 if((block>=0)&&(block<=18)) {srn = 0;}
AhmedPlaymaker 29:c6358c39a70e 171 if((block>=19)&&(block<=34)) {srn = 1;}
AhmedPlaymaker 29:c6358c39a70e 172 if((block>=35)&&(block<=50)) {srn = 2;}
AhmedPlaymaker 29:c6358c39a70e 173 if((block>=51)&&(block<=66)) {srn = 3;}
AhmedPlaymaker 29:c6358c39a70e 174 if((block>=67)&&(block<=83)) {srn = 4;}
AhmedPlaymaker 29:c6358c39a70e 175 return srn;
AhmedPlaymaker 29:c6358c39a70e 176 }
AhmedPlaymaker 27:3b4775a0d0bb 177
AhmedPlaymaker 27:3b4775a0d0bb 178 void SnakevsBlock::ImplementCollision(Gamepad &pad) {
AhmedPlaymaker 27:3b4775a0d0bb 179 send=1;
AhmedPlaymaker 27:3b4775a0d0bb 180 blocknum-=1;
AhmedPlaymaker 27:3b4775a0d0bb 181 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 182 length-=1;
AhmedPlaymaker 27:3b4775a0d0bb 183 pad.tone(1000.0,0.1);
AhmedPlaymaker 29:c6358c39a70e 184 wait(0.04);
AhmedPlaymaker 12:1e601b176437 185 }
AhmedPlaymaker 13:9785f2404045 186 }
AhmedPlaymaker 13:9785f2404045 187
AhmedPlaymaker 13:9785f2404045 188 void SnakevsBlock::CheckSnakeBlockSidesCollision(Gamepad &pad, Direction d)
AhmedPlaymaker 13:9785f2404045 189 {
AhmedPlaymaker 26:3495f7b0ede7 190 //Obtains all required coordinates for checking block sides and snake collision.
AhmedPlaymaker 13:9785f2404045 191 Vector2D b_pos = _b.get_pos();
AhmedPlaymaker 24:1c118b071430 192 snake_pos[0] = _s.get_pos(length);
AhmedPlaymaker 24:1c118b071430 193 snake_pos[1] = _s.get_pos_before1(length);
AhmedPlaymaker 24:1c118b071430 194 snake_pos[2] = _s.get_pos_before2(length);
AhmedPlaymaker 24:1c118b071430 195 snake_pos[3] = _s.get_pos_before3(length);
AhmedPlaymaker 24:1c118b071430 196 snake_pos[4] = _s.get_pos_before4(length);
AhmedPlaymaker 24:1c118b071430 197 snake_pos[5] = _s.get_pos_before5(length);
AhmedPlaymaker 24:1c118b071430 198 snake_pos[6] = _s.get_pos_before6(length);
AhmedPlaymaker 24:1c118b071430 199 snake_pos[7] = _s.get_pos_before7(length);
AhmedPlaymaker 24:1c118b071430 200 snake_pos[8] = _s.get_pos_before8(length);
AhmedPlaymaker 24:1c118b071430 201 snake_pos[9] = _s.get_pos_before9(length);
AhmedPlaymaker 24:1c118b071430 202 snake_pos[10] = _s.get_pos_before10(length);
AhmedPlaymaker 24:1c118b071430 203 snake_pos[11] = _s.get_pos_before11(length);
AhmedPlaymaker 24:1c118b071430 204 snake_pos[12] = _s.get_pos_before12(length);
AhmedPlaymaker 24:1c118b071430 205 snake_pos[13] = _s.get_pos_before13(length);
AhmedPlaymaker 24:1c118b071430 206 snake_pos[14] = _s.get_pos_before14(length);
AhmedPlaymaker 13:9785f2404045 207
AhmedPlaymaker 13:9785f2404045 208 //If statements check if the snake sprite has collided with any
AhmedPlaymaker 13:9785f2404045 209 //of the blocks' sides and then stop the snake moving in x axis
AhmedPlaymaker 13:9785f2404045 210
AhmedPlaymaker 24:1c118b071430 211 for(int i=0; i<=14; i++) {
AhmedPlaymaker 24:1c118b071430 212 b[i] = 1;
AhmedPlaymaker 24:1c118b071430 213 }
AhmedPlaymaker 23:592345a70329 214
AhmedPlaymaker 23:592345a70329 215 for(int i=0; i<=14; i++) {
AhmedPlaymaker 26:3495f7b0ede7 216 for(int a=0; a<=10; a++) {
AhmedPlaymaker 26:3495f7b0ede7 217 if (
AhmedPlaymaker 26:3495f7b0ede7 218 (snake_pos[i].y == b_pos.y + a) ||
AhmedPlaymaker 26:3495f7b0ede7 219 (snake_pos[i].y + 1 == b_pos.y + a) ||
AhmedPlaymaker 26:3495f7b0ede7 220 (snake_pos[i].y + 2 == b_pos.y + a)) {
AhmedPlaymaker 26:3495f7b0ede7 221
AhmedPlaymaker 32:3a3bdeffdf62 222 //For West side of walls
AhmedPlaymaker 32:3a3bdeffdf62 223 if(
AhmedPlaymaker 32:3a3bdeffdf62 224 ((snake_pos[i].x == b_pos.x + 4) || //W
AhmedPlaymaker 26:3495f7b0ede7 225 (snake_pos[i].x == b_pos.x + 36) || //W
AhmedPlaymaker 26:3495f7b0ede7 226 (snake_pos[i].x == b_pos.x + 68) || //W
AhmedPlaymaker 26:3495f7b0ede7 227 (snake_pos[i].x + 1 == b_pos.x + 4) || //W
AhmedPlaymaker 26:3495f7b0ede7 228 (snake_pos[i].x + 1 == b_pos.x + 36) || //W
AhmedPlaymaker 26:3495f7b0ede7 229 (snake_pos[i].x + 1 == b_pos.x + 68) || //W
AhmedPlaymaker 26:3495f7b0ede7 230 (snake_pos[i].x == b_pos.x + 20) || //W
AhmedPlaymaker 26:3495f7b0ede7 231 (snake_pos[i].x == b_pos.x + 52) || //W
AhmedPlaymaker 26:3495f7b0ede7 232 (snake_pos[i].x == b_pos.x + 84) || //W
AhmedPlaymaker 26:3495f7b0ede7 233 (snake_pos[i].x + 1 == b_pos.x + 20) || //W
AhmedPlaymaker 26:3495f7b0ede7 234 (snake_pos[i].x + 1 == b_pos.x + 52) || //W
AhmedPlaymaker 32:3a3bdeffdf62 235 (snake_pos[i].x + 1 == b_pos.x + 84))&&(d != E)&&(length > i) //W
AhmedPlaymaker 26:3495f7b0ede7 236 ) {
AhmedPlaymaker 26:3495f7b0ede7 237 //code makes sure that the colliding part doesn't move in x axis.
AhmedPlaymaker 26:3495f7b0ede7 238 for(int snake_beed_num=0; snake_beed_num<=15; snake_beed_num++) {
AhmedPlaymaker 26:3495f7b0ede7 239 if(length == snake_beed_num + i) {
AhmedPlaymaker 26:3495f7b0ede7 240 b[snake_beed_num - 1] = 0;
AhmedPlaymaker 26:3495f7b0ede7 241 }
AhmedPlaymaker 25:e827f1a8fadc 242 }
AhmedPlaymaker 24:1c118b071430 243 }
AhmedPlaymaker 26:3495f7b0ede7 244
AhmedPlaymaker 26:3495f7b0ede7 245 //for East side of walls
AhmedPlaymaker 26:3495f7b0ede7 246 else if (
AhmedPlaymaker 32:3a3bdeffdf62 247 ((snake_pos[i].x + 1 == b_pos.x + 18) || //E
AhmedPlaymaker 26:3495f7b0ede7 248 (snake_pos[i].x + 1 == b_pos.x + 50) || //E
AhmedPlaymaker 26:3495f7b0ede7 249 (snake_pos[i].x + 1 == b_pos.x + 82) || //E
AhmedPlaymaker 26:3495f7b0ede7 250 (snake_pos[i].x + 2 == b_pos.x + 18) || //E
AhmedPlaymaker 26:3495f7b0ede7 251 (snake_pos[i].x + 2 == b_pos.x + 50) || //E
AhmedPlaymaker 26:3495f7b0ede7 252 (snake_pos[i].x + 2 == b_pos.x + 82) || //E
AhmedPlaymaker 26:3495f7b0ede7 253 (snake_pos[i].x + 1 == b_pos.x + 2) || //E
AhmedPlaymaker 26:3495f7b0ede7 254 (snake_pos[i].x + 1 == b_pos.x + 34) || //E
AhmedPlaymaker 26:3495f7b0ede7 255 (snake_pos[i].x + 1 == b_pos.x + 66) || //E
AhmedPlaymaker 26:3495f7b0ede7 256 (snake_pos[i].x + 2 == b_pos.x + 2) || //E
AhmedPlaymaker 26:3495f7b0ede7 257 (snake_pos[i].x + 2 == b_pos.x + 34) || //E
AhmedPlaymaker 32:3a3bdeffdf62 258 (snake_pos[i].x + 2 == b_pos.x + 66))&&(d != W) //E
AhmedPlaymaker 26:3495f7b0ede7 259 ) {
AhmedPlaymaker 32:3a3bdeffdf62 260 //code makes sure that the colliding part doesn't move in x axis.
AhmedPlaymaker 32:3a3bdeffdf62 261 for(int snake_beed_num=0; snake_beed_num<=15; snake_beed_num++) {
AhmedPlaymaker 32:3a3bdeffdf62 262 if(length == snake_beed_num + i) {
AhmedPlaymaker 32:3a3bdeffdf62 263 b[snake_beed_num - 1] = 0;
AhmedPlaymaker 32:3a3bdeffdf62 264 }
AhmedPlaymaker 32:3a3bdeffdf62 265 }
AhmedPlaymaker 26:3495f7b0ede7 266 }
AhmedPlaymaker 25:e827f1a8fadc 267 }
AhmedPlaymaker 24:1c118b071430 268 }
AhmedPlaymaker 15:f4d069da093d 269 }
AhmedPlaymaker 22:ee698f66146f 270 }