comparison gamelib/gameboard.py @ 380:1586eccdefe4

Ripped out legacy animation infrastructure in favour of layered sprites.
author Jeremy Thurgood <firxen@gmail.com>
date Sun, 25 Oct 2009 10:56:01 +0000
parents a8a7ada27fa2
children 7a58dadfd251
comparison
equal deleted inserted replaced
379:a8a7ada27fa2 380:1586eccdefe4
251 self.vid = vid 251 self.vid = vid
252 self.vid.bounds = pygame.Rect((0, 0), vid.tile_to_view(vid.size)) 252 self.vid.bounds = pygame.Rect((0, 0), vid.tile_to_view(vid.size))
253 253
254 def paint(self, surface): 254 def paint(self, surface):
255 self.vid.paint(surface) 255 self.vid.paint(surface)
256 # Blit animation frames on top of the drawing
257 x, y = self.vid.view.x, self.vid.view.y
258 for anim in self.gameboard.animations:
259 anim.fix_pos(self.vid)
260 anim.irect.x = anim.rect.x - anim.shape.x
261 anim.irect.y = anim.rect.y - anim.shape.y
262 surface.blit(anim.image, (anim.irect.x - x, anim.irect.y - y))
263 # We don't store anim._irect, since we only update anims if the
264 # image changes, which kills irect
265 256
266 def update(self, surface): 257 def update(self, surface):
267 us = [] 258 return self.vid.update(surface)
268 x, y = self.vid.view.x, self.vid.view.y
269 for anim in self.gameboard.animations[:]:
270 if (anim.updated or anim.removed) and \
271 self.gameboard.in_bounds(anim.pos):
272 # We flag that we need to redraw stuff undeneath the animation
273 anim.irect.x = anim.rect.x - anim.shape.x
274 anim.irect.y = anim.rect.y - anim.shape.y
275 us.append(pygame.Rect(anim.irect.x - x, anim.irect.y - y,
276 anim.irect.width, anim.irect.height))
277 self.vid.alayer[anim.pos.y][anim.pos.x]=1
278 self.vid.updates.append(anim.pos.to_tuple())
279 if anim.removed:
280 # Remove the animation from the draw loop
281 self.gameboard.animations.remove(anim)
282 us.extend(self.vid.update(surface))
283 for anim in self.gameboard.animations:
284 if anim.updated:
285 # setimage has happened, so redraw
286 anim.updated = 0
287 anim.fix_pos(self.vid)
288 if self.gameboard.in_bounds(anim.pos):
289 surface.blit(anim.image, (anim.irect.x - x, anim.irect.y - y))
290 # This is enough, because sprite changes happen disjoint
291 # from the animation sequence, so we don't need to worry
292 # other changes forcing us to redraw the animation frame.
293 return us
294 259
295 def move_view(self, x, y): 260 def move_view(self, x, y):
296 self.vid.view.move_ip((x, y)) 261 self.vid.view.move_ip((x, y))
297 262
298 def event(self, e): 263 def event(self, e):
335 self.animal_to_place = None 300 self.animal_to_place = None
336 self.sprite_cursor = None 301 self.sprite_cursor = None
337 self.chickens = set() 302 self.chickens = set()
338 self.foxes = set() 303 self.foxes = set()
339 self.buildings = [] 304 self.buildings = []
340 self.animations = []
341 self.cash = 0 305 self.cash = 0
342 self.eggs = 0 306 self.eggs = 0
343 self.days = 0 307 self.days = 0
344 self.killed_foxes = 0 308 self.killed_foxes = 0
345 self.add_cash(constants.STARTING_CASH) 309 self.add_cash(constants.STARTING_CASH)
824 else: 788 else:
825 self.tv.sprites.remove(fox) 789 self.tv.sprites.remove(fox)
826 self.foxes = set() # Remove all the foxes 790 self.foxes = set() # Remove all the foxes
827 791
828 def run_animations(self): 792 def run_animations(self):
829 for anim in self.animations: 793 # For legacy.
830 anim.animate()
831 if self.toolbar.anim_clear_tool: 794 if self.toolbar.anim_clear_tool:
832 self.toolbar.clear_tool() 795 self.toolbar.clear_tool()
833 796
834 def move_foxes(self): 797 def move_foxes(self):
835 """Move the foxes. 798 """Move the foxes.