Changeset 204:0f9715a2f07b


Ignore:
Timestamp:
04/06/11 20:49:25 (12 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Phase:
public
Rebase:
63333361303365303637373961653738636330366434396661356135306137393563333231643865
Message:

Make fire 1 do the attacking animation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/sprites/player.py

    r203 r204  
    2525        self._last_time = time.time()
    2626        # State flags and such
     27        self.attacking = 0
    2728        self.running = False
    2829        self.jumping = False
     
    4849        else:
    4950            cur_pos = (0, 0)
    50 
    5151        # TODO: can save a lot of calculation here by caching collision rects
    5252        cand_image = images[int(self._animation_frame)]
     
    5656        cand_rect.midbottom = cur_pos[0] + cand_rect_offset[0], cur_pos[1] + cand_rect_offset[1]
    5757        cand_collide_rect.midbottom = cur_pos
    58         if not self.check_collide_rect(cand_collide_rect, cand_rect, cand_image):
     58        # We always allow the attacking animation frames
     59        if not self.check_collide_rect(cand_collide_rect, cand_rect, cand_image) and not self.attacking:
    5960            return
    60 
    6161        self.image = cand_image
    6262        self.collide_rect = cand_collide_rect
     
    6868        v_x, v_y = self.velocity
    6969        # Never animate slower than !7 fps, never faster than ~15 fps
    70         old_frame = self._animation_frame
    71         self._animation_frame += abs(v_x) / 300
    72         time_diff = time.time() - self._last_time
    73         if int(self._animation_frame) - int(old_frame) > 0:
    74             # Check time diff
    75             if time_diff < 0.10:
    76                 # Delay animation frame jump
    77                 self._animation_frame -= abs(v_x) / 300
     70        if self.attacking > 0:
     71            if self._last_time:
     72                if time.time() - self._last_time > 0.15:
     73                    self._animation_frame += 1
     74                    self.attacking -= 1
     75                    self._last_time = time.time()
    7876            else:
    7977                self._last_time = time.time()
    80         elif time_diff > 0.20:
    81             # Force animation frame jump
    82             self._animation_frame = old_frame + 1
    83             self._last_time = time.time()
     78        else:
     79            old_frame = self._animation_frame
     80            self._animation_frame += abs(v_x) / 300
     81            time_diff = time.time() - self._last_time
     82            if int(self._animation_frame) - int(old_frame) > 0:
     83                # Check time diff
     84                if time_diff < 0.10:
     85                    # Delay animation frame jump
     86                    self._animation_frame -= abs(v_x) / 300
     87                else:
     88                    self._last_time = time.time()
     89            elif time_diff > 0.20:
     90                # Force animation frame jump
     91                self._animation_frame = old_frame + 1
     92                self._last_time = time.time()
    8493        if abs(v_x) < 80:
    8594            # Clamp when we're not moving at least 5 pixel / s
     
    166175
    167176    def action_fire1(self):
     177        if self.tails < 2:
     178            # Only have a bite attack
     179            print 'attacking'
     180            self.attacking = 2
    168181        print "F1"
    169182
     
    172185
    173186    def _get_action(self):
     187        if self.attacking:
     188            return 'attacking'
    174189        if self.running:
    175190            return 'running'
Note: See TracChangeset for help on using the changeset viewer.