Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
Diff: SnakevsBlock/SnakevsBlock.cpp
- Revision:
- 33:249cf423fb18
- Parent:
- 32:3a3bdeffdf62
- Child:
- 36:dfdd619874ae
--- a/SnakevsBlock/SnakevsBlock.cpp Mon Apr 15 13:58:09 2019 +0000 +++ b/SnakevsBlock/SnakevsBlock.cpp Wed Apr 17 07:47:06 2019 +0000 @@ -53,7 +53,7 @@ if(foodbuff >=8) { send = _b.draw(lcd, length, blocknum, srn, blockgap); } - if(foodbuff == 8) { + if(foodbuff == 11) { blockbuff = 0; } //Code to print length on game screen. @@ -63,7 +63,7 @@ } -int SnakevsBlock::update(Gamepad &pad) //Updates objects on screen. +int SnakevsBlock::update(Gamepad &pad, SDFileSystem &sd) //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. @@ -74,12 +74,15 @@ _fff.update(); _b.update(blocknum, srn, send); blockbuff++; - if(blockbuff == blockgap) { //change this while changing the block drop gap + if(blockbuff == blockgap + 11) { //this makes blockbuff reset every time the new set of blocks appear. blockbuff = 0; } if(length > 15) { //to make progressive levels harder - blockgap -= 20; + if(blockgap>=50) { //to make progressive levels harder + blockgap -= 20; + } level += 1; + _statset.write(level, sd); } if(pad.check_event(Gamepad::BACK_PRESSED)){ //Waits for Back button to be pressed. back = 1; @@ -153,16 +156,16 @@ //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) - for(int block=0; block<=83; block+=1) { //this loop automatically detects for each section of block and each combination of collision - if ((snake_pos.y == b_pos.y + 10) && (snake_pos.x + 1 == b_pos.x + block)) { - //printf("snake collision working \n"); - //audio feedback - if(blocknum > 0) {b_pos.y = 0;} //change this to speed y = 0 when length = 10. - srn = CheckBlock(block); //this tells us which of the 5 blocks we are colliding with - blocknum = b_number[srn]; - ImplementCollision(pad); + for(int block=0; block<=83; block+=1) { //this loop automatically detects for each section of block and each combination of collision + if ((snake_pos.y == b_pos.y + 10) && (snake_pos.x + 1 == b_pos.x + block)) { + //printf("snake collision working \n"); + //audio feedback + if(blocknum > 0) {b_pos.y = 0;} //change this to speed y = 0 when length = 10. + srn = CheckBlock(block); //this tells us which of the 5 blocks we are colliding with + blocknum = b_number[srn]; + ImplementCollision(pad); + } } - } } int SnakevsBlock::CheckBlock(int block) {