Changeset 408:bbfc2cc07ba4


Ignore:
Timestamp:
04/09/11 15:23:07 (12 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Children:
409:ed26bbfec03a, 413:5f896e2f78c4
Phase:
public
Rebase:
37653631326362666131636166653765356335313962396365366336366438656233316632666135
Message:

Add invisibility power.

Location:
skaapsteker
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/levelscene.py

    r407 r408  
    33from pygame.locals import (KEYDOWN, KEYUP, K_DOWN, K_ESCAPE, K_LEFT, K_RIGHT,
    44                           K_SEMICOLON, K_UP, K_c, K_j, K_p, K_q, K_x, K_z,
    5                            K_RETURN, SRCALPHA)
     5                           K_v, K_k, K_RETURN, SRCALPHA)
    66
    77import pygame
     
    9191            self._slow_key_map[K_q] = action('fire2')
    9292            self._slow_key_map[K_j] = action('transform')
     93            self._slow_key_map[K_k] = action('invisible')
    9394        else:
    9495            self._slow_key_map[K_x] = action('fire1')
    9596            self._slow_key_map[K_z] = action('fire2')
    9697            self._slow_key_map[K_c] = action('transform')
     98            self._slow_key_map[K_v] = action('invisible')
    9799            self._slow_key_map[K_q] = self._quit
    98100
  • skaapsteker/sprites/player.py

    r398 r408  
    1010from ..data import get_files, load_image
    1111from ..engine import PlayerDied, AddSpriteEvent, OpenNotification
     12
     13from pygame.constants import BLEND_RGBA_MULT
    1214
    1315
     
    3133        self._last_time = time.time()
    3234        self._last_fired = time.time()
     35        self._inv_cache = {}
    3336        # State flags and such
    3437        self.attacking = 0
     
    3639        self.sprinting = 0
    3740        self.jumping = False
    38         self.flying = False
     41        self.flying = 0
    3942        self.prep_flight = 0.0
     43        self.invisible = 0
    4044        self.shape = 'fox'  # Needed so load image does the right thing
    4145        self._load_images()
     
    7175        if not self.check_collide_rect(cand_collide_rect, cand_rect, cand_image) and not self.attacking:
    7276            return False
     77        if self.invisible > 0:
     78            id_cand_image = id(cand_image)
     79            if id_cand_image in self._inv_cache:
     80                cand_image = self._inv_cache[id_cand_image]
     81            else:
     82                cand_image = cand_image.copy()
     83                cand_image.fill((0, 0, 0, 140), None, BLEND_RGBA_MULT)
     84                self._inv_cache[id_cand_image] = cand_image
    7385        self.image = cand_image
    7486        self.collide_rect = cand_collide_rect
     
    112124            if (now - self._flight_start_time) > self._max_flight_time:
    113125                self.flying = 0
    114             # v_y = 0 # Standard platformer flying
     126        if self.invisible > 0:
     127            if (now - self._invisibility_start_time) > self._max_invisibility_time:
     128                self.invisible = 0
    115129        if abs(v_x) < 80:
    116130            # Clamp when we're not moving at least 5 pixel / s
     
    228242        self._flight_start_time = time.time()
    229243
     244    def action_invisible(self):
     245        if self.invisible > 0 or 'invisibility' not in self._me.tails:
     246            return
     247        self.invisible = 1
     248        self._max_invisibility_time = float(len(self._me.tails))
     249        self._invisibility_start_time = time.time()
     250
    230251    def action_transform(self):
    231252        """Transform the fox"""
Note: See TracChangeset for help on using the changeset viewer.