From 31161c2862e4696a22cbd34fb63db5d2d33014d2 Mon Sep 17 00:00:00 2001 From: asaf Date: Sat, 08 Aug 2009 23:26:26 +0000 Subject: Added "Roll" tool --- diff --git a/MANIFEST b/MANIFEST index 602efc6..d76ff48 100644 --- a/MANIFEST +++ b/MANIFEST @@ -41,6 +41,7 @@ icons/joint.svg icons/magicpen.svg icons/polygon.svg icons/triangle.svg +icons/roll.svg olpcgames/__init__.py olpcgames/_cairoimage.py olpcgames/_gtkmain.py diff --git a/icons/roll.svg b/icons/roll.svg new file mode 100644 index 0000000..adafaed --- /dev/null +++ b/icons/roll.svg @@ -0,0 +1,118 @@ + + +image/svg+xml + + + + + + \ No newline at end of file diff --git a/physics.py b/physics.py index 6179206..dba7368 100644 --- a/physics.py +++ b/physics.py @@ -56,6 +56,13 @@ class PhysicsGame: self.currentTool.handleEvents(event) # Clear Display self.screen.fill((255,255,255)) #255 for white + + if self.world.run_physics: + for body in self.world.world.GetBodyList(): + if type(body.userData) == type({}): + if body.userData.has_key('rollMotor'): + diff = body.userData['rollMotor']['targetVelocity']- body.GetAngularVelocity() + body.ApplyTorque(body.userData['rollMotor']['strength']*diff*body.getMassData().I) # Update & Draw World self.world.update() diff --git a/tools.py b/tools.py index a7c4cfd..963e2a8 100644 --- a/tools.py +++ b/tools.py @@ -380,6 +380,32 @@ class MotorTool(Tool): self.jb1 = self.jb1pos = None def cancel(self): self.jb1 = self.jb1pos = None + +class RollTool(Tool): + name = 'Roll' + icon = 'roll' + toolTip = _("Roll") + toolAccelerator = _("r") + + def __init__(self,gameInstance): + self.game = gameInstance + self.name = 'Roll' + self.jb1 = self.jb1pos = None + def handleEvents(self,event): + #look for default events, and if none are handled then try the custom events + if not super(RollTool,self).handleEvents(event): + if event.type == MOUSEBUTTONDOWN: + if event.button == 1: + self.jb1pos = event.pos + self.jb1 = self.game.world.get_bodies_at_pos(event.pos) + if self.jb1: + if type(self.jb1[0].userData) == type({}): + self.jb1[0].userData['rollMotor'] = {} + self.jb1[0].userData['rollMotor']['targetVelocity'] = -10 + self.jb1[0].userData['rollMotor']['strength'] = 40 + self.jb1 = self.jb1pos = None + def cancel(self): + self.jb1 = self.jb1pos = None # The destroy tool -- cgit v0.9.1