From 14a66b8e27011a0409451f91d181a2ddd0524527 Mon Sep 17 00:00:00 2001 From: jonny_jr9 Date: Sun, 17 Dec 2023 19:40:42 +0100 Subject: [PATCH] Fix bugged tail element at 0,0 when first eaten Fixed array index -> prevents render functions from accessing uninitialized value in `snake.tail[]` --- src/snake.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/snake.c b/src/snake.c index 9520aa7..6a9ffc0 100644 --- a/src/snake.c +++ b/src/snake.c @@ -36,8 +36,8 @@ void snakeGrow() game.snake.length++; // tail part is attached left of last tail part // maybe problem while rendering --> MUST BE SOLVED THEN - game.snake.tail[game.snake.length][0] = game.snake.tail[game.snake.length - 1][0] - 1; - game.snake.tail[game.snake.length][1] = game.snake.tail[game.snake.length - 1][1]; + game.snake.tail[game.snake.length - 1][0] = game.snake.tail[game.snake.length - 2][0]; + game.snake.tail[game.snake.length - 1][1] = game.snake.tail[game.snake.length - 2][1]; return; }