Mercurial > rinkhals
comparison gamelib/gameboard.py @ 425:1d0cc37b4e14
Add method for clearing all chickens (will be useful later). Cache animal positions only just before night starts. Range-check position before adding it to the cache.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sat, 21 Nov 2009 15:55:32 +0000 |
parents | fbef17cab632 |
children | a356e57529ea |
comparison
equal
deleted
inserted
replaced
424:fbef17cab632 | 425:1d0cc37b4e14 |
---|---|
367 def start_night(self): | 367 def start_night(self): |
368 self.day, self.night = False, True | 368 self.day, self.night = False, True |
369 self.tv.sun(False) | 369 self.tv.sun(False) |
370 self.reset_states() | 370 self.reset_states() |
371 self.toolbar.update_fin_tool(self.day) | 371 self.toolbar.update_fin_tool(self.day) |
372 self._cache_animal_positions() | |
373 self.spawn_foxes() | 372 self.spawn_foxes() |
374 self.eggs = 0 | 373 self.eggs = 0 |
375 for chicken in self.chickens.copy(): | 374 for chicken in self.chickens.copy(): |
376 chicken.start_night(self) | 375 chicken.start_night(self) |
377 self.toolbar.update_egg_counter(self.eggs) | 376 self.toolbar.update_egg_counter(self.eggs) |
377 self._cache_animal_positions() | |
378 | 378 |
379 def start_day(self): | 379 def start_day(self): |
380 self.day, self.night = True, False | 380 self.day, self.night = True, False |
381 self.tv.sun(True) | 381 self.tv.sun(True) |
382 self.reset_states() | 382 self.reset_states() |
786 self.kill_fox(fox) | 786 self.kill_fox(fox) |
787 else: | 787 else: |
788 self.remove_fox(fox) | 788 self.remove_fox(fox) |
789 self.foxes = set() # Remove all the foxes | 789 self.foxes = set() # Remove all the foxes |
790 | 790 |
791 def clear_chickens(self): | |
792 for chicken in self.chickens.copy(): | |
793 self.remove_chicken(chicken) | |
794 | |
791 def run_animations(self): | 795 def run_animations(self): |
792 # For legacy. | 796 # For legacy. |
793 if self.toolbar.anim_clear_tool: | 797 if self.toolbar.anim_clear_tool: |
794 self.toolbar.clear_tool() | 798 self.toolbar.clear_tool() |
795 | 799 |
818 self._add_to_pos_cache(fox, 'fox') | 822 self._add_to_pos_cache(fox, 'fox') |
819 for chick in self.chickens: | 823 for chick in self.chickens: |
820 self._add_to_pos_cache(chick, 'chicken') | 824 self._add_to_pos_cache(chick, 'chicken') |
821 | 825 |
822 def _add_to_pos_cache(self, animal, cache_type): | 826 def _add_to_pos_cache(self, animal, cache_type): |
823 self._pos_cache[cache_type][animal.pos.x][animal.pos.y][animal.pos.z] = animal | 827 if self.in_bounds(animal.pos): |
828 self._pos_cache[cache_type][animal.pos.x][animal.pos.y][animal.pos.z] = animal | |
824 | 829 |
825 def _update_pos_cache(self, old_pos, animal, cache_type): | 830 def _update_pos_cache(self, old_pos, animal, cache_type): |
826 if self.in_bounds(old_pos) and self._pos_cache[cache_type]: | 831 if self.in_bounds(old_pos) and self._pos_cache[cache_type]: |
827 self._pos_cache[cache_type][old_pos.x][old_pos.y][old_pos.z] = None | 832 self._pos_cache[cache_type][old_pos.x][old_pos.y][old_pos.z] = None |
828 if animal: | 833 if animal: |