Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
Diff: SnakevsBlock/SnakevsBlock.cpp
- Revision:
- 44:cd10d07ea1e5
- Parent:
- 43:233f93860d08
- Child:
- 46:dc7dccae9f9e
--- a/SnakevsBlock/SnakevsBlock.cpp Thu Apr 25 18:12:17 2019 +0000 +++ b/SnakevsBlock/SnakevsBlock.cpp Thu Apr 25 21:43:07 2019 +0000 @@ -17,7 +17,7 @@ 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_block_number = 0; - blockgap = 500; + blockgap = 300; blockbuff = -50; for(int i=0; i<=14; i++) { b[i] = 1; @@ -34,6 +34,11 @@ { //This prepares the game for the next level by reseting certain variables. foodbuff = 0; + for(int i=0; i<=2; i++) { + food_pos[i].x = 0; + food_pos[i].y = 0; + } + _l.init(); _s.init(); _f.init(); _ff.init(); @@ -95,38 +100,13 @@ _l.print_length_on_screen(lcd); if(_length >= 20) { - if(blockgap >= 50) { //to make progressive levels harder - blockgap -= 40; - } - level += 1; _statset.write(level, sd); SnakevsBlock::reset(); - food_pos[0].x = 0; - food_pos[0].y = 0; - food_pos[1].x = 0; - food_pos[1].y = 0; - food_pos[2].x = 0; - food_pos[2].y = 0; - lcd.clear(); - lcd.printString("Level Complete",0,1); - lcd.printString("Press Start",10,3); - lcd.printString("to Proceed",12,4); - lcd.refresh(); - while (pad.check_event(Gamepad::START_PRESSED) == false) { - pad.leds_on(); - pad.tone(rand()%1001,0.1); //helps to set max freq for random sound - wait(0.1); - pad.leds_off(); - wait(0.1); - } - lcd.clear(); - sprintf(bufferlevel,"%d",level); - lcd.printString("Level:",25,1); - lcd.printString(bufferlevel,40,3); - lcd.refresh(); - wait(2); - _l._setLength(3); - } + _wl.LevelComplete(lcd, pad, food_pos, level, blockgap); + } + if(_length == 0) { + _wl.GameOver(lcd,pad); + } } int SnakevsBlock::update(Gamepad &pad) //Updates objects on screen. @@ -260,12 +240,12 @@ void SnakevsBlock::ImplementCollision(Gamepad &pad) { 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; + if(blocknum > 0) { // to make sure that snake doesn't decrease in _length if number on the block is less than 1; _l.MinusLength(); pad.tone(1000.0,0.1); wait(0.04); } + blocknum-=1; } void SnakevsBlock::CheckSnakeBlockSidesCollision(Gamepad &pad)