snake no longer turns back on itself
This commit is contained in:
parent
68c2ae2498
commit
31b2f2c06d
3 changed files with 17 additions and 5 deletions
BIN
nsnake
BIN
nsnake
Binary file not shown.
BIN
obj/main.o
BIN
obj/main.o
Binary file not shown.
20
src/main.c
20
src/main.c
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue