Prevent edge warping in Snake minigame

This commit is contained in:
Louis-Antoine 2020-04-26 21:17:15 +02:00
parent 10fbaaf781
commit 7c9ce1faee

View file

@ -1252,18 +1252,32 @@ static void CL_HandleSnake(void)
switch (snake->snakedir) switch (snake->snakedir)
{ {
case 1: case 1:
x = x > 0 ? x - 1 : SNAKE_NUM_BLOCKS_X - 1; if (x > 0)
x--;
else
snake->gameover = true;
break; break;
case 2: case 2:
x = x < SNAKE_NUM_BLOCKS_X - 1 ? x + 1 : 0; if (x < SNAKE_NUM_BLOCKS_X - 1)
x++;
else
snake->gameover = true;
break; break;
case 3: case 3:
y = y > 0 ? y - 1 : SNAKE_NUM_BLOCKS_Y - 1; if (y > 0)
y--;
else
snake->gameover = true;
break; break;
case 4: case 4:
y = y < SNAKE_NUM_BLOCKS_Y - 1 ? y + 1 : 0; if (y < SNAKE_NUM_BLOCKS_Y - 1)
y++;
else
snake->gameover = true;
break; break;
} }
if (snake->gameover)
return;
// Check collision with snake // Check collision with snake
for (i = 1; i < snake->snakelength - 1; i++) for (i = 1; i < snake->snakelength - 1; i++)