Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bridge.py35
-rw-r--r--physics.py7
-rw-r--r--tools.py17
3 files changed, 31 insertions, 28 deletions
diff --git a/bridge.py b/bridge.py
index e01a866..4f7eb79 100644
--- a/bridge.py
+++ b/bridge.py
@@ -5,7 +5,6 @@ class Bridge:
self.game = game
self.screen = game.screen
self.world = game.world
- self.joints = []
self.cost = 0
self.stress = 0
self.capacity = 1
@@ -41,11 +40,11 @@ class Bridge:
def joint_added(self, joint):
print "joint added!"
- self.joints.append(joint)
self.add_cost(100)
self.capacity += 500
- def joint_deleted(self):
+ def joint_deleted(self, joint):
+ print "joint deleting!"
self.add_cost(-100)
self.capacity -= 500
@@ -57,20 +56,26 @@ class Bridge:
def for_each_frame(self):
self.stress = 0
- for joint in self.joints:
- force = joint.GetReactionForce().Length()
- self.stress += force
+ joint = self.world.world.GetJointList()
+ going = True
+ while going:
+ if joint.GetType() == 1:
+ if joint.asRevoluteJoint().IsMotorEnabled() == False:
+ force = joint.GetReactionForce().Length()
+ self.stress += force
- if force > 500:
- print "destroy joint!"
- self.world.world.DestroyJoint(joint)
- self.joints.remove(joint)
- self.capacity -= 500
+ if force > 500:
+ print "destroy joint!"
+ self.world.world.DestroyJoint(joint)
+ 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:
- 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)
-
+ going = False
pos = self.first_train.GetPosition()
if pos.x > 14.0:
if not self.level_completed:
diff --git a/physics.py b/physics.py
index 57c9d46..f9afca1 100644
--- a/physics.py
+++ b/physics.py
@@ -67,18 +67,15 @@ class PhysicsGame:
# Clear Display
self.screen.fill((80,160,240)) #255 for white
-
-
# Update & Draw World
self.world.update()
self.world.draw()
-
if self.world.run_physics:
self.bridge.for_each_frame()
-
+
# draw output from tools
self.currentTool.draw()
-
+
#Print all the text on the screen
text = self.font.render(_("Total Cost: %d") % self.bridge.cost, True, (0,0,0))
textpos = text.get_rect(left=100,top=7)
diff --git a/tools.py b/tools.py
index d61f748..8a34f12 100644
--- a/tools.py
+++ b/tools.py
@@ -218,14 +218,15 @@ class DestroyTool(Tool):
self.vertices.pop(0)
tokill = self.game.world.get_bodies_at_pos(pygame.mouse.get_pos())
if tokill:
- joint = tokill[0].GetJointList()
- if joint:
- self.game.bridge.joint_deleted()
- while joint.next:
- joint = joint.next
- self.game.bridge.joint_deleted()
- self.game.world.world.DestroyBody(tokill[0])
- self.game.bridge.box_deleted()
+ jointnode = tokill[0].GetJointList()
+ if jointnode:
+ joint = jointnode.joint
+ self.game.bridge.joint_deleted(joint)
+ while joint.GetNext():
+ joint = joint.GetNext()
+ self.game.bridge.joint_deleted(joint)
+ self.game.world.world.DestroyBody(tokill[0])
+ self.game.bridge.box_deleted()
elif event.type == MOUSEBUTTONUP and event.button == 1:
self.cancel()
def draw(self):