changeset 366:249ba3bd6904

Very, very frightening.
author Simon Cross <hodgestar@gmail.com>
date Sat, 09 Apr 2011 14:46:23 +0200
parents a43f571e8f5b
children 92cf515a6cf6
files skaapsteker/sprites/base.py skaapsteker/sprites/player.py skaapsteker/sprites/projectiles.py
diffstat 3 files changed, 48 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- 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()
 
--- 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:
--- 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