Created
October 31, 2015 11:48
-
-
Save stamaniorec/e91992a9fb83d09d4b2e to your computer and use it in GitHub Desktop.
#pygame event handling
This file contains hidden or 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
| 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