# HG changeset patch # User Simon Cross # Date 1302353183 -7200 # Node ID 249ba3bd6904a4254903e08fb9d654d08a188087 # Parent a43f571e8f5bbf605dbd16d19cf401a531cf685a Very, very frightening. diff -r a43f571e8f5b -r 249ba3bd6904 skaapsteker/sprites/base.py --- a/skaapsteker/sprites/base.py Sat Apr 09 14:39:18 2011 +0200 +++ b/skaapsteker/sprites/base.py Sat Apr 09 14:46:23 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 a43f571e8f5b -r 249ba3bd6904 skaapsteker/sprites/player.py --- a/skaapsteker/sprites/player.py Sat Apr 09 14:39:18 2011 +0200 +++ b/skaapsteker/sprites/player.py Sat Apr 09 14:46:23 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 a43f571e8f5b -r 249ba3bd6904 skaapsteker/sprites/projectiles.py --- a/skaapsteker/sprites/projectiles.py Sat Apr 09 14:39:18 2011 +0200 +++ b/skaapsteker/sprites/projectiles.py Sat Apr 09 14:46:23 2011 +0200 @@ -19,18 +19,24 @@ ('right', lambda x: transform.flip(x, True, False))), } - FIREBALL_WIDTH = 55 # 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, 4) - dv = (-self.VELOCITY[0], self.VELOCITY[1]) - else: - shift = (self.FIREBALL_WIDTH / 2, 4) - 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