Changeset 241:1a7000c8211c


Ignore:
Timestamp:
Sep 5, 2009, 11:19:26 AM (11 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@242
Message:

Demolition foxes, including better fox selection.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • TODO

    r222 r241  
    1616
    1717* Animations? (Fox catching chicken (with feathers), demolition foxes blowing things up?)
    18 
    19 * Add the demolition fox
    2018
    2119* <confluence> We should have text images instead of buttons (in the various menus and toolbars).
  • gamelib/animal.py

    r236 r241  
    1111import sound
    1212import equipment
     13import animations
    1314
    1415class Animal(Sprite):
     
    370371            self.landmarks.append(final_pos)
    371372        elif tiles.TILE_MAP[this_tile] == 'fence' and not self.dig_pos:
    372             self._dig(final_pos)
     373            self._dig(gameboard, final_pos)
    373374            return self.pos
    374375        self.last_steps.append(final_pos)
     
    377378        return final_pos
    378379
    379     def _dig(self, dig_pos):
     380    def _dig(self, gameboard, dig_pos):
    380381        """Setup dig parameters, to be overridden if needed"""
    381382        self.tick = 5
     
    423424    """Demolition Foxes destroy fences easily"""
    424425
     426    DIG_ANIMATION = animations.FenceExplosion
     427    IMAGE_FILE = 'sprites/sapper_fox.png'
     428
     429    def _dig(self, gameboard, dig_pos):
     430        """Setup dig parameters, to be overridden if needed"""
     431        self.tick = 0 # Costs us nothing to go through a fence.
     432        self.dig_pos = dig_pos
     433        gameboard.animations.append(self.DIG_ANIMATION(dig_pos))
     434        self._make_hole(gameboard)
     435
    425436class GreedyFox(Fox):
    426437    """Greedy foxes eat more chickens"""
  • gamelib/animations.py

    r237 r241  
    5757            Animation.__init__(self, self.SEQUENCE_LEFT, chicken.pos)
    5858
     59class FenceExplosion(Animation):
     60
     61    FLASH_LEFT = imagecache.load_image('sprites/muzzle_flash.png')
     62    FLASH_RIGHT = imagecache.load_image('sprites/muzzle_flash.png',
     63            ("right_facing",))
     64
     65    SEQUENCE = [FLASH_LEFT, FLASH_RIGHT, FLASH_LEFT, FLASH_RIGHT]
     66
     67    def __init__(self, fencetile):
     68        Animation.__init__(self, self.SEQUENCE, fencetile)
     69
  • gamelib/gameboard.py

    r239 r241  
    1515import cursors
    1616import sprite_cursor
     17import misc
    1718
    1819class OpaqueLabel(gui.Label):
     
    207208    WOODLAND = tiles.REVERSE_TILE_MAP['woodland']
    208209    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        )
    209217
    210218    def __init__(self, main_app):
     
    814822            x += 1
    815823
     824    def _choose_fox(self, (x, y)):
     825        fox_cls = misc.WeightedSelection(self.FOX_WEIGHTINGS).choose()
     826        return fox_cls((x, y))
     827
    816828    def spawn_foxes(self):
    817829        """The foxes come at night, and this is where they come from."""
     
    844856                    break
    845857            if not skip:
    846                 roll = random.randint(0, 10)
    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)
     858                self.add_fox(self._choose_fox((x, y)))
    854859
    855860    def fix_buildings(self):
  • gamelib/misc.py

    r107 r241  
    11# Holder for misc useful classes
     2
     3import random
    24
    35class Position(object):
     
    3032    def __eq__(self, b):
    3133        return self.x == b.x and self.y == b.y
     34
     35class WeightedSelection(object):
     36    def __init__(self, weightings=None):
     37        self.weightings = []
     38        self.total = 0
     39        if weightings:
     40            for item, weight in weightings:
     41                self.weightings.append((item, weight))
     42                self.total += weight
     43       
     44    def choose(self):
     45        roll = random.uniform(0, self.total)
     46        for item, weight in self.weightings:
     47            if roll < weight:
     48                return item
     49            roll -= weight
Note: See TracChangeset for help on using the changeset viewer.