From 7c56f20c8a7fd4eb23ef6415d57735f84a5fdd66 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 14 Jul 2008 15:47:03 +0000 Subject: Gears... right click with joint tool --- diff --git a/elements/add_objects.py b/elements/add_objects.py index eb396d8..bac1606 100644 --- a/elements/add_objects.py +++ b/elements/add_objects.py @@ -465,7 +465,7 @@ class Add: self.parent.world.CreateJoint(jointDef) def fixedJoint(self, *args): - if len(args) == 2: + if len(args) >= 2: # Fixed Joint to the Background, don't assume the center of the body b1 = self.parent.world.GetGroundBody() b2 = args[0] @@ -473,7 +473,10 @@ class Add: jointDef = box2d.b2RevoluteJointDef() jointDef.Initialize(b1, b2, p1) - + if len(args) == 3: + jointDef.maxMotorTorque = 900.0 + jointDef.motorSpeed = 20.0 + jointDef.enableMotor = True self.parent.world.CreateJoint(jointDef) elif len(args) == 1: # Fixed Joint to the Background, assume the center of the body @@ -485,7 +488,7 @@ class Add: jointDef.Initialize(b1, b2, p1) self.parent.world.CreateJoint(jointDef) - + def revoluteJoint(self,b1,b2,p1): # revolute joint between to bodies p1 = self.to_b2vec(p1) @@ -518,7 +521,13 @@ class Add: jointDef.maxLength2 = maxLength2 self.parent.world.CreateJoint(jointDef) - + + #def jointMotor(self,b1,b2,p1,speed): + # p1 = self.tob2vec(p1) + # jointDef = box2d.b2RevoluteJointDef() + # jointDef.Initialize(b1, b2, p1) + # jointDef. + # def joint(self, *args): print "* Add Joint:", args diff --git a/tools.py b/tools.py index f3aee81..5bafd3c 100644 --- a/tools.py +++ b/tools.py @@ -37,6 +37,8 @@ class Tool(object): self.game.setTool("destroy") elif event.key == K_m: self.game.setTool("magicpen") + elif event.key == K_g: + self.game.setTool("gear") elif event.type == USEREVENT: if hasattr(event,"action"): if self.game.tools.has_key(event.action): self.game.setTool(event.action) @@ -260,11 +262,11 @@ class JointTool(Tool): #look for default events, and if none are handled then try the custom events if not super(JointTool,self).handleEvents(event): if event.type == MOUSEBUTTONDOWN: - if event.button == 1: + if event.button >= 1: # grab the first body self.jb1pos = event.pos self.jb1 = self.game.world.get_bodies_at_pos(event.pos) - self.jb2 = self.jb2pos = None + self.jb2 = self.jb2pos = None elif event.type == MOUSEBUTTONUP: if event.button == 1: # grab the second body @@ -280,10 +282,12 @@ class JointTool(Tool): self.jb1 = self.jb2 = self.jb1pos = self.jb2pos = None if event.button == 3: # add a centered fixed joint - self.jb2 = self.game.world.get_bodies_at_pos(event.pos) + '''self.jb2 = self.game.world.get_bodies_at_pos(event.pos) if self.jb2: self.game.world.add.fixedJoint(self.jb2[0]) # regardless, clean everything up + self.jb1 = self.jb2 = self.jb1pos = self.jb2pos = None''' + self.game.world.add.fixedJoint(self.jb1[0],self.jb1pos, True) self.jb1 = self.jb2 = self.jb1pos = self.jb2pos = None def draw(self): if self.jb1: -- cgit v0.9.1