# HG changeset patch # User Adrianna PiƄska # Date 1302353613 -7200 # Node ID 92cf515a6cf6a3cfb09a7ab6a7930df69b66b165 # Parent f14621568fb6eea858d210b5ddee2189ceb9234c# Parent 249ba3bd6904a4254903e08fb9d654d08a188087 merge diff -r f14621568fb6 -r 92cf515a6cf6 skaapsteker/cutscene.py --- a/skaapsteker/cutscene.py Sat Apr 09 14:52:51 2011 +0200 +++ b/skaapsteker/cutscene.py Sat Apr 09 14:53:33 2011 +0200 @@ -2,8 +2,9 @@ from __future__ import division import pygame -from pygame.locals import K_ESCAPE, K_q, KEYDOWN +from pygame.locals import K_ESCAPE, K_q, KEYDOWN, SRCALPHA +from . import constants from . import data from .engine import ChangeScene, Scene from .widgets.text import Text, ButtonSet, TextButton, unindent_text @@ -12,18 +13,27 @@ def __init__(self, game_state, soundsystem, text, background, music=None): super(CutScene, self).__init__(game_state, soundsystem) self.background = data.load_image('backgrounds/' + background) + fill = pygame.Surface(self.background.get_size(), flags=SRCALPHA) + fill.fill((255, 255, 255, 128)) + self.background.convert_alpha(fill) + self.background.blit(fill, (0, 0)) + self.background.convert_alpha() self.start_time = pygame.time.get_ticks() self.run_time = 60000 # ms self._background_music = None self._background_music = music - text_widget = Text(text, pygame.Rect(20, 20, 800-40, 600-40), + text_widget = Text(text, pygame.Rect(20, 20, + constants.SCREEN[0] - 40, + constants.SCREEN[1] - 40), size=24, shadow='gray', wrap=True) self.widgets.append(text_widget) button_set = ButtonSet() - button_set.append(TextButton("Continue", (300, 500), size=24, color='yellow')) + # TODO: Dynamic position + button_set.append(TextButton("Continue", (20, constants.SCREEN[1] - 68), + size=24, color='red')) button_set.callbacks.append(self.done) self.widgets.append(button_set) diff -r f14621568fb6 -r 92cf515a6cf6 skaapsteker/sprites/base.py --- a/skaapsteker/sprites/base.py Sat Apr 09 14:52:51 2011 +0200 +++ b/skaapsteker/sprites/base.py Sat Apr 09 14:53:33 2011 +0200 @@ -236,12 +236,29 @@ DAMAGE = 10 - def setup(self, hits): + PROJECTILE_SIZE = (0, 0) # pixels + VELOCITY = (10, 10) # pixels/s + + def setup(self, direction, hits, **opts): + super(Projectile, self).setup(**opts) + self.facing = direction + if isinstance(hits, tuple): self.hits = hits + (Geography,) else: self.hits = (hits, Geography) + if self.facing == "left": + shift = (-self.PROJECTILE_SIZE[0] / 2, self.PROJECTILE_SIZE[1]) + dv = (-self.VELOCITY[0], self.VELOCITY[1]) + else: + shift = (self.PROJECTILE_SIZE[0] / 2, self.PROJECTILE_SIZE[1]) + dv = (self.VELOCITY[0], self.VELOCITY[1]) + + self.rect.move_ip(shift) + self.collide_rect.move_ip(shift) + self.deltav(dv) + def explode(self): self.kill() diff -r f14621568fb6 -r 92cf515a6cf6 skaapsteker/sprites/player.py --- a/skaapsteker/sprites/player.py Sat Apr 09 14:52:51 2011 +0200 +++ b/skaapsteker/sprites/player.py Sat Apr 09 14:53:33 2011 +0200 @@ -4,7 +4,7 @@ import time from ..sprites.base import find_sprite, Monster, TILE_SIZE, PC_LAYER, MONSTER_LAYER, PROJECTILE_LAYER -from ..sprites.projectiles import Fireball +from ..sprites.projectiles import Fireball, Lightning from ..physics import Sprite from ..constants import Layers, FoxHud from ..data import get_files, load_image @@ -269,21 +269,25 @@ self.attacking = 2 self._last_time = time.time() # Reset the animation clock + def _launch_projectile(self, cls): + if self.facing == 'left': + pos = pygame.Rect(self.rect.midleft, (0, 0)) + else: + pos = pygame.Rect(self.rect.midright, (0, 0)) + projectile = cls(pos, direction=self.facing, hits=Monster) + AddSpriteEvent.post(projectile) + def _fireball_attack(self): print 'ninja fireball attack attack attack' self.attacking = 2 self._last_time = time.time() # Reset the animation clock - if self.facing == 'left': - pos = pygame.Rect(self.rect.midleft, (0, 0)) - else: - pos = pygame.Rect(self.rect.midright, (0, 0)) - fireball = Fireball(pos, direction=self.facing, hits=Monster) - AddSpriteEvent.post(fireball) + self._launch_projectile(Fireball) def _lightning_attack(self): print 'thunderbolts and lightning' self.attacking = 2 self._last_time = time.time() # Reset the animation clock + self._launch_projectile(Lightning) def action_fire1(self): if "fireball" not in self._me.tails: diff -r f14621568fb6 -r 92cf515a6cf6 skaapsteker/sprites/projectiles.py --- a/skaapsteker/sprites/projectiles.py Sat Apr 09 14:52:51 2011 +0200 +++ b/skaapsteker/sprites/projectiles.py Sat Apr 09 14:53:33 2011 +0200 @@ -19,18 +19,24 @@ ('right', lambda x: transform.flip(x, True, False))), } - FIREBALL_WIDTH = 60 # pixels + PROJECTILE_SIZE = (55, 8) # pixels VELOCITY = (300, -1000) # pps - def setup(self, direction, **opts): - super(Fireball, self).setup(**opts) - self.facing = direction - if self.facing == "left": - shift = (-self.FIREBALL_WIDTH / 2, 0) - dv = (-self.VELOCITY[0], self.VELOCITY[1]) - else: - shift = (self.FIREBALL_WIDTH / 2, 0) - dv = (self.VELOCITY[0], self.VELOCITY[1]) - self.rect.move_ip(shift) - self.collide_rect.move_ip(shift) - self.deltav(dv) + +class Lightning(Projectile): + + gravitates = False + + image_dir = 'sprites/attacks/fireball' + animation_regexes = [ + ('frightening', r"^fireball-\d+-sm.png$"), + ] + + facings = { + "frightening" : ( + ('left', None), + ('right', lambda x: transform.flip(x, True, False))), + } + + PROJECTILE_SIZE = (55, 8) # pixels + VELOCITY = (400, 0) # pps