Changeset 416:3db2fc263d11


Ignore:
Timestamp:
04/09/11 15:42:20 (12 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Phase:
public
Rebase:
37656137343032313537346236353965633236633463363366356433353262663864646630396561
Message:

Kill sprites that leave the level area.

Location:
skaapsteker
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/levelscene.py

    r411 r416  
    3535        self._level_surface = self._level.get_surface()
    3636        self._clip_rect = None
    37         self._world = physics.World()
     37        self._world = physics.World(self._level_surface.get_rect())
    3838        self._paused = False
    3939
  • skaapsteker/physics.py

    r401 r416  
    169169        return not bool(new_collisions - old_collisions)
    170170
     171    def fix_bounds(self):
     172        print "Killing", self, self.rect, self._float_pos
     173        self.kill()
     174
    171175
    172176class World(object):
     
    174178    GRAVITY = 0.0, 9.8 * 80.0 # pixels / s^2
    175179
    176     def __init__(self):
     180    def __init__(self, bounds):
    177181        self._all = pygame.sprite.LayeredUpdates()
    178182        self._mobiles = pygame.sprite.Group()
     
    183187        self._collision_groups = { None: pygame.sprite.Group() }
    184188        self._last_time = None
     189        self._bounds = bounds
    185190
    186191    def freeze(self):
     
    264269        for sprite in self._mobiles:
    265270            sprite.apply_friction()
     271
     272        # kill sprites outside the world
     273        inbound = self._bounds.colliderect
     274        for sprite in self._mobiles:
     275            if not inbound(sprite):
     276                sprite.fix_bounds()
    266277
    267278        # position update and collision check (do last)
Note: See TracChangeset for help on using the changeset viewer.