Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bridge.py10
-rw-r--r--physics.py4
-rw-r--r--tools.py6
3 files changed, 16 insertions, 4 deletions
diff --git a/bridge.py b/bridge.py
index 6dac4c7..62a0f76 100644
--- a/bridge.py
+++ b/bridge.py
@@ -5,6 +5,7 @@ class Bridge:
self.game = game
self.screen = game.screen
self.world = game.world
+ self.joints = []
def create_world(self):
rect = pygame.Rect((0,800), (350, -250))
@@ -20,4 +21,13 @@ class Bridge:
def joint_added(self, joint):
print "joint added!"
+ self.joints.append(joint)
+
+ def for_each_frame(self):
+ for joint in self.joints:
+ force = joint.GetReactionForce().Length()
+ if force > 500:
+ print "destroy joint!"
+ self.world.world.DestroyJoint(joint)
+ self.joints.remove(joint)
diff --git a/physics.py b/physics.py
index b76db14..b2ca2cb 100644
--- a/physics.py
+++ b/physics.py
@@ -59,6 +59,9 @@ class PhysicsGame:
self.currentTool.handleEvents(event)
# Clear Display
self.screen.fill((255,255,255)) #255 for white
+
+ if self.world.run_physics:
+ self.bridge.for_each_frame()
# Update & Draw World
self.world.update()
@@ -71,6 +74,7 @@ class PhysicsGame:
text = self.font.render("Current Tool: "+self.currentTool.name, True, (255,255,255))
textpos = text.get_rect(left=700,top=7)
self.screen.blit(text,textpos)
+
# Flip Display
pygame.display.flip()
diff --git a/tools.py b/tools.py
index 1302d8c..0bb4c90 100644
--- a/tools.py
+++ b/tools.py
@@ -451,13 +451,11 @@ class BridgeJointTool(Tool):
if event.type != MOUSEBUTTONUP or event.button != 1:
return
- print "mouse button up"
- bodies = self.game.world.get_bodies_at_pos(event.pos)
+ bodies = self.game.world.get_bodies_at_pos(event.pos,
+ include_static=True)
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)