Changeset 167:f7fb2ee24c70


Ignore:
Timestamp:
Apr 5, 2011, 10:03:03 PM (9 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Message:

Twiddle player animation behaviour

File:
1 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/sprites/player.py

    r160 r167  
    33import pygame.transform
    44import os
     5import time
    56
    67from skaapsteker.sprites.base import TILE_SIZE, PC_LAYER, MONSTER_LAYER
     
    2324        self._animation_frame = 0.0
    2425        self._recent_collisions = []
     26        self._last_time = time.time()
    2527        # State flags and such
    2628        self.running = False
     
    6163    def update(self):
    6264        v_x, v_y = self.velocity
    63         self._animation_frame += abs(v_x) / 3000.0
    64         if abs(v_x) < 10:
     65        # Never animate slower than !7 fps, never faster than ~15 fps
     66        old_frame = self._animation_frame
     67        self._animation_frame += abs(v_x) / 300
     68        time_diff = time.time() - self._last_time
     69        if int(self._animation_frame) - int(old_frame) > 0:
     70            # Check time diff
     71            if time_diff < 0.07:
     72                # Delay animation frame jump
     73                self._animation_frame -= abs(v_x) / 300
     74            else:
     75                self._last_time = time.time()
     76        elif time_diff > 0.15:
     77            # Force animation frame jump
     78            self._animation_frame = old_frame + 1
     79            self._last_time = time.time()
     80        if abs(v_x) < 80:
    6581            # Clamp when we're not moving at least 5 pixel / s
    6682            self.velocity = (0, v_y)
Note: See TracChangeset for help on using the changeset viewer.