Wednesday, October 19, 2011

Get a Gamepad Working with pygame.joystick

Since my 7th grade son loves to play Call of Duty 2 on the XBox 360, I've been thinking of incorporating the gamepad input device into his lessons.   

While I was going through the Panda3D manual, I found this reference to the Pygame joystick module.
"While Panda3D has mouse and keyboard support, it is best to look to the open source community for joystick support. Pygame is an open-source module that contains joystick support that may be easily included into a Panda3D application. Pygame may be found at"

Since the Panda3D developers suggested that their community use the Pygame joystick module,I felt more confident that learning more about this module would be time well spent.  I already had a Logitech Rumblepad USB gamepad which I purchased a few years ago for my son to play Halo 2 on Windows Vista.  

I found a short tutorial here on the use of pygame.joystick.  

Using the tutorial as a reference, I created a lesson based on a screenshot of Call of Duty 2 as a background image in my Pygame window and a crosshair target that moves around the screen with the left thumbpad.  

Here's some example code.


Here's a video of a python / pygame shooter game working with a Rumblepad.  The game author is 13 years old.