summaryrefslogtreecommitdiff
path: root/snake.c
diff options
context:
space:
mode:
Diffstat (limited to 'snake.c')
-rw-r--r--snake.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/snake.c b/snake.c
index 24c0900..6b94287 100644
--- a/snake.c
+++ b/snake.c
@@ -99,11 +99,15 @@ int main(void)
/* direction key detection */
case 's':
case 'j':
- snake->direction = DOWN;
+ /* prevent changing direction into yourself */
+ if (snake->direction != UP)
+ snake->direction = DOWN;
break;
case 'w':
case 'k':
- snake->direction = UP;
+ /* prevent changing direction into yourself */
+ if (snake->direction != DOWN)
+ snake->direction = UP;
break;
case 'a':
case 'h':