Mercurial > skaapsteker
view skaapsteker/sprites/enemies.py @ 493:cb2060f8316f
Tweak gamestate to fail earlier on unknown items.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sat, 09 Apr 2011 22:41:38 +0200 |
parents | fc3b5460d454 |
children | b7f912705adb |
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): 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, direction): PatrollingOni.setup(self, direction) 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'