Skip to content
Snippets Groups Projects
Commit 87e9f611 authored by Hameed Andy's avatar Hameed Andy
Browse files

still snake moves in all directions

parent 9d88a0f0
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment