Anonymous avatar Anonymous committed 0dc0bf3

joystick support

Comments (0)

Files changed (1)


     screen = pygame.display.set_mode(SCREENRECT.size, winstyle)
+    if pygame.joystick.get_init() and pygame.joystick.get_count():
+        joy = pygame.joystick.Joystick(0)
+        joy.init()
+        if not joy.get_numaxes() or not joy.get_numbuttons():
+            print 'warning: joystick disabled. requires at least one axis and one button'
+            joy.quit()
+            joy = None
+    else:
+        joy = None
     # Load the Resources
     Img.background = load_image('background.gif', 0)
     Img.shot = load_image('shot.gif', 1)
-        # Move the player
+        # Handle Input, Control Tank
         if player.alive:
             direction = keystate[K_RIGHT] - keystate[K_LEFT]
+            firing = keystate[K_SPACE]
+            if joy:
+                direction += joy.get_axis(0)
+                firing += joy.get_button(0)
-        # Create new shots
-            if not player.reloading and keystate[K_SPACE] and len(shots) < MAX_SHOTS:
+            if not player.reloading and firing and len(shots) < MAX_SHOTS:
-            player.reloading = keystate[K_SPACE]
+            player.reloading = firing
         # Create new alien
         if alienreload:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.