From 87e9f611d3306c6b0a138b10d207e21d4ea1b331 Mon Sep 17 00:00:00 2001 From: andyh98 <hameea1@mcmaster.ca> Date: Thu, 22 Nov 2018 11:02:54 -0500 Subject: [PATCH] still snake moves in all directions --- BlankProjectTemplate/src/Gameplay.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/BlankProjectTemplate/src/Gameplay.py b/BlankProjectTemplate/src/Gameplay.py index 5197934..92048be 100644 --- a/BlankProjectTemplate/src/Gameplay.py +++ b/BlankProjectTemplate/src/Gameplay.py @@ -35,6 +35,7 @@ def game(speed, colour, backgroundColour): pygame.draw.rect(win, colour , [x,y, size, size]) food = Food(size) + still = True #Loop through the events as long as the game is running run = True @@ -52,21 +53,22 @@ def game(speed, colour, backgroundColour): if event.type == pygame.KEYDOWN: if (event.key == pygame.K_LEFT): # if snake is moving up or down, turn left, otherwise don't turn - if (snake.axis): snake.direct = -1 + if (snake.axis or still): snake.direct = -1; still = False snake.axis = 0 if (event.key == pygame.K_RIGHT): #if snake is moving up or down turn right, otherwise dont turn - if (snake.axis): snake.direct = 1 + if (snake.axis or still): snake.direct = 1; still = False snake.axis = 0 if (event.key == pygame.K_UP): #if snake is moving left or right turn up, otherwise dont turn - if (not snake.axis): snake.direct = -1 + if (not snake.axis or still): snake.direct = -1; still = False snake.axis = 1 if (event.key == pygame.K_DOWN): #if snake is moving left or right turn down, otherwise dont turn - if (not snake.axis): snake.direct = 1 + if (not snake.axis or still): snake.direct = 1; still = False snake.axis = 1 + #Snake moving depending on axis and direction if (snake.axis): y += (size)*snake.direct -- GitLab