comparison gamelib/gameboard.py @ 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 e61f95503461
children d2acf43aba6f
comparison
equal deleted inserted replaced
359:7bcdfb190f33 360:b4ead8d2b776
269 269
270 def update(self, surface): 270 def update(self, surface):
271 us = [] 271 us = []
272 x, y = self.vid.view.x, self.vid.view.y 272 x, y = self.vid.view.x, self.vid.view.y
273 for anim in self.gameboard.animations[:]: 273 for anim in self.gameboard.animations[:]:
274 if anim.updated or anim.removed: 274 if (anim.updated or anim.removed) and \
275 self.gameboard.in_bounds(anim.pos):
275 # We flag that we need to redraw stuff undeneath the animation 276 # We flag that we need to redraw stuff undeneath the animation
277 anim.irect.x = anim.rect.x - anim.shape.x
278 anim.irect.y = anim.rect.y - anim.shape.y
276 us.append(pygame.Rect(anim.irect.x - x, anim.irect.y - y, 279 us.append(pygame.Rect(anim.irect.x - x, anim.irect.y - y,
277 anim.irect.width, anim.irect.height)) 280 anim.irect.width, anim.irect.height))
278 self.vid.alayer[anim.pos.y][anim.pos.x]=1 281 self.vid.alayer[anim.pos.y][anim.pos.x]=1
279 self.vid.updates.append(anim.pos.to_tuple()) 282 self.vid.updates.append(anim.pos.to_tuple())
280 if anim.removed: 283 if anim.removed:
281 # Remove the animation from the draw loop 284 # Remove the animation from the draw loop
282 self.gameboard.animations.remove(anim) 285 self.gameboard.animations.remove(anim)
283 us.extend(self.vid.update(surface)) 286 us.extend(self.vid.update(surface))
284 for anim in self.gameboard.animations: 287 for anim in self.gameboard.animations:
285 if anim.updated: 288 if anim.updated:
289 # setimage has happened, so redraw
290 anim.updated = 0
286 anim.fix_pos(self.vid) 291 anim.fix_pos(self.vid)
287 # setimage has happened, so redraw 292 if self.gameboard.in_bounds(anim.pos):
288 anim.irect.x = anim.rect.x - anim.shape.x 293 surface.blit(anim.image, (anim.irect.x - x, anim.irect.y - y))
289 anim.irect.y = anim.rect.y - anim.shape.y
290 surface.blit(anim.image, (anim.irect.x - x, anim.irect.y - y))
291 anim.updated = 0
292 us.append(pygame.Rect(anim.irect.x - x, anim.irect.y - y,
293 anim.irect.width, anim.irect.height))
294 # This is enough, because sprite changes happen disjoint 294 # This is enough, because sprite changes happen disjoint
295 # from the animation sequence, so we don't need to worry 295 # from the animation sequence, so we don't need to worry
296 # other changes forcing us to redraw the animation frame. 296 # other changes forcing us to redraw the animation frame.
297 return us 297 return us
298 298