11import pygame
22
3+
34class joystick (object ):
45 def __init__ (self ):
56 self .joystick_names = []
@@ -12,22 +13,23 @@ def __init__(self):
1213 self .joystick_names .append (pygame .joystick .Joystick (i ).get_name ())
1314
1415 # By default, load the first available joystick.
15- if ( len (self .joystick_names ) > 0 ) :
16+ if len (self .joystick_names ) > 0 :
1617 self .myJoystick = pygame .joystick .Joystick (0 )
1718 self .myJoystick .init ()
1819
1920 def joystickAvailable (self ):
20- if self .myJoystick != None :
21+ if self .myJoystick is not None :
2122 return True
2223 else :
2324 return False
2425
2526 def getAction (self ):
2627 action = ""
27- if self .myJoystick != None :
28+ if self .myJoystick is not None :
2829 try :
2930 xAx = 0
3031 yAx = 0
32+
3133 # sometimes 2 axis, sometimes 6, wtf?!
3234 if self .myJoystick .get_numaxes () == 2 :
3335 xAx = 0
@@ -39,25 +41,25 @@ def getAction(self):
3941 self .doMove = 2
4042 elif self .myJoystick .get_axis (xAx ) < 0 :
4143 self .doMove = 4
42- elif self .myJoystick .get_axis (yAx ) > 0 :
44+ elif self .myJoystick .get_axis (yAx ) > 0 :
4345 self .doMove = 3
44- elif self .myJoystick .get_axis (yAx ) < 0 :
46+ elif self .myJoystick .get_axis (yAx ) < 0 :
4547 self .doMove = 1
4648
47- if self .myJoystick .get_button (0 ) and self .joyButtonDown == False : # speed up
49+ if self .myJoystick .get_button (0 ) and self .joyButtonDown is False : # speed up
4850 action = "speedUp"
49- elif self .myJoystick .get_button (1 ) and self .joyButtonDown == False : # speed down
51+ elif self .myJoystick .get_button (1 ) and self .joyButtonDown is False : # speed down
5052 action = "speedDown"
51- elif (self .myJoystick .get_button (9 ) and self .joyButtonDown == False )\
52- or (self .myJoystick .get_button (3 ) and self .joyButtonDown == False ): # (re)start
53+ elif (self .myJoystick .get_button (9 ) and self .joyButtonDown is False )\
54+ or (self .myJoystick .get_button (3 ) and self .joyButtonDown is False ): # (re)start
5355 action = "restart"
54- elif ( self .myJoystick .get_button (8 ) and self .joyButtonDown == False ) :
56+ elif self .myJoystick .get_button (8 ) and self .joyButtonDown is False :
5557 action = 'quit'
5658 #else:
5759 # make sure NO button is down for reset
5860 someJoyButtonDown = False
5961 for i in range (0 , self .myJoystick .get_numbuttons ()):
60- if ( self .myJoystick .get_button (i )) :
62+ if self .myJoystick .get_button (i ) is True :
6163 someJoyButtonDown = True
6264 self .joyButtonDown = someJoyButtonDown
6365
0 commit comments