diff skaapsteker/physics.py @ 416:3db2fc263d11

Kill sprites that leave the level area.
author Simon Cross <hodgestar@gmail.com>
date Sat, 09 Apr 2011 17:42:20 +0200
parents 55e00f186c6f
children 7c0643e51f33
line wrap: on
line diff
--- a/skaapsteker/physics.py	Sat Apr 09 17:40:21 2011 +0200
+++ b/skaapsteker/physics.py	Sat Apr 09 17:42:20 2011 +0200
@@ -168,12 +168,16 @@
         self.rect = old_rect
         return not bool(new_collisions - old_collisions)
 
+    def fix_bounds(self):
+        print "Killing", self, self.rect, self._float_pos
+        self.kill()
+
 
 class World(object):
 
     GRAVITY = 0.0, 9.8 * 80.0 # pixels / s^2
 
-    def __init__(self):
+    def __init__(self, bounds):
         self._all = pygame.sprite.LayeredUpdates()
         self._mobiles = pygame.sprite.Group()
         self._gravitators = pygame.sprite.Group()
@@ -182,6 +186,7 @@
         self._actors = pygame.sprite.Group()
         self._collision_groups = { None: pygame.sprite.Group() }
         self._last_time = None
+        self._bounds = bounds
 
     def freeze(self):
         self._last_time = None
@@ -264,6 +269,12 @@
         for sprite in self._mobiles:
             sprite.apply_friction()
 
+        # kill sprites outside the world
+        inbound = self._bounds.colliderect
+        for sprite in self._mobiles:
+            if not inbound(sprite):
+                sprite.fix_bounds()
+
         # position update and collision check (do last)
         for sprite in self._mobiles:
             sprite.deltap(dt)