[Sugar-devel] PATCH: add a delete all function to physics
Bernie Innocenti
bernie at codewiz.org
Fri Dec 18 22:50:08 EST 2009
Hello Gary,
today I had a great dinner at Mel's aunts and after dinner Mel's cousin
and I hacked together this new feature for Physics.
We tested on a previous version of the activity, but then we upgraded to
the latest version available and -- oops! -- it does not work on x86_64
any more! :-)
So here's what you get for not supporting my architecture. An untested
patch!
--- Physics.activity/tools.py.orig 2009-12-18 22:43:20.779933607 -0500
+++ Physics.activity/tools.py 2009-12-18 22:41:50.680806893 -0500
@@ -458,6 +458,23 @@
else:
self.game.world.world.DestroyBody(tokill[0])
+ # Destroy everything!
+ elif pygame.mouse.get_pressed()[2]:
+
+ # Build a Python list of all bodies from the linked list returned by box2D
+ body = self.game.world.world.GetBodyList()
+ shapes = []
+ while body:
+ shapes.append(body)
+ body = body.GetNext()
+
+ # Destroy everything! Muhahahah!
+ for body in shapes:
+ self.game.world.world.DestroyBody(body)
+
+ # Oops! Restore the ground which we eagerly destroyed :-)
+ self.game.world.add.ground()
+
elif event.type == MOUSEBUTTONUP and event.button == 1:
self.cancel()
def draw(self):
--
// Bernie Innocenti - http://codewiz.org/
\X/ Sugar Labs - http://sugarlabs.org/
More information about the Sugar-devel
mailing list