Skip to content

Instantly share code, notes, and snippets.

@stamaniorec
Created October 31, 2015 11:48
Show Gist options
  • Select an option

  • Save stamaniorec/e91992a9fb83d09d4b2e to your computer and use it in GitHub Desktop.

Select an option

Save stamaniorec/e91992a9fb83d09d4b2e to your computer and use it in GitHub Desktop.
#pygame event handling
while is_running:
for event in pygame.event.get():
# print(event)
if event.type == pygame.QUIT:
is_running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
is_running = False
elif event.key == pygame.K_RIGHT:
player.direction_x = 1
elif event.key == pygame.K_LEFT:
player.direction_x = -1
elif event.key == pygame.K_UP:
player.direction_y = -1
elif event.key == pygame.K_DOWN:
player.direction_y = 1
elif event.type == pygame.KEYUP:
if event.key == pygame.K_RIGHT:
player.direction_x = 0
elif event.key == pygame.K_LEFT:
player.direction_x = 0
elif event.key == pygame.K_UP:
player.direction_y = 0
elif event.key == pygame.K_DOWN:
player.direction_y = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment