Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bridge.py
diff options
context:
space:
mode:
authorGary Martin <gary@garycmartin.com>2012-10-24 00:40:54 (GMT)
committer Gary Martin <gary@garycmartin.com>2012-10-24 00:40:54 (GMT)
commitdb517f0b40c441158203d69aa34627058f2ab2e9 (patch)
tree3416eca5bca558b995d9c8feff24d76b18e3430f /bridge.py
parente6cff9307917aa97019785c32fbf0e412ba0e7ea (diff)
Use recent versions of Box2D and elements and ARM platform compatibility.
The version of Box2D and elements as used by the current version of Physics has been migrated over into Bridge and the old versions removed. The Elements egg needed some minor patches for a function used in Bridge hence the change in name to Elements-0.13-py2.5-bridge.egg. The binary blob paths are appended to the system path rather than inserted as the first choice so that builds that included newer versions of Box2d, or versions build for different architectures, will still work (tested on ARM XO-1.75 and XO-4 platforms). Due to the change in Elements/Box2D api some additional code changes were necessary, particularly the calculations in Bridge.py for calculating the joint stress on the rivits.
Diffstat (limited to 'bridge.py')
-rw-r--r--bridge.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/bridge.py b/bridge.py
index 4f7eb79..63d793d 100644
--- a/bridge.py
+++ b/bridge.py
@@ -57,25 +57,24 @@ class Bridge:
def for_each_frame(self):
self.stress = 0
joint = self.world.world.GetJointList()
- going = True
- while going:
- if joint.GetType() == 1:
- if joint.asRevoluteJoint().IsMotorEnabled() == False:
- force = joint.GetReactionForce().Length()
+ for j in joint:
+ try:
+ if j.IsMotorEnabled() == False:
+ force = j.GetReactionForce(30).Length()
self.stress += force
if force > 500:
print "destroy joint!"
- self.world.world.DestroyJoint(joint)
+ self.world.world.DestroyJoint(j)
self.capacity -= 500
else:
- vec = joint.GetAnchor1()
- coord = int(self.world.meter_to_screen(vec.x)),int(780 - self.world.meter_to_screen(vec.y))
- pygame.draw.circle(self.screen, (int(force/2),255-int(force/2),0), coord, 4)
- if joint.GetNext():
- joint = joint.GetNext()
- else:
- going = False
+ vec = j.GetAnchor1()
+ coord = int(self.world.meter_to_screen(vec.x)), \
+ int(780 - self.world.meter_to_screen(vec.y))
+ pygame.draw.circle(self.screen, (int(force/2),
+ 255-int(force/2),0), coord, 4)
+ except AttributeError:
+ print "*** hit an AttributeError", j
pos = self.first_train.GetPosition()
if pos.x > 14.0:
if not self.level_completed: