Changeset 236:9528c6fc7f75


Ignore:
Timestamp:
04/07/11 10:38:45 (12 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Phase:
public
Message:

Hook up attack anaimation (needs facing support still)

Location:
skaapsteker/sprites
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/sprites/base.py

    r228 r236  
    4040        ("running", r"^.*_\d+.png$"),
    4141        ("standing", r"^.*_standing.png$"),
     42        ("attacking", r"^.*_attacking.png$"),
    4243    ]
    4344
     
    7778        cand_collide_rect.midbottom = cur_pos
    7879
    79         if not self.check_collide_rect(cand_collide_rect, cand_rect, cand_image):
     80        if not self.check_collide_rect(cand_collide_rect, cand_rect, cand_image) and not self._animation == 'attacking':
    8081            return
    8182
     
    9495
    9596
    96 class Monster(GameSprite):
     97class Monster(AnimatedGameSprite):
    9798
    9899    collision_layer = MONSTER_LAYER
     
    103104    block = True
    104105
    105     def __init__(self, pos, **opts):
    106         GameSprite.__init__(self, pos, **opts)
     106    attack_frame = None  # Mark a spefici frame in the animatio n as when the attack lands
     107    attack_damage = 1
     108
     109    def __init__(self, pos, **opts):
     110        AnimatedGameSprite.__init__(self, pos, **opts)
    107111        self.floor_rect = Rect(self.collide_rect.topleft, (self.collide_rect.width, 2))
    108112        self._layer = Layers.PLAYER
     
    113117    def collided_player(self, player):
    114118        print "%s collided with player" % self
    115         player.damage(1)
     119        self.start_attack(player)
     120
     121    def update(self):
     122        AnimatedGameSprite.update(self)
     123        if self._animation == 'attacking':
     124            if self._frame == 0 and self._tick == 1:
     125                # FIXME: This will need to change when AnimatedGameSprite changes
     126                # We've just looped through the animation sequence
     127                self._animation = self._old_state
     128            elif self._frame == self.attack_frame and self._tick == 5:
     129                # Attack the player
     130                self.do_attack()
     131
     132    def do_attack(self):
     133        """Overriden by monster classes"""
     134        if self.check_collides(self._target):
     135            self._target.damage(self.attack_damage)
     136
     137    def start_attack(self, player):
     138        if self._animation == 'attacking':
     139            return # We're already attacking
     140        elif self.attack_frame is not None:
     141            self._target = player
     142            self._old_state = self._animation
     143            self._animation = 'attacking'
     144            self._tick = 1
     145            self._frame = 0  # Start the attack from the beginning
     146        else:
     147            player.damage(1)  # collision damage
    116148
    117149    def damage(self, damage):
  • skaapsteker/sprites/enemies.py

    r202 r236  
    33
    44class Dummy(Monster):
    5     image_file = 'oni red/oni-red-01.png'
     5    image_dir = 'sprites/oni red'
     6
     7    attack_frame = 1
     8    attack_damage = 10
    69
    710    def setup(self, direction):
Note: See TracChangeset for help on using the changeset viewer.