snake no longer turns back on itself

This commit is contained in:
Noah Swerhun 2021-09-18 19:22:23 -05:00
parent 68c2ae2498
commit 31b2f2c06d
3 changed files with 17 additions and 5 deletions

BIN
nsnake

Binary file not shown.

Binary file not shown.

View file

@ -58,10 +58,22 @@ int main(void) {
field_print(f);
switch (c) {
case up_key: dirn = UP; break;
case down_key: dirn = DOWN; break;
case right_key: dirn = RIGHT; break;
case left_key: dirn = LEFT; break;
case up_key:
if (dirn != DOWN)
dirn = UP;
break;
case down_key:
if (dirn != UP)
dirn = DOWN;
break;
case right_key:
if (dirn != LEFT)
dirn = RIGHT;
break;
case left_key:
if (dirn != RIGHT)
dirn = LEFT;
break;
case quit_key: goto quit;
}
snake_forward(s, dirn);