changeset 266:be516ca5e3b8

Add sprinting
author Neil Muller <drnlmuller@gmail.com>
date Fri, 08 Apr 2011 15:34:02 +0200
parents 7628467eecd9
children 3bee081ad4ac
files skaapsteker/sprites/player.py
diffstat 1 files changed, 44 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/skaapsteker/sprites/player.py	Fri Apr 08 15:06:24 2011 +0200
+++ b/skaapsteker/sprites/player.py	Fri Apr 08 15:34:02 2011 +0200
@@ -16,6 +16,8 @@
     collides_with = set([MONSTER_LAYER])
     wants_updates = True
 
+    _max_sprint_time = 2
+
     def __init__(self, the_world, soundsystem):
         Sprite.__init__(self)
         self.image = None
@@ -28,6 +30,7 @@
         # State flags and such
         self.attacking = 0
         self.running = False
+        self.sprinting = False
         self.jumping = False
         self.flying = False
         self._load_images()
@@ -91,6 +94,9 @@
                 # Force animation frame jump
                 self._animation_frame = old_frame + 1
                 self._last_time = time.time()
+        if self.sprinting:
+            if (time.time() - self._sprint_start_time) > self._max_sprint_time:
+                self.sprinting = False
         if abs(v_x) < 80:
             # Clamp when we're not moving at least 5 pixel / s
             self.velocity = (0, v_y)
@@ -174,13 +180,36 @@
         if self.facing != 'left':
             self.facing = 'left'
             self.set_image()
-        self.deltav((-450.0, 0.0))
+        if self.sprinting:
+            self.deltav((-900.0, 0.0))
+        else:
+            self.deltav((-450.0, 0.0))
+
+    def action_double_left(self):
+        # FIXME: Tie this to the tails
+        if self.sprinting:
+            return
+        self.sprinting = True
+        self._sprint_start_time = time.time()
+
+    def action_double_down(self):
+        print 'double down tap'
+
+    def action_double_right(self):
+        if self.sprinting:
+            return
+        self.sprinting = True
+        self._sprint_start_time = time.time()
 
     def action_right(self):
         if self.facing != 'right':
             self.facing = 'right'
             self.set_image()
-        self.deltav((450.0, 0.0))
+        if self.sprinting:
+            self.deltav((900.0, 0.0))
+        else:
+            self.deltav((450.0, 0.0))
+
 
     def action_up(self):
         if self.on_solid:
@@ -204,6 +233,8 @@
     def _get_action(self):
         if self.attacking:
             return 'attacking'
+        if self.sprinting and self.running:
+            return 'sprinting'
         if self.running:
             return 'running'
         if self.jumping:
@@ -232,9 +263,20 @@
                             # Skip extra junk for now
                             continue
                         image = load_image('%s/%s' % (directory, image_file))
+                        if action == 'running':
+                            sprint_key = self._make_key(tails, 'sprinting')
+                            if sprint_key not in self._image_dict:
+                                self._image_dict[sprint_key] = []
+                            shockwave = load_image('sprites/kitsune_shockwave.png')
+                            if facing == 'right':
+                                shockwave = pygame.transform.flip(shockwave, True, False)
                         if facing == 'right':
                             image = pygame.transform.flip(image, True, False)
                         self._image_dict[key].append(image)
+                        if action == 'running':
+                            sprint_image = image.copy()
+                            sprint_image.blit(shockwave, (0, 0))
+                            self._image_dict[sprint_key].append(sprint_image)
 
 
     def take_item(self, item):