Skip to content

Instantly share code, notes, and snippets.

Created September 9, 2021 23:46
What would you like to do?
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment