This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Gameplay. | |
while not is_game_over: | |
#gets all the events occuring at any given time | |
for event in pygame.event.get(): | |
#If there is a quit type event - exit out of loop | |
if event.type == pygame.QUIT: | |
is_game_over = True | |
# Detect when key is pressed down | |
elif event.type == pygame.KEYDOWN: | |
# Move up if up key pressed | |
if event.key == pygame.K_UP: | |
direction = 1 | |
# Move down if down key is pressed | |
elif event.key == pygame.K_DOWN: | |
direction = -1 | |
# Detect when key is released | |
elif event.type == pygame.KEYUP: | |
# Stop movement when key no longer pressed | |
if event.key == pygame.K_UP or event.key == pygame.K_DOWN: | |
direction = 0 | |
print(event) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment