changeset 360:b4ead8d2b776

Add bounds checking to animation drawing loop
author Neil Muller <drnlmuller@gmail.com>
date Mon, 07 Sep 2009 11:20:52 +0000
parents 7bcdfb190f33
children d2acf43aba6f
files gamelib/gameboard.py
diffstat 1 files changed, 8 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/gameboard.py	Sun Sep 06 23:55:49 2009 +0000
+++ b/gamelib/gameboard.py	Mon Sep 07 11:20:52 2009 +0000
@@ -271,8 +271,11 @@
         us = []
         x, y = self.vid.view.x, self.vid.view.y
         for anim in self.gameboard.animations[:]:
-            if anim.updated or anim.removed:
+            if (anim.updated or anim.removed) and \
+                    self.gameboard.in_bounds(anim.pos):
                 # We flag that we need to redraw stuff undeneath the animation
+                anim.irect.x = anim.rect.x - anim.shape.x
+                anim.irect.y = anim.rect.y - anim.shape.y
                 us.append(pygame.Rect(anim.irect.x - x, anim.irect.y - y,
                     anim.irect.width, anim.irect.height))
                 self.vid.alayer[anim.pos.y][anim.pos.x]=1
@@ -282,15 +285,12 @@
                 self.gameboard.animations.remove(anim)
         us.extend(self.vid.update(surface))
         for anim in self.gameboard.animations:
-            if anim.updated: 
-                anim.fix_pos(self.vid)
+            if anim.updated:
                 # setimage has happened, so redraw
-                anim.irect.x = anim.rect.x - anim.shape.x
-                anim.irect.y = anim.rect.y - anim.shape.y
-                surface.blit(anim.image, (anim.irect.x - x, anim.irect.y - y))
                 anim.updated = 0
-                us.append(pygame.Rect(anim.irect.x - x, anim.irect.y - y,
-                    anim.irect.width, anim.irect.height))
+                anim.fix_pos(self.vid)
+                if self.gameboard.in_bounds(anim.pos): 
+                    surface.blit(anim.image, (anim.irect.x - x, anim.irect.y - y))
                 # This is enough, because sprite changes happen disjoint
                 # from the animation sequence, so we don't need to worry
                 # other changes forcing us to redraw the animation frame.