1 / 9

Pygame Events

Pygame Events. Lecture 08. What is an Event?. We’ve been using them already. for event in pygame.event.get (): if event. type == pygame.QUIT :          done = True. When to Use Events. Anytime you’re looking for input from the user Specifically keys, or mouse clicks

Download Presentation

Pygame Events

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Pygame Events Lecture 08

  2. What is an Event? We’ve been using them already for event inpygame.event.get(): ifevent.type == pygame.QUIT:          done = True

  3. When to Use Events Anytime you’re looking for input from the user Specifically keys, or mouse clicks Events are processed as fast as the FPS

  4. Up Arrow - Pressed Let’s detect when the up arrow is pressed. Then print to the console when it is. for event inpygame.event.get(): ifevent.type == pygame.QUIT:          done = True ifevent.type == pygame.KEYDOWN: ifevent.key == pygame.K_UP: print"The up arrow was pressed!"

  5. Up Arrow - Released Events can also be on key releases ifevent.type == pygame.KEYDOWN: ifevent.key == pygame.K_UP: print"The up arrow was pressed!" ifevent.type == pygame.KEYUP: ifevent.key == pygame.K_UP: print"The up arrow was released!"

  6. All Arrow Keys ifevent.type == pygame.KEYDOWN: ifevent.key == pygame.K_UP: print"The up arrow was pressed!" ifevent.key == pygame.K_DOWN: print"The down arrow was pressed!" ifevent.key == pygame.K_RIGHT: print"The right arrow was pressed!" ifevent.key == pygame.K_LEFT: print"The left arrow was pressed!" ifevent.type == pygame.KEYUP: ifevent.key == pygame.K_UP: print"The up arrow was released!" ifevent.key == pygame.K_DOWN: print"The down arrow was released!" ifevent.key == pygame.K_RIGHT: print"The right arrow was released!" ifevent.key == pygame.K_LEFT: print"The left arrow was released!"

  7. Other Keys? If you want to use other keys (WASD) then go to: http://www.pygame.org/docs/ref/key.html

  8. Control an Entity We just need to change what happens on events ifevent.type == pygame.KEYDOWN: ifevent.key == pygame.K_UP: dude.dy = -3 ifevent.key == pygame.K_DOWN: dude.dy = 3 ifevent.key == pygame.K_RIGHT: dude.dx = 3 ifevent.key == pygame.K_LEFT: dude.dx = -3

  9. So That’s Basically a Game We can do all kinds of stuff

More Related