Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
Diff: SnakevsBlock/SnakevsBlock.cpp
- Revision:
- 42:973bb6036f81
- Parent:
- 41:4edac50f010d
- Child:
- 43:233f93860d08
--- a/SnakevsBlock/SnakevsBlock.cpp Tue Apr 23 12:25:49 2019 +0000 +++ b/SnakevsBlock/SnakevsBlock.cpp Tue Apr 23 15:22:09 2019 +0000 @@ -16,7 +16,7 @@ level = 1; garbage = 0; //this is to allow the user to change the position of reference for motion control by saving the absolute angle. foodbuff = 0; //this makes the food fall at diffrent times when a particular level starts. - send = 0; + send_block_number = 0; blockgap = 500; blockbuff = -50; for(int i=0; i<=14; i++) { @@ -34,6 +34,7 @@ { //This prepares the game for the next level by reseting certain variables. foodbuff = 0; + _s.init(); _f.init(); _ff.init(); _fff.init(); @@ -124,7 +125,8 @@ int SnakevsBlock::update(Gamepad &pad) //Updates objects on screen. { - send = 0; + send_block_number = 0; //this is for the game to decide wether to remember the number on the block for the current itteration. + //we dont need to remember if it has already gone past the 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); //Function checks for when the snake collides with any of the blocks' sides. @@ -132,7 +134,7 @@ _f.update(); _ff.update(); _fff.update(); - _b.update(blocknum, srn, send); + _b.update(blocknum, srn, send_block_number); blockbuff++; if(blockbuff >= blockgap) { //this makes blockbuff reset every time the new set of blocks appear. blockbuff = -11; @@ -250,7 +252,7 @@ } void SnakevsBlock::ImplementCollision(Gamepad &pad) { - send = 1; + send_block_number = 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; _l.MinusLength(); @@ -260,16 +262,15 @@ } void SnakevsBlock::CheckSnakeBlockSidesCollision(Gamepad &pad) - { - //If statements check if the snake sprite has collided with any - //of the blocks' sides and then stop the snake moving in x axis +{ + //If statements check if the snake sprite has collided with any + //of the blocks' sides and then stop the snake moving in x axis - if(_length>=10) {_length = 10;} //to stop the snake length virtually at 10 when it goes past it. + if(_length>=10) {_length = 10;} //to stop the snake length virtually at 10 when it goes past it. - for(int i=0; i<=9; i++) { - b[i] = 1; - } - + for(int i=0; i<=9; i++) { + b[i] = 1; + } for(int i=0; i<=9; i++) { //i checks for all possible collisions with the snake respective to it's length. for(int b_y_combination=0; b_y_combination<=10; b_y_combination++) { if ( @@ -289,7 +290,6 @@ } } } - //for East side of walls else if ( ((snake_pos[i].x + 1 == b_x_combination) || //E