Snake: Reorder apple generation/snake body update

If new apple was generated to heads previous position after update,
it would not render.
This commit is contained in:
Bananymous 2023-09-05 14:30:30 +03:00
parent d9c4114b5f
commit f46f5b2050
1 changed files with 7 additions and 7 deletions

View File

@ -169,6 +169,13 @@ void update()
}
}
MUST(g_tail.insert(0, old_head));
if (g_tail.size() > g_tail_target)
{
set_grid_tile(g_tail.back(), " ");
g_tail.pop_back();
}
if (g_head == g_apple)
{
g_tail_target++;
@ -177,13 +184,6 @@ void update()
printf("\e[%dH\e[mScore: %d", g_grid_size.y + 3, g_score);
}
MUST(g_tail.insert(0, old_head));
if (g_tail.size() > g_tail_target)
{
set_grid_tile(g_tail.back(), " ");
g_tail.pop_back();
}
set_grid_tile(old_head, "\e[32mo");
set_grid_tile(g_head, "\e[32mO");