Mercurial > skaapsteker
view skaapsteker/sprites/enemies.py @ 549:b7f912705adb
Fishmonger now mongers fish.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sun, 10 Apr 2011 01:14:14 +0200 |
parents | fc3b5460d454 |
children | 0675f390653c |
line wrap: on
line source
from base import Monster, PatrollingMonster from pygame import transform class RedOni(Monster): image_dir = 'sprites/oni red' attack_frame = 1 attack_damage = 10 frame_pause = 0.05 # Fast attacks facings = { 'running' : (('left', None), ('right', lambda x: transform.flip(x, True, False))), 'attacking' : (('left', None), ('right', lambda x: transform.flip(x, True, False))), } def setup(self, direction, **opts): super(RedOni, self).setup(**opts) self.facing = direction def start_attack(self, player): if self._animation != 'attacking': # Turn to face the player we're attacking if player.collide_rect.centerx > self.collide_rect.centerx: self.facing = 'right' else: self.facing = 'left' Monster.start_attack(self, player) class FireballOni(RedOni): pass # TODO class PatrollingOni(RedOni, PatrollingMonster): image_dir = 'sprites/oni blue' class FlyingOni(PatrollingOni): image_dir = 'sprites/oni gold' gravitates = False patrol_velocity = (0, 200) def setup(self, **opts): super(PatrollingOni, self).setup(**opts) self.heading = 'up' def update(self): PatrollingOni.update(self) if self._animation == 'running': if self.heading == 'up': self.velocity = (0, -self.patrol_velocity[1]) else: self.velocity = (0, self.patrol_velocity[1]) def check_floors(self, floors): pass def collided(self, other): if not other.block or not other.floor: return if other.collide_rect.bottom < self.collide_rect.bottom: # We're colliding with something above us if self.heading == 'up': self.change_facing() else: if self.heading == 'down': self.change_facing() def change_facing(self): if self.heading == 'up': self.heading = 'down' else: self.heading = 'up'