![](/media/cache/profiles/LinkedIn_0NghoZJ.jpeg.50x50_q85.jpg)
Snake vs Block Game to be run upon K64F.
Diff: GameObjects/Snake/Snake.cpp
- Revision:
- 79:35cb65c52d25
- Parent:
- 77:5c6bd659c32d
- Child:
- 81:4c1641e10dcd
--- a/GameObjects/Snake/Snake.cpp Sun May 05 17:22:48 2019 +0000 +++ b/GameObjects/Snake/Snake.cpp Sun May 05 23:48:57 2019 +0000 @@ -52,7 +52,7 @@ _x[0] = p.x; //Spawns player sprite near the middle of the screen. _y[0] = p.y; - for(int i=0; i<=13; i++) { + for(int i=0; i<=8; i++) { _x[i+1] = _x[i]; _y[i+1] = _y[i] - 3; } @@ -93,7 +93,7 @@ { //this makes all of the snake beeds chained together by making the lower ones drag towards where the top one was in the previous loop //the b[i] makes sure that the snake beed doesn't move if that beed is deactivated by colliding with a barrier. b[i] also signifies the specific beed number by i. - for(int i=0; i<=14; i++) { + for(int i=1; i<=9; i++) { if((_length > i)&&(_x[i-1] != _x[i])) { if ((_x[i-1] > _x[i])&&(b[i] == 1)&&(b[i-1] == 1)) { _x[i-1]-=_speed; @@ -108,7 +108,7 @@ void Snake::mooveSnake(Direction d, int* b) { //this makes the controls of W/E directions only exclusive to the top beed in the snake - for(int i=14; i>=0; i--) { + for(int i=0; i<=9; i++) { if((_length == i+1)&&(b[i] == 1)) { if (d == E) { @@ -127,15 +127,15 @@ { // the following makes sure that when the length is increased, the snake stays where it was when it ate food. - for(int i=2; i<=15; i++) { + for(int i=1; i<=9; i++) { - if(_length < i) { - _x[i-1] = _x[i-2]; + if(_length < (i+1)) { + _x[i] = _x[i-1]; } } //Limits set so that the snake does not travel off the screen. - for(int i=0; i<=14; i++) { + for(int i=0; i<=9; i++) { if (_x[i] <= 0) { _x[i] = 0;