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?
|
bool isAlive; // lebt die Schlange noch oder ist sie mit sich selbst kollidiert?
|
||||||
} snake_t;
|
} snake_t;
|
||||||
|
|
||||||
extern gameData_t game;
|
|
||||||
|
|
||||||
void snakeInit();
|
void snakeInit();
|
||||||
// Snake mit bestimmter Startlänge an Startposition erstellen
|
// Snake mit bestimmter Startlänge an Startposition erstellen
|
||||||
|
15
src/snake.c
15
src/snake.c
@ -1,4 +1,5 @@
|
|||||||
#include "snake.h"
|
#include "snake.h"
|
||||||
|
#include "game.h" //for access to global 'game' struct
|
||||||
|
|
||||||
|
|
||||||
void snakeInit()
|
void snakeInit()
|
||||||
@ -78,13 +79,13 @@ bool snakeIsAlive()
|
|||||||
|
|
||||||
void snakeSetHeadPos()
|
void snakeSetHeadPos()
|
||||||
{
|
{
|
||||||
switch(game.snake.direction)
|
switch(game.snake.direction)
|
||||||
{
|
{
|
||||||
// DOWN
|
// DOWN
|
||||||
case DOWN:
|
case DOWN:
|
||||||
game.snake.headX = game.snake.tail[0][0];
|
game.snake.headX = game.snake.tail[0][0];
|
||||||
game.snake.headY = game.snake.tail[0][1] + 1;
|
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;
|
game.snake.headY = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -92,23 +93,23 @@ void snakeSetHeadPos()
|
|||||||
case UP:
|
case UP:
|
||||||
game.snake.headX = game.snake.tail[0][0];
|
game.snake.headX = game.snake.tail[0][0];
|
||||||
game.snake.headY = game.snake.tail[0][1] - 1;
|
game.snake.headY = game.snake.tail[0][1] - 1;
|
||||||
if(game.snake.headY <= 0)
|
if(game.snake.headY < 0)
|
||||||
game.snake.headY = game.snake.height - 1;
|
game.snake.headY = game.map.height - 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// LEFT
|
// LEFT
|
||||||
case LEFT:
|
case LEFT:
|
||||||
game.snake.headX = game.snake.tail[0][0] - 1;
|
game.snake.headX = game.snake.tail[0][0] - 1;
|
||||||
game.snake.headY = game.snake.tail[0][1];
|
game.snake.headY = game.snake.tail[0][1];
|
||||||
if(game.snake.headX <= 0)
|
if(game.snake.headX < 0)
|
||||||
game.snake.headX = game.snake.weight - 1;
|
game.snake.headX = game.map.width - 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// RIGHT
|
// RIGHT
|
||||||
case RIGHT:
|
case RIGHT:
|
||||||
game.snake.headX = game.snake.tail[0][0] + 1;
|
game.snake.headX = game.snake.tail[0][0] + 1;
|
||||||
game.snake.headY = game.snake.tail[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;
|
game.snake.headX = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user