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