CHAPTER 11

image

Controllers and Graphics

How do we get objects to move using the keyboard, mouse, or a game controller?

9781484217894_unFig11-01.jpg

So far, we’ve shown how to animate items on the screen, but not how to interact with them. How do we use a mouse, keyboard, or game controller to control the action onscreen? Thankfully this is pretty easy.

To begin with, it is necessary to have an object that can be moved around the screen. The best way to do this is to have a function that takes in an x and y coordinate, then draws an object at that location. So back to Chapter ...

Get Program Arcade Games: With Python and Pygame, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.