Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
Diff: Blocks/Blocks.cpp
- Revision:
- 41:4edac50f010d
- Parent:
- 37:ee47699915b8
- Child:
- 42:973bb6036f81
--- a/Blocks/Blocks.cpp Mon Apr 22 07:10:52 2019 +0000 +++ b/Blocks/Blocks.cpp Tue Apr 23 12:25:49 2019 +0000 @@ -276,13 +276,13 @@ void Blocks::init() { - blockdrop=0; k = 0; } -int Blocks::draw(N5110 &lcd, int length, int blockgap) -{ +void Blocks::draw(N5110 &lcd, int length, int blockgap) +{ + _length = length; velocity.x = 0; velocity.y = 1; //Resets SnakeFood position if it reaches the bottom of the screen. @@ -297,19 +297,20 @@ k = 0; } if(k == 0){ - send=0; + send = 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. _bx = 0; _by = -11; k = k+1; pos = 4; - times = 1; + times = 0; i=0;// to save the positions of the random numbers generated in a block while(pos<=68) { if(times == rand()%6) { - double round = length/(3/2); + double round = _length/(3/2); caseselect[i] = floor(round); } - if(times == rand()%6) { + else if(times == rand()%6) { caseselect[i] = 0; } else { @@ -317,12 +318,12 @@ } pos+=16; times+=1; - if (times == 5) { + if (times >= 5) { times = 0; } i++; } - double roundagain = length/(7/2); //to make sure at least one is smaller than the snake size + double roundagain = _length/(7/2); //to make sure at least one is smaller than the snake size caseselect[rand()%5] = floor(roundagain); } @@ -388,11 +389,9 @@ default: break; } - i++; - pos+=16; - } - return send; //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. + i++; + pos+=16; + } }