Fix typos in snake.c - compiles now
- use global variable 'game' from game.h instead of declaring new one - fix typo wrong variables - correct move out of map boundary
This commit is contained in:
parent
529b633c7a
commit
6b29f1360f
@ -21,7 +21,6 @@ typedef struct snake_t
|
||||
bool isAlive; // lebt die Schlange noch oder ist sie mit sich selbst kollidiert?
|
||||
} snake_t;
|
||||
|
||||
extern gameData_t game;
|
||||
|
||||
void snakeInit();
|
||||
// Snake mit bestimmter Startlänge an Startposition erstellen
|
||||
|
13
src/snake.c
13
src/snake.c
@ -1,4 +1,5 @@
|
||||
#include "snake.h"
|
||||
#include "game.h" //for access to global 'game' struct
|
||||
|
||||
|
||||
void snakeInit()
|
||||
@ -84,7 +85,7 @@ void snakeSetHeadPos()
|
||||
case DOWN:
|
||||
game.snake.headX = game.snake.tail[0][0];
|
||||
game.snake.headY = game.snake.tail[0][1] + 1;
|
||||
if(game.snake.headY >= game.snake.height)
|
||||
if(game.snake.headY >= game.map.height)
|
||||
game.snake.headY = 0;
|
||||
break;
|
||||
|
||||
@ -92,23 +93,23 @@ void snakeSetHeadPos()
|
||||
case UP:
|
||||
game.snake.headX = game.snake.tail[0][0];
|
||||
game.snake.headY = game.snake.tail[0][1] - 1;
|
||||
if(game.snake.headY <= 0)
|
||||
game.snake.headY = game.snake.height - 1;
|
||||
if(game.snake.headY < 0)
|
||||
game.snake.headY = game.map.height - 1;
|
||||
break;
|
||||
|
||||
// LEFT
|
||||
case LEFT:
|
||||
game.snake.headX = game.snake.tail[0][0] - 1;
|
||||
game.snake.headY = game.snake.tail[0][1];
|
||||
if(game.snake.headX <= 0)
|
||||
game.snake.headX = game.snake.weight - 1;
|
||||
if(game.snake.headX < 0)
|
||||
game.snake.headX = game.map.width - 1;
|
||||
break;
|
||||
|
||||
// RIGHT
|
||||
case RIGHT:
|
||||
game.snake.headX = game.snake.tail[0][0] + 1;
|
||||
game.snake.headY = game.snake.tail[0][1];
|
||||
if(game.snake.headX >= game.snake.weight)
|
||||
if(game.snake.headX >= game.map.width)
|
||||
game.snake.headX = 0;
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user