changeset 348:7d4738347a9c

Hook up transformation
author Neil Muller <drnlmuller@gmail.com>
date Sat, 09 Apr 2011 13:30:44 +0200
parents e035f6951a91
children bc40be4ab5fc
files skaapsteker/levelscene.py skaapsteker/sprites/player.py
diffstat 2 files changed, 48 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/skaapsteker/levelscene.py	Sat Apr 09 13:28:24 2011 +0200
+++ b/skaapsteker/levelscene.py	Sat Apr 09 13:30:44 2011 +0200
@@ -1,7 +1,7 @@
 """Scene wrapping a level object."""
 
 from pygame.locals import (KEYDOWN, KEYUP, K_DOWN, K_ESCAPE, K_LEFT, K_RIGHT,
-                           K_SEMICOLON, K_UP, K_p, K_q, K_x, K_z, K_RETURN)
+                           K_SEMICOLON, K_UP, K_p, K_q, K_x, K_z, K_RETURN, K_c, K_j)
 
 import pygame
 import time
@@ -85,9 +85,11 @@
         if options['dvorak']:
             self._slow_key_map[K_SEMICOLON] = action('fire1')
             self._slow_key_map[K_q] = action('fire2')
+            self._slow_key_map[K_j] = action('transform')
         else:
             self._slow_key_map[K_x] = action('fire1')
             self._slow_key_map[K_z] = action('fire2')
+            self._slow_key_map[K_c] = action('transform')
             self._slow_key_map[K_q] = self._quit
 
         self._key_tap_map = {
--- a/skaapsteker/sprites/player.py	Sat Apr 09 13:28:24 2011 +0200
+++ b/skaapsteker/sprites/player.py	Sat Apr 09 13:30:44 2011 +0200
@@ -36,10 +36,12 @@
         self.sprinting = 0
         self.jumping = False
         self.flying = False
+        self.shape = 'fox'  # Needed so load image does the right thing
         self._load_images()
         self.inventory_image = None
         # We muck with these in load for convience, so ensure they're right
         self.the_world = the_world
+        self.shape = the_world.fox.shape
         self._me = the_world.fox
         self.set_facing('left')
         self.set_image()
@@ -190,7 +192,9 @@
         if self.facing != 'left':
             self.facing = 'left'
             self.set_image()
-        if self.sprinting > 0:
+        if self.shape != 'fox':
+            self.deltav((-300.0, 0.0))
+        elif self.sprinting > 0:
             self.sprinting = 1
             self.deltav((-900.0, 0.0))
         else:
@@ -212,11 +216,29 @@
     def action_double_up(self):
         pass
 
+    def action_transform(self):
+        """Transform the fox"""
+        if not self.on_solid:
+            return
+        if 'shapeshift' not in self.the_world.fox.tails:
+            return
+        if self.shape == 'fox':
+            # Become human
+            if self.the_world.fox.has_fan:
+                self.the_world.fox.shape = 'human_with_fan'
+            else:
+                self.the_world.fox.shape = 'human'
+        else:
+            self.the_world.fox.shape = 'fox'
+        self.shape = self.the_world.fox.shape
+
     def action_right(self):
         if self.facing != 'right':
             self.facing = 'right'
             self.set_image()
-        if self.sprinting > 0:
+        if self.shape != 'fox':
+            self.deltav((300.0, 0.0))
+        elif self.sprinting > 0:
             self.sprinting = 1  # Flag so stopping works
             self.deltav((900.0, 0.0))
         else:
@@ -224,7 +246,7 @@
 
 
     def action_up(self):
-        if self.on_solid:
+        if self.on_solid and self.shape == 'fox':
             self.deltav((0.0, -self.terminal_velocity[1]))
             self.on_solid = False
 
@@ -277,6 +299,12 @@
         return 'standing'
 
     def _make_key(self, tails, action=None):
+        if self.shape != 'fox':
+            # special logic for human shapes
+            if self.running:
+                return '%s_running_%s' % (self.shape, self.facing)
+            else:
+                return '%s_standing_%s' % (self.shape, self.facing)
         if action is None:
             action = self._get_action()
         if tails >= 4:
@@ -312,8 +340,20 @@
                             sprint_image = image.copy()
                             sprint_image.blit(shockwave, (0, 0))
                             self._image_dict[sprint_key].append(sprint_image)
-
-
+        for shape, name in [('human', 'disguise_'), ('human_with_fan', 'disguise-fan_')]:
+            directory = 'sprites/kitsune_disguise'
+            for facing in ['left', 'right']:
+                key = '%s_running_%s' % (shape, facing)
+                standing_key = '%s_standing_%s' % (shape, facing)
+                self._image_dict[key] = []
+                for image_file in get_files(directory):
+                    if name not in image_file:
+                        continue
+                    image = load_image('%s/%s' % (directory, image_file))
+                    if facing == 'right':
+                        image = pygame.transform.flip(image, True, False)
+                    self._image_dict[key].append(image)
+                self._image_dict[standing_key] = [self._image_dict[key][0]]
 
     def discard_item(self):
         self._me.item = None