Mercurial > rinkhals
comparison gamelib/gameboard.py @ 73:f3ce3346e25e
Spawn foxes jsut outside the map
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Mon, 31 Aug 2009 22:44:37 +0000 |
parents | 18db99fda6bd |
children | 65958516c7d9 |
comparison
equal
deleted
inserted
replaced
72:aa4bd93575d9 | 73:f3ce3346e25e |
---|---|
7 import data | 7 import data |
8 import tiles | 8 import tiles |
9 import constants | 9 import constants |
10 import buildings | 10 import buildings |
11 import animal | 11 import animal |
12 from misc import Position | |
13 | 12 |
14 class OpaqueLabel(gui.Label): | 13 class OpaqueLabel(gui.Label): |
15 def paint(self, s): | 14 def paint(self, s): |
16 s.fill(self.style.background) | 15 s.fill(self.style.background) |
17 gui.Label.paint(self, s) | 16 gui.Label.paint(self, s) |
297 self.add_chicken(chick) | 296 self.add_chicken(chick) |
298 x += 1 | 297 x += 1 |
299 | 298 |
300 def spawn_foxes(self): | 299 def spawn_foxes(self): |
301 """The foxes come at night, and this is where they come from.""" | 300 """The foxes come at night, and this is where they come from.""" |
302 # Very simple, we walk around the tilemap, and, for each farm tile, | 301 # Foxes spawn just outside the map |
303 # we randomly add a chicken (1 in 10 chance) until we have 5 chickens | |
304 # or we run out of board | |
305 x, y = 0, 0 | 302 x, y = 0, 0 |
306 width, height = self.tv.size | 303 width, height = self.tv.size |
307 new_foxes = random.randint(3, 7) | 304 new_foxes = random.randint(3, 7) |
308 while len(self.foxes) < new_foxes: | 305 while len(self.foxes) < new_foxes: |
309 if x < width: | 306 side = random.randint(0, 3) |
310 tile = self.tv.get((x, y)) | 307 if side == 0: |
308 # top | |
309 y = -1 | |
310 x = random.randint(-1, width) | |
311 elif side == 1: | |
312 # bottom | |
313 y = height | |
314 x = random.randint(-1, width) | |
315 elif side == 2: | |
316 # left | |
317 x = -1 | |
318 y = random.randint(-1, height) | |
311 else: | 319 else: |
312 y += 1 | 320 x = width |
313 if y >= height: | 321 y = random.randint(-1, height) |
322 skip = False | |
323 for other_fox in self.foxes: | |
324 if other_fox.pos.x == x and other_fox.pos.y == y: | |
325 skip = True # Choose a new position | |
314 break | 326 break |
315 x = 0 | 327 if not skip: |
316 continue | 328 fox = animal.Fox((x, y)) |
317 # See if we place a fox | 329 self.add_fox(fox) |
318 if tiles.TILE_MAP[tile] == 'woodland': | |
319 # Forest | |
320 roll = random.randint(1, 20) | |
321 if roll == 1: | |
322 # Create a fox | |
323 fox = animal.Fox((x, y)) | |
324 self.add_fox(fox) | |
325 x += 5 | |
326 | 330 |
327 def fix_buildings(self): | 331 def fix_buildings(self): |
328 """Go through the level map looking for buildings that haven't | 332 """Go through the level map looking for buildings that haven't |
329 been added to self.buildings and adding them. | 333 been added to self.buildings and adding them. |
330 | 334 |