view gamelib/equipment.py @ 97:529a4d41c67a

Rather use sound playing (we don't need to stream sound effects from disk), and cache sounds
author David Fraser <davidf@sjsoft.com>
date Wed, 02 Sep 2009 11:52:02 +0000
parents 5494af02a0e8
children f5d56688943b
line wrap: on
line source

"""Stuff for animals to use."""

import random

class Equipment(object):
    is_weapon = False

class Weapon(Equipment):
    is_weapon = True

    def in_range(self, gameboard, wielder, target):
        """Can the lucky wielder hit the potentially unlucky target with this?"""
        return False

    def hit(self, gameboard, wielder, target):
        """Is the potentially unlucky target actually unlucky?"""
        return False

class Rifle(Weapon):
    def in_range(self, gameboard, wielder, target):
        """For now, we ignore terrain and just assume we can hit
        anything that isn't too far away."""
        return wielder.pos.dist(target.pos) <= 3

    def hit(self, gameboard, wielder, target):
        """Closer is more accurate."""
        return random.randint(1, 100) > 60 + 10*wielder.pos.dist(target.pos)