Changeset 120:9b08afeadf06


Ignore:
Timestamp:
Apr 4, 2011, 8:11:33 PM (9 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Message:

Animated running.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/sprites/player.py

    r116 r120  
    2020        self.image = None
    2121        self._image_dict = {}
     22        self._animation_frame = 0.0
    2223        # State flags and such
    2324        self.running = False
     
    3435    def set_image(self):
    3536        key = self._make_key()
    36         # TODO: handle animations
    37         self.image = self._image_dict[key][0]
     37        images = self._image_dict[key]
     38        if self._animation_frame >= len(images):
     39            self._animation_frame = 0.0
     40        self.image = images[int(self._animation_frame)]
    3841
    3942    def update(self):
    40         pass # animate tail here
     43        v_x, v_y = self.velocity
     44        self._animation_frame += abs(v_x) / 3000.0
     45        if v_x == 0:
     46            self.running = False
     47        else:
     48            self.running = True
     49        self.set_image()
    4150
    4251    def set_facing(self, new_facing):
     
    108117                            image = pygame.transform.flip(image, True, False)
    109118                        self._image_dict[key].append(image)
    110 
    111 
Note: See TracChangeset for help on using the changeset viewer.