changeset 408:bbfc2cc07ba4

Add invisibility power.
author Simon Cross <hodgestar@gmail.com>
date Sat, 09 Apr 2011 17:23:07 +0200
parents d97840ee6759
children ed26bbfec03a 5f896e2f78c4
files skaapsteker/levelscene.py skaapsteker/sprites/player.py
diffstat 2 files changed, 26 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/skaapsteker/levelscene.py	Sat Apr 09 17:18:11 2011 +0200
+++ b/skaapsteker/levelscene.py	Sat Apr 09 17:23:07 2011 +0200
@@ -2,7 +2,7 @@
 
 from pygame.locals import (KEYDOWN, KEYUP, K_DOWN, K_ESCAPE, K_LEFT, K_RIGHT,
                            K_SEMICOLON, K_UP, K_c, K_j, K_p, K_q, K_x, K_z,
-                           K_RETURN, SRCALPHA)
+                           K_v, K_k, K_RETURN, SRCALPHA)
 
 import pygame
 import time
@@ -90,10 +90,12 @@
             self._slow_key_map[K_SEMICOLON] = action('fire1')
             self._slow_key_map[K_q] = action('fire2')
             self._slow_key_map[K_j] = action('transform')
+            self._slow_key_map[K_k] = action('invisible')
         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_v] = action('invisible')
             self._slow_key_map[K_q] = self._quit
 
         self._key_tap_map = {
--- a/skaapsteker/sprites/player.py	Sat Apr 09 17:18:11 2011 +0200
+++ b/skaapsteker/sprites/player.py	Sat Apr 09 17:23:07 2011 +0200
@@ -10,6 +10,8 @@
 from ..data import get_files, load_image
 from ..engine import PlayerDied, AddSpriteEvent, OpenNotification
 
+from pygame.constants import BLEND_RGBA_MULT
+
 
 class Player(Sprite):
 
@@ -30,13 +32,15 @@
         self._animation_frame = 0.0
         self._last_time = time.time()
         self._last_fired = time.time()
+        self._inv_cache = {}
         # State flags and such
         self.attacking = 0
         self.running = False
         self.sprinting = 0
         self.jumping = False
-        self.flying = False
+        self.flying = 0
         self.prep_flight = 0.0
+        self.invisible = 0
         self.shape = 'fox'  # Needed so load image does the right thing
         self._load_images()
         self.inventory_image = None
@@ -70,6 +74,14 @@
         # We always allow the attacking animation frames
         if not self.check_collide_rect(cand_collide_rect, cand_rect, cand_image) and not self.attacking:
             return False
+        if self.invisible > 0:
+            id_cand_image = id(cand_image)
+            if id_cand_image in self._inv_cache:
+                cand_image = self._inv_cache[id_cand_image]
+            else:
+                cand_image = cand_image.copy()
+                cand_image.fill((0, 0, 0, 140), None, BLEND_RGBA_MULT)
+                self._inv_cache[id_cand_image] = cand_image
         self.image = cand_image
         self.collide_rect = cand_collide_rect
         self.rect = cand_rect
@@ -111,7 +123,9 @@
         if self.flying > 0:
             if (now - self._flight_start_time) > self._max_flight_time:
                 self.flying = 0
-            # v_y = 0 # Standard platformer flying
+        if self.invisible > 0:
+            if (now - self._invisibility_start_time) > self._max_invisibility_time:
+                self.invisible = 0
         if abs(v_x) < 80:
             # Clamp when we're not moving at least 5 pixel / s
             self.velocity = (0, v_y)
@@ -227,6 +241,13 @@
         self._max_flight_time = float(len(self._me.tails))
         self._flight_start_time = time.time()
 
+    def action_invisible(self):
+        if self.invisible > 0 or 'invisibility' not in self._me.tails:
+            return
+        self.invisible = 1
+        self._max_invisibility_time = float(len(self._me.tails))
+        self._invisibility_start_time = time.time()
+
     def action_transform(self):
         """Transform the fox"""
         if not self.on_solid: