comparison gamelib/gameboard.py @ 241:1a7000c8211c

Demolition foxes, including better fox selection.
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 05 Sep 2009 11:19:26 +0000
parents 8224d1ac99c7
children 4f86c2616cdf
comparison
equal deleted inserted replaced
240:af19d6fdc1f8 241:1a7000c8211c
12 import animal 12 import animal
13 import equipment 13 import equipment
14 import sound 14 import sound
15 import cursors 15 import cursors
16 import sprite_cursor 16 import sprite_cursor
17 import misc
17 18
18 class OpaqueLabel(gui.Label): 19 class OpaqueLabel(gui.Label):
19 def __init__(self, value, **params): 20 def __init__(self, value, **params):
20 gui.Label.__init__(self, value, **params) 21 gui.Label.__init__(self, value, **params)
21 if 'width' in params: 22 if 'width' in params:
204 205
205 GRASSLAND = tiles.REVERSE_TILE_MAP['grassland'] 206 GRASSLAND = tiles.REVERSE_TILE_MAP['grassland']
206 FENCE = tiles.REVERSE_TILE_MAP['fence'] 207 FENCE = tiles.REVERSE_TILE_MAP['fence']
207 WOODLAND = tiles.REVERSE_TILE_MAP['woodland'] 208 WOODLAND = tiles.REVERSE_TILE_MAP['woodland']
208 BROKEN_FENCE = tiles.REVERSE_TILE_MAP['broken fence'] 209 BROKEN_FENCE = tiles.REVERSE_TILE_MAP['broken fence']
210
211 FOX_WEIGHTINGS = (
212 (animal.Fox, 60),
213 (animal.GreedyFox, 30),
214 (animal.NinjaFox, 5),
215 (animal.DemoFox, 5),
216 )
209 217
210 def __init__(self, main_app): 218 def __init__(self, main_app):
211 self.disp = main_app 219 self.disp = main_app
212 self.tv = tiles.FarmVid() 220 self.tv = tiles.FarmVid()
213 self.tv.tga_load_tiles(data.filepath('tiles.tga'), self.TILE_DIMENSIONS) 221 self.tv.tga_load_tiles(data.filepath('tiles.tga'), self.TILE_DIMENSIONS)
811 # Create a chicken 819 # Create a chicken
812 chick = animal.Chicken((x, y)) 820 chick = animal.Chicken((x, y))
813 self.add_chicken(chick) 821 self.add_chicken(chick)
814 x += 1 822 x += 1
815 823
824 def _choose_fox(self, (x, y)):
825 fox_cls = misc.WeightedSelection(self.FOX_WEIGHTINGS).choose()
826 return fox_cls((x, y))
827
816 def spawn_foxes(self): 828 def spawn_foxes(self):
817 """The foxes come at night, and this is where they come from.""" 829 """The foxes come at night, and this is where they come from."""
818 # Foxes spawn just outside the map 830 # Foxes spawn just outside the map
819 x, y = 0, 0 831 x, y = 0, 0
820 width, height = self.tv.size 832 width, height = self.tv.size
841 for other_fox in self.foxes: 853 for other_fox in self.foxes:
842 if other_fox.pos.x == x and other_fox.pos.y == y: 854 if other_fox.pos.x == x and other_fox.pos.y == y:
843 skip = True # Choose a new position 855 skip = True # Choose a new position
844 break 856 break
845 if not skip: 857 if not skip:
846 roll = random.randint(0, 10) 858 self.add_fox(self._choose_fox((x, y)))
847 if roll < 8:
848 fox = animal.Fox((x, y))
849 elif roll < 9:
850 fox = animal.NinjaFox((x, y))
851 else:
852 fox = animal.GreedyFox((x, y))
853 self.add_fox(fox)
854 859
855 def fix_buildings(self): 860 def fix_buildings(self):
856 """Go through the level map looking for buildings that haven't 861 """Go through the level map looking for buildings that haven't
857 been added to self.buildings and adding them. 862 been added to self.buildings and adding them.
858 863