Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
SnakevsBlock/SnakevsBlock.cpp
- Committer:
- AhmedPlaymaker
- Date:
- 2019-04-10
- Revision:
- 23:592345a70329
- Parent:
- 22:ee698f66146f
- Child:
- 24:1c118b071430
File content as of revision 23:592345a70329:
#include "SnakevsBlock.h" SnakevsBlock::SnakevsBlock() { } SnakevsBlock::~SnakevsBlock() { } void SnakevsBlock::init() { //The snake length configuration and all the other initial information passing will be done here length = 3; level = 1; foodbuff = 0; send=0; speed = 1; blockgap = 500; blockbuff = 0; for(int i=0; i<=14; i++) { b[i] = 1; } } void SnakevsBlock::read_input(Gamepad &pad) { _d = pad.get_direction(); //Obtains Direction pushed towards on Joystick. _mag = pad.get_mag(); //Obtains Magnitude of Joystick. } void SnakevsBlock::draw(N5110 &lcd, Gamepad &pad) { 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 if(foodbuff >=0) { _f.draw(lcd); //Draws the first food. if(foodbuff >=50) { _ff.draw(lcd); //Draws the second food. if(foodbuff >=80) { _fff.draw(lcd); //Draws the third food. } } foodbuff +=1; } if(foodbuff >=8) { send = _b.draw(lcd, length, blocknum, srn, blockgap); } if(foodbuff == 8) { blockbuff = 0; } //Code to print length on game screen. char bufferscore[14]; sprintf(bufferscore,"%d",length); lcd.printString(bufferscore,1,0); if(pad.check_event(Gamepad::BACK_PRESSED)){ //Waits for Back button to be pressed. NVIC_SystemReset(); //Software Reset. } } void SnakevsBlock::update(Gamepad &pad) //Updates objects on screen. { CheckSnakeBlockCollision(pad); //Function checks for when the snake collides with any of the blocks. CheckSnakeFoodCollision(pad); //Function checks for when the snake collides with it's food. CheckSnakeBlockSidesCollision(pad, _d); //Function checks for when the snake collides with any of the blocks' sides. _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 _f.update(); _ff.update(); _fff.update(); _b.update(blocknum, srn, send); blockbuff++; if(blockbuff == blockgap) { //change this while changing the block drop gap blockbuff = 0; } if(length >= 11) { //to make it easier to react to sudden happenings speed = 2; } else { speed = 1; } if(length > 15) { //to make progressive levels harder blockgap -= 20; level += 1; } } void SnakevsBlock::get_pos() { Vector2D snake_pos = _s.get_pos(length); //printf("player pos = %f %f \n", player_pos.x, player_pos.y); //top left of player sprite // 81.000000 0.000000 top right // 0.000000 0.000000 is top left // 81.000000 45.000000 bottom right snakex = snake_pos.x; snakey = snake_pos.y; //printf("snakexy in GAME = %d %d \n", snakex, snakey); } void SnakevsBlock::CheckSnakeFoodCollision(Gamepad &pad) { //Obtains all required coordinates. Vector2D f_pos = _f.get_pos(); Vector2D ff_pos = _ff.get_pos(); Vector2D fff_pos = _fff.get_pos(); Vector2D snake_pos = _s.get_pos(length); //If statements check if the snake sprite has collided with any //of the three food sprites, if so then the food location is reset and //length of the snake is increased using the length variable. if ( ((snake_pos.y == f_pos.y) || (snake_pos.y == f_pos.y + 1) || (snake_pos.y == f_pos.y + 2) || (snake_pos.y + 1== f_pos.y) || (snake_pos.y + 1== f_pos.y + 1) || (snake_pos.y + 1== f_pos.y + 2) || (snake_pos.y + 2 == f_pos.y) || (snake_pos.y + 2 == f_pos.y + 1) || (snake_pos.y + 2 == f_pos.y + 2)) && ((snake_pos.x == f_pos.x) || (snake_pos.x == f_pos.x + 1) || (snake_pos.x == f_pos.x + 2) || (snake_pos.x + 1 == f_pos.x) || (snake_pos.x + 1== f_pos.x + 1) || (snake_pos.x + 1 == f_pos.x + 2) || (snake_pos.x + 2 == f_pos.x) || (snake_pos.x + 2 == f_pos.x + 1) || (snake_pos.x + 2 == f_pos.x + 2)) ) { //printf("snake feast working \n"); //audio feedback pad.tone(1000.0,0.1); f_pos.x = rand() % 82; if(blockbuff>25) { //change this while changing the block drop gap f_pos.y = -2; } length+=1; } if ( ((snake_pos.y == ff_pos.y) || (snake_pos.y == ff_pos.y + 1) || (snake_pos.y == ff_pos.y + 2) || (snake_pos.y + 1== ff_pos.y) || (snake_pos.y + 1== ff_pos.y + 1) || (snake_pos.y + 1== ff_pos.y + 2) || (snake_pos.y + 2 == ff_pos.y) || (snake_pos.y + 2 == ff_pos.y + 1) || (snake_pos.y + 2 == ff_pos.y + 2)) && ((snake_pos.x == ff_pos.x) || (snake_pos.x == ff_pos.x + 1) || (snake_pos.x == ff_pos.x + 2) || (snake_pos.x + 1 == ff_pos.x) || (snake_pos.x + 1== ff_pos.x + 1) || (snake_pos.x + 1 == ff_pos.x + 2) || (snake_pos.x + 2 == ff_pos.x) || (snake_pos.x + 2 == ff_pos.x + 1) || (snake_pos.x + 2 == ff_pos.x + 2)) ) { //printf("snake feast working \n"); // audio feedback pad.tone(1000.0,0.1); ff_pos.x = rand() % 82; ff_pos.y = -2; if(blockbuff>25) { //change this while changing the block drop gap f_pos.y = -2; } length+=1; } if ( ((snake_pos.y == fff_pos.y) || (snake_pos.y == fff_pos.y + 1) || (snake_pos.y == fff_pos.y + 2) || (snake_pos.y + 1== fff_pos.y) || (snake_pos.y + 1== fff_pos.y + 1) || (snake_pos.y + 1== fff_pos.y + 2) || (snake_pos.y + 2 == fff_pos.y) || (snake_pos.y + 2 == fff_pos.y + 1) || (snake_pos.y + 2 == fff_pos.y + 2)) && ((snake_pos.x == fff_pos.x) || (snake_pos.x == fff_pos.x + 1) || (snake_pos.x == fff_pos.x + 2) || (snake_pos.x + 1 == fff_pos.x) || (snake_pos.x + 1== fff_pos.x + 1) || (snake_pos.x + 1 == fff_pos.x + 2) || (snake_pos.x + 2 == fff_pos.x) || (snake_pos.x + 2 == fff_pos.x + 1) || (snake_pos.x + 2 == fff_pos.x + 2)) ) { //printf("snake feast working \n"); // audio feedback pad.tone(1000.0,0.1); fff_pos.x = rand() % 82; fff_pos.y = -2; if(blockbuff>25) { //change this while changing the block drop gap f_pos.y = -2; } length+=1; } _f.set_pos(f_pos); _ff.set_pos(ff_pos); _fff.set_pos(fff_pos); } void SnakevsBlock::CheckSnakeBlockCollision(Gamepad &pad) { //Obtains all required coordinates. Vector2D b_pos = _b.get_pos(); int *b_number; b_number = _b.get_number(); Vector2D snake_pos = _s.get_pos(length); //If statements check if the snake sprite has collided with any //of the blocks which are a maximum of 5, if so then the snake length reduces and the block number reduces //the block has to move slower and come down after every 2/3 iterations(dependent on the snake size.(think about this) if ( ((snake_pos.y == b_pos.y + 10) || (snake_pos.y == b_pos.y + 10) || (snake_pos.y == b_pos.y + 10)) && ((snake_pos.x + 1 == b_pos.x + 1) || (snake_pos.x + 1 == b_pos.x + 2) || (snake_pos.x + 1 == b_pos.x + 3) || (snake_pos.x + 1 == b_pos.x + 4) || (snake_pos.x + 1 == b_pos.x + 5) || (snake_pos.x + 1 == b_pos.x + 6) || (snake_pos.x + 1 == b_pos.x + 7) || (snake_pos.x + 1 == b_pos.x + 8) || (snake_pos.x + 1 == b_pos.x + 9) || (snake_pos.x + 1 == b_pos.x + 10) || (snake_pos.x + 1 == b_pos.x + 11) || (snake_pos.x + 1 == b_pos.x + 12) || (snake_pos.x + 1 == b_pos.x + 13) || (snake_pos.x + 1 == b_pos.x + 14) || (snake_pos.x + 1 == b_pos.x + 15) || (snake_pos.x + 1 == b_pos.x + 16) || (snake_pos.x + 1 == b_pos.x + 17) || (snake_pos.x + 1 == b_pos.x + 18)) ) { //printf("snake collision working \n"); //audio feedback if(blocknum > 0) { b_pos.y = 0; } srn = 0; blocknum = b_number[srn]; send=1; blocknum-=1; if(blocknum >= 0) { // to make sure that snake doesn't decrease in length if number on the block is less than 1; speed = 2; length-=1; pad.tone(1000.0,0.1); wait(0.05); } else { speed = 1; } } if ( ((snake_pos.y == b_pos.y + 10) || (snake_pos.y == b_pos.y + 10) || (snake_pos.y == b_pos.y + 10)) && ((snake_pos.x + 1 == b_pos.x + 19) || (snake_pos.x + 1 == b_pos.x + 20) || (snake_pos.x + 1 == b_pos.x + 21) || (snake_pos.x + 1 == b_pos.x + 22) || (snake_pos.x + 1 == b_pos.x + 23) || (snake_pos.x + 1 == b_pos.x + 24) || (snake_pos.x + 1 == b_pos.x + 25) || (snake_pos.x + 1 == b_pos.x + 26) || (snake_pos.x + 1 == b_pos.x + 27) || (snake_pos.x + 1 == b_pos.x + 28) || (snake_pos.x + 1 == b_pos.x + 29) || (snake_pos.x + 1 == b_pos.x + 30) || (snake_pos.x + 1 == b_pos.x + 31) || (snake_pos.x + 1 == b_pos.x + 32) || (snake_pos.x + 1 == b_pos.x + 33) || (snake_pos.x + 1 == b_pos.x + 34)) ) { //printf("snake collision working \n"); //audio feedback if(blocknum > 0) { b_pos.y = 0; } srn = 1; blocknum = b_number[srn]; send=1; blocknum-=1; if(blocknum >= 0) { // to make sure that snake doesn't decrease in length if number on the block is less than 1; speed = 2; length-=1; pad.tone(1000.0,0.1); wait(0.05); } else { speed = 1; } } if ( ((snake_pos.y == b_pos.y + 10) || (snake_pos.y == b_pos.y + 10) || (snake_pos.y == b_pos.y + 10)) && ((snake_pos.x + 1 == b_pos.x + 35) || (snake_pos.x + 1 == b_pos.x + 36) || (snake_pos.x + 1 == b_pos.x + 37) || (snake_pos.x + 1 == b_pos.x + 38) || (snake_pos.x + 1 == b_pos.x + 39) || (snake_pos.x + 1 == b_pos.x + 40) || (snake_pos.x + 1 == b_pos.x + 41) || (snake_pos.x + 1 == b_pos.x + 42) || (snake_pos.x + 1 == b_pos.x + 43) || (snake_pos.x + 1 == b_pos.x + 44) || (snake_pos.x + 1 == b_pos.x + 45) || (snake_pos.x + 1 == b_pos.x + 46) || (snake_pos.x + 1 == b_pos.x + 47) || (snake_pos.x + 1 == b_pos.x + 48) || (snake_pos.x + 1 == b_pos.x + 49) || (snake_pos.x + 1 == b_pos.x + 50)) ) { //printf("snake collision working \n"); //audio feedback if(blocknum > 0) { b_pos.y = 0; } srn = 2; blocknum = b_number[srn]; send=1; blocknum-=1; if(blocknum >= 0) { // to make sure that snake doesn't decrease in length if number on the block is less than 1; speed = 2; length-=1; pad.tone(1000.0,0.1); wait(0.05); } else { speed = 1; } } if ( ((snake_pos.y == b_pos.y + 10) || (snake_pos.y == b_pos.y + 10) || (snake_pos.y == b_pos.y + 10)) && ((snake_pos.x + 1 == b_pos.x + 51) || (snake_pos.x + 1 == b_pos.x + 52) || (snake_pos.x + 1 == b_pos.x + 53) || (snake_pos.x + 1 == b_pos.x + 54) || (snake_pos.x + 1 == b_pos.x + 55) || (snake_pos.x + 1 == b_pos.x + 56) || (snake_pos.x + 1 == b_pos.x + 57) || (snake_pos.x + 1 == b_pos.x + 58) || (snake_pos.x + 1 == b_pos.x + 59) || (snake_pos.x + 1 == b_pos.x + 60) || (snake_pos.x + 1 == b_pos.x + 61) || (snake_pos.x + 1 == b_pos.x + 62) || (snake_pos.x + 1 == b_pos.x + 63) || (snake_pos.x + 1 == b_pos.x + 64) || (snake_pos.x + 1 == b_pos.x + 65) || (snake_pos.x + 1 == b_pos.x + 66)) ) { //printf("snake collision working \n"); //audio feedback if(blocknum > 0) { b_pos.y = 0; } srn = 3; blocknum = b_number[srn]; send=1; blocknum-=1; if(blocknum >= 0) { // to make sure that snake doesn't decrease in length if number on the block is less than 1; length-=1; pad.tone(1000.0,0.1); wait(0.05); } else { speed = 1; } } if ( ((snake_pos.y == b_pos.y + 10) || (snake_pos.y == b_pos.y + 10) || (snake_pos.y == b_pos.y + 10)) && ((snake_pos.x + 1 == b_pos.x + 67) || (snake_pos.x + 1 == b_pos.x + 68) || (snake_pos.x + 1 == b_pos.x + 69) || (snake_pos.x + 1 == b_pos.x + 70) || (snake_pos.x + 1 == b_pos.x + 71) || (snake_pos.x + 1 == b_pos.x + 72) || (snake_pos.x + 1 == b_pos.x + 73) || (snake_pos.x + 1 == b_pos.x + 74) || (snake_pos.x + 1 == b_pos.x + 75) || (snake_pos.x + 1 == b_pos.x + 76) || (snake_pos.x + 1 == b_pos.x + 77) || (snake_pos.x + 1 == b_pos.x + 78) || (snake_pos.x + 1 == b_pos.x + 79) || (snake_pos.x + 1 == b_pos.x + 80) || (snake_pos.x + 1 == b_pos.x + 81) || (snake_pos.x + 1 == b_pos.x + 82) || (snake_pos.x + 1 == b_pos.x + 83)) ) { //printf("snake collision working \n"); //audio feedback if(blocknum > 0) { b_pos.y = 0; } srn = 4; blocknum = b_number[srn]; send=1; blocknum-=1; if(blocknum >= 0) { // to make sure that snake doesn't decrease in length if number on the block is less than 1; speed = 2; length-=1; pad.tone(1000.0,0.1); wait(0.05); } else { speed = 1; } } } void SnakevsBlock::CheckSnakeBlockSidesCollision(Gamepad &pad, Direction d) { //Obtains all required coordinates. Vector2D b_pos = _b.get_pos(); snake_posx[0] = _s.get_pos(length).x; snake_posy[0] = _s.get_pos(length).y; snake_posx[1] = _s.get_pos_before1(length).x; snake_posy[1] = _s.get_pos_before1(length).y; snake_posx[2] = _s.get_pos_before2(length).x; snake_posy[2] = _s.get_pos_before2(length).y; snake_posx[3] = _s.get_pos_before3(length).x; snake_posy[3] = _s.get_pos_before3(length).y; snake_posx[4] = _s.get_pos_before4(length).x; snake_posy[4] = _s.get_pos_before4(length).y; snake_posx[5] = _s.get_pos_before5(length).x; snake_posy[5] = _s.get_pos_before5(length).y; snake_posx[6] = _s.get_pos_before6(length).x; snake_posy[6] = _s.get_pos_before6(length).y; snake_posx[7] = _s.get_pos_before7(length).x; snake_posy[7] = _s.get_pos_before7(length).y; snake_posx[8] = _s.get_pos_before8(length).x; snake_posy[8] = _s.get_pos_before8(length).y; snake_posx[9] = _s.get_pos_before9(length).x; snake_posy[9] = _s.get_pos_before9(length).y; snake_posx[10] = _s.get_pos_before10(length).x; snake_posy[10] = _s.get_pos_before10(length).y; snake_posx[11] = _s.get_pos_before11(length).x; snake_posy[11] = _s.get_pos_before11(length).y; snake_posx[12] = _s.get_pos_before12(length).x; snake_posy[12] = _s.get_pos_before12(length).y; snake_posx[13] = _s.get_pos_before13(length).x; snake_posy[13] = _s.get_pos_before13(length).y; snake_posx[14] = _s.get_pos_before14(length).x; snake_posy[14] = _s.get_pos_before14(length).y; Vector2D snake_pos = _s.get_pos(length); Vector2D snake_posb1 = _s.get_pos_before1(length); Vector2D snake_posb2 = _s.get_pos_before2(length); Vector2D snake_posb3 = _s.get_pos_before3(length); Vector2D snake_posb4 = _s.get_pos_before4(length); Vector2D snake_posb5 = _s.get_pos_before5(length); Vector2D snake_posb6 = _s.get_pos_before6(length); Vector2D snake_posb7 = _s.get_pos_before7(length); Vector2D snake_posb8 = _s.get_pos_before8(length); Vector2D snake_posb9 = _s.get_pos_before9(length); Vector2D snake_posb10 = _s.get_pos_before10(length); Vector2D snake_posb11 = _s.get_pos_before11(length); Vector2D snake_posb12 = _s.get_pos_before12(length); Vector2D snake_posb13 = _s.get_pos_before13(length); Vector2D snake_posb14 = _s.get_pos_before14(length); //If statements check if the snake sprite has collided with any //of the blocks' sides and then stop the snake moving in x axis speed = 1; for(int i=0; i<=14; i++) { b[i] = 1; } //For West for(int i=0; i<=14; i++) { if ( ((((snake_posy[i] == b_pos.y + 1) || (snake_posy[i] == b_pos.y + 1) || (snake_posy[i] == b_pos.y + 2) || (snake_posy[i] == b_pos.y + 3) || (snake_posy[i] == b_pos.y + 4) || (snake_posy[i] == b_pos.y + 5) || (snake_posy[i] == b_pos.y + 6) || (snake_posy[i] == b_pos.y + 7) || (snake_posy[i] == b_pos.y + 8) || (snake_posy[i] == b_pos.y + 9) || (snake_posy[i] == b_pos.y + 10) || (snake_posy[i] + 1 == b_pos.y) || (snake_posy[i] + 1 == b_pos.y + 1) || (snake_posy[i] + 1 == b_pos.y + 2) || (snake_posy[i] + 1 == b_pos.y + 3) || (snake_posy[i] + 1 == b_pos.y + 4) || (snake_posy[i] + 1 == b_pos.y + 5) || (snake_posy[i] + 1 == b_pos.y + 6) || (snake_posy[i] + 1 == b_pos.y + 7) || (snake_posy[i] + 1 == b_pos.y + 8) || (snake_posy[i] + 1 == b_pos.y + 9) || (snake_posy[i] + 1 == b_pos.y + 10) || (snake_posy[i] + 2 == b_pos.y) || (snake_posy[i] + 2 == b_pos.y + 1) || (snake_posy[i] + 2 == b_pos.y + 2) || (snake_posy[i] + 2 == b_pos.y + 3) || (snake_posy[i] + 2 == b_pos.y + 4) || (snake_posy[i] + 2 == b_pos.y + 5) || (snake_posy[i] + 2 == b_pos.y + 6) || (snake_posy[i] + 2 == b_pos.y + 7) || (snake_posy[i] + 2 == b_pos.y + 8) || (snake_posy[i] + 2 == b_pos.y + 9) || (snake_posy[i] + 2 == b_pos.y + 10)) && ((snake_posx[i] == b_pos.x + 4) || //W (snake_posx[i] == b_pos.x + 36) || //W (snake_posx[i] == b_pos.x + 68) || //W (snake_posx[i] + 1 == b_pos.x + 4) || //W (snake_posx[i] + 1 == b_pos.x + 36) || //W (snake_posx[i] + 1 == b_pos.x + 68) || //W (snake_posx[i] + 2 == b_pos.x + 4) || //W (snake_posx[i] + 2 == b_pos.x + 36) || //W (snake_posx[i] + 2 == b_pos.x + 68) || //W (snake_posx[i] == b_pos.x + 20) || //W (snake_posx[i] == b_pos.x + 52) || //W (snake_posx[i] == b_pos.x + 84) || //W (snake_posx[i] + 1 == b_pos.x + 20) || //W (snake_posx[i] + 1 == b_pos.x + 52) || //W (snake_posx[i] + 1 == b_pos.x + 84) || //W (snake_posx[i] + 2 == b_pos.x + 20) || //W (snake_posx[i] + 2 == b_pos.x + 52) || //W (snake_posx[i] + 2 == b_pos.x + 84)))&&(d != E)&&(length > i)) //W ) { //add some code that it doesn't move if(length == 1 + i) { b[0] = 0; } if(length == 2 + i) { b[1] = 0; } if(length== 3 + i) { b[2] = 0; } if(length== 4 + i) { b[3] = 0; } if(length== 5 + i) { b[4] = 0; } if(length== 6 + i) { b[5] = 0; } if(length== 7 + i) { b[6] = 0; } if(length== 8 + i) { b[7] = 0; } if(length== 9 + i) { b[8] = 0; } if(length== 10 + i) { b[9] = 0; } if(length== 11 + i) { b[10] = 0; } if(length== 12 + i) { b[11] = 0; } if(length== 13 + i) { b[12] = 0; } if(length == 14 + i) { b[13] = 0; } if(length== 15 + i) { b[14] = 0; } } //for East if ( ((((snake_posy[i] == b_pos.y + 1) || (snake_posy[i] == b_pos.y + 1) || (snake_posy[i] == b_pos.y + 2) || (snake_posy[i] == b_pos.y + 3) || (snake_posy[i] == b_pos.y + 4) || (snake_posy[i] == b_pos.y + 5) || (snake_posy[i] == b_pos.y + 6) || (snake_posy[i] == b_pos.y + 7) || (snake_posy[i] == b_pos.y + 8) || (snake_posy[i] == b_pos.y + 9) || (snake_posy[i] == b_pos.y + 10) || (snake_posy[i] + 1 == b_pos.y) || (snake_posy[i] + 1 == b_pos.y + 1) || (snake_posy[i] + 1 == b_pos.y + 2) || (snake_posy[i] + 1 == b_pos.y + 3) || (snake_posy[i] + 1 == b_pos.y + 4) || (snake_posy[i] + 1 == b_pos.y + 5) || (snake_posy[i] + 1 == b_pos.y + 6) || (snake_posy[i] + 1 == b_pos.y + 7) || (snake_posy[i] + 1 == b_pos.y + 8) || (snake_posy[i] + 1 == b_pos.y + 9) || (snake_posy[i] + 1 == b_pos.y + 10) || (snake_posy[i] + 2 == b_pos.y) || (snake_posy[i] + 2 == b_pos.y + 1) || (snake_posy[i] + 2 == b_pos.y + 2) || (snake_posy[i] + 2 == b_pos.y + 3) || (snake_posy[i] + 2 == b_pos.y + 4) || (snake_posy[i] + 2 == b_pos.y + 5) || (snake_posy[i] + 2 == b_pos.y + 6) || (snake_posy[i] + 2 == b_pos.y + 7) || (snake_posy[i] + 2 == b_pos.y + 8) || (snake_posy[i] + 2 == b_pos.y + 9) || (snake_posy[i] + 2 == b_pos.y + 10)) && ((snake_posx[i] == b_pos.x + 18) || //E (snake_posx[i] == b_pos.x + 50) || //E (snake_posx[i] == b_pos.x + 82) || //E (snake_posx[i] + 1 == b_pos.x + 18) || //E (snake_posx[i] + 1 == b_pos.x + 50) || //E (snake_posx[i] + 1 == b_pos.x + 82) || //E (snake_posx[i] + 2 == b_pos.x + 18) || //E (snake_posx[i] + 2 == b_pos.x + 50) || //E (snake_posx[i] + 2 == b_pos.x + 82) || //E (snake_posx[i] == b_pos.x + 2) || //E (snake_posx[i] == b_pos.x + 34) || //E (snake_posx[i] == b_pos.x + 66) || //E (snake_posx[i] + 1 == b_pos.x + 2) || //E (snake_posx[i] + 1 == b_pos.x + 34) || //E (snake_posx[i] + 1 == b_pos.x + 66) || //E (snake_posx[i] + 2 == b_pos.x + 2) || //E (snake_posx[i] + 2 == b_pos.x + 34) || //E (snake_posx[i] + 2 == b_pos.x + 66)))&&(d != W)) //E ) { //add some code that it doesn't move through speed = 0; } } }