diff options
author | Daniel Drake <dsd@laptop.org> | 2008-08-30 21:45:22 (GMT) |
---|---|---|
committer | Daniel Drake <dsd@laptop.org> | 2008-08-30 21:45:22 (GMT) |
commit | f837fb6f1d40087a3686d2e22c70e05be02e58f3 (patch) | |
tree | 6f71c817040bde91ea659b83a625a0b1dd26ba6c /tools.py | |
parent | 53489a7c53e90e1c31a06877549bd8e2fb052685 (diff) |
create a tool for adding resolute joints
Diffstat (limited to 'tools.py')
-rw-r--r-- | tools.py | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -4,6 +4,7 @@ # By Alex Levenson #================================================================== import pygame +from elements import box2d from pygame.locals import * from helpers import * from inspect import getmro @@ -92,6 +93,9 @@ class Tool(object): # default cancel doesn't do anything pass + def to_b2vec(self, pt): + return self.game.world.add.to_b2vec(pt) + # The circle creation tool class CircleTool(Tool): name = "circle" @@ -430,6 +434,41 @@ class JoystickTool(Tool): self.vertices = None +# The joint tool +class BridgeJointTool(Tool): + name = "bridgejoint" + icon = "joint" + toolTip = "Bridge Joint" + + def __init__(self,gameInstance): + self.game = gameInstance + self.name = "Bridge Joint" + self.jb1 = self.jb2 = self.jb1pos = self.jb2pos = None + def handleEvents(self,event): + #look for default events, and if none are handled then try the custom events + if super(BridgeJointTool,self).handleEvents(event): + return + if event.type != MOUSEBUTTONUP or event.button != 1: + return + + print "mouse button up" + bodies = self.game.world.get_bodies_at_pos(event.pos) + if not bodies or len(bodies) != 2: + return + + print bodies[0] + print bodies[1] + jointDef = box2d.b2RevoluteJointDef() + jointDef.Initialize(bodies[0], bodies[1], self.to_b2vec(event.pos)) + joint = self.game.world.world.CreateJoint(jointDef) + self.game.bridge.joint_added(joint) + + def draw(self): + return + + def cancel(self): + self.jb1 = self.jb2 = self.jb1pos = self.jb2pos = None + def getAllTools(): this_mod = __import__(__name__) all = [val for val in this_mod.__dict__.values() if isinstance(val, type)] |