From 6b29f1360fb8e832322a71fac7389da2aef3e118 Mon Sep 17 00:00:00 2001 From: jonny_jr9 Date: Sun, 3 Dec 2023 21:58:21 +0100 Subject: [PATCH] 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 --- include/snake.h | 1 - src/snake.c | 15 ++++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/snake.h b/include/snake.h index 68cc199..5f6990d 100644 --- a/include/snake.h +++ b/include/snake.h @@ -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 diff --git a/src/snake.c b/src/snake.c index 9b1a407..42f8c94 100644 --- a/src/snake.c +++ b/src/snake.c @@ -1,4 +1,5 @@ #include "snake.h" +#include "game.h" //for access to global 'game' struct void snakeInit() @@ -78,13 +79,13 @@ bool snakeIsAlive() void snakeSetHeadPos() { - switch(game.snake.direction) + switch(game.snake.direction) { // DOWN 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; }