diff options
author | Brian Jordan <brian@laptop.org> | 2008-07-20 20:24:38 (GMT) |
---|---|---|
committer | Brian Jordan <brian@laptop.org> | 2008-07-20 20:24:38 (GMT) |
commit | 313b03a86347294b6744c127a92a9eedad4d3ba0 (patch) | |
tree | f93c05d2af7c3edc5a23c18e4c0c6b6ea0e34202 /tools.py | |
parent | dd6761a5e4c29667725cb5298b3db32ac25280c2 (diff) |
Joystick button (is awesome... in progress)
Diffstat (limited to 'tools.py')
-rw-r--r-- | tools.py | 55 |
1 files changed, 45 insertions, 10 deletions
@@ -43,6 +43,39 @@ class Tool(object): self.game.setTool("magicpen") #elif event.key == K_g: # self.game.setTool("gear") + # Game/joystick-related keys + elif event.key == K_KP4: # Left gamepad, left arrow + if self.game.joystickobject: + self.game.joystickobject[0].ApplyTorque(9000) + elif self.game.debug: print "Left gamepad left arrow error: no joystick object selected" + elif event.key == K_KP6: # Left gamepad, right arrow + if self.game.joystickobject: + self.game.joystickobject[0].ApplyTorque(9000) + elif self.game.debug: print "Left gamepad right arrow error: no joystick object selected" + elif event.key == K_KP8: # Left gamepad, up arrow + if self.game.joystickobject: + self.game.joystickobject[0].ApplyTorque(9000) + elif self.game.debug: print "Left gamepad up arrow error: no joystick object selected" + elif event.key == K_KP2: # Left gamepad, down arrow + if self.game.joystickobject: + self.game.joystickobject[0].ApplyTorque(9000) + elif self.game.debug: print "Left gamepad down arrow error: no joystick object selected" + elif event.key == K_KP7: # Right gamepad, square + if self.game.joystickobject: + self.game.joystickobject[0].ApplyTorque(-9000) + elif self.game.debug: print "Right gamepad square button error: no joystick object selected" + elif event.key == K_KP1: # Right gamepad, check + if self.game.joystickobject: + self.game.joystickobject[0].ApplyTorque(-9000) + elif self.game.debug: print "Right gamepad check button error: no joystick object selected" + elif event.key == K_KP9: # Right gamepad, circle + if self.game.joystickobject: + self.game.joystickobject[0].ApplyTorque(-9000) + elif self.game.debug: print "Right gamepad circle button error: no joystick object selected" + elif event.key == K_KP3: # Right gamepad, X + if self.game.joystickobject: + self.game.joystickobject[0].ApplyTorque(-9000) + elif self.game.debug: print "Right gamepad X button error: no joystick object selected" elif event.type == USEREVENT: if hasattr(event,"action"): if self.game.toolList.has_key(event.action): self.game.setTool(event.action) @@ -374,17 +407,19 @@ class JoystickTool(Tool): #self.joystickobject def handleEvents(self,event): #look for default events, and if none are handled then try the custom events - if not super(JoystickTool,self).handleEvents(event): - if pygame.mouse.get_pressed()[0]: - if not self.vertices: self.vertices = [] + super(JoystickTool,self).handleEvents(event) + if pygame.mouse.get_pressed()[0]: + if not self.vertices: + self.vertices = [] self.vertices.append(pygame.mouse.get_pos()) - if len(self.vertices) > 10: - self.vertices.pop(0) - self.joystickobject = self.game.world.get_bodies_at_pos(pygame.mouse.get_pos()) - if tokill: - self.game.world.world.DestroyBody(tokill[0]) - elif event.type == MOUSEBUTTONUP and event.button == 1: - self.cancel() + if len(self.vertices) > 10: + self.vertices.pop(0) + self.game.joystickobject = self.game.world.get_bodies_at_pos(pygame.mouse.get_pos()) + if self.game.joystickobject: + print "hi1" + #self.game.world.world.DestroyBody(self.joystickobject[0]) + elif event.type == MOUSEBUTTONUP and event.button == 1: + self.cancel() def draw(self): # draw the trail if self.vertices: |