changeset 538:c1b0ad1c0932

Hook up projectile sounds.
author Simon Cross <hodgestar@gmail.com>
date Sun, 10 Apr 2011 00:33:06 +0200
parents a7b7694644a5
children 4e8be9c52952
files skaapsteker/sprites/base.py skaapsteker/sprites/player.py skaapsteker/sprites/projectiles.py
diffstat 3 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/skaapsteker/sprites/base.py	Sun Apr 10 00:32:24 2011 +0200
+++ b/skaapsteker/sprites/base.py	Sun Apr 10 00:33:06 2011 +0200
@@ -11,6 +11,7 @@
 from ..engine import OpenDialog, AddSpriteEvent
 from .. import data
 from .. import dialogue
+from .. import sound
 
 
 TILE_SIZE = (64, 64)
@@ -180,6 +181,7 @@
         else:
             pos = pygame.Rect(self.rect.midright, (0, 0))
         projectile = cls(pos, direction=self.facing, hits=Player, source=self)
+        projectile.launch()
         AddSpriteEvent.post(projectile)
 
     def do_attack(self):
@@ -303,6 +305,7 @@
 
     collision_layer = PROJECTILE_LAYER
     collides_with = set()
+    launch_sound = None, None
 
     gravitates = False
 
@@ -316,6 +319,8 @@
         self.facing = direction
         self.source = source # source of the projectile (may be None)
         self._update_image(True)  # ensure we get the direction right
+        if self.launch_sound[0]:
+            sound.load_sound(self.launch_sound[0], self.launch_sound[0], self.launch_sound[1])
 
         if isinstance(hits, tuple):
             self.hits = hits + (Geography,)
@@ -333,6 +338,10 @@
         self.collide_rect.move_ip(shift)
         self.deltav(dv)
 
+    def launch(self):
+        if self.launch_sound[0]:
+            sound.play_sound(self.launch_sound[0])
+
     def explode(self):
         self.kill()
 
--- a/skaapsteker/sprites/player.py	Sun Apr 10 00:32:24 2011 +0200
+++ b/skaapsteker/sprites/player.py	Sun Apr 10 00:33:06 2011 +0200
@@ -375,6 +375,7 @@
         else:
             pos = pygame.Rect(self.rect.midright, (0, 0))
         projectile = cls(pos, direction=self.facing, hits=(Monster, BreakableItem), source=self)
+        projectile.launch()
         AddSpriteEvent.post(projectile)
 
     def _fireball_attack(self):
--- a/skaapsteker/sprites/projectiles.py	Sun Apr 10 00:32:24 2011 +0200
+++ b/skaapsteker/sprites/projectiles.py	Sun Apr 10 00:33:06 2011 +0200
@@ -4,10 +4,12 @@
 
 from .base import Projectile
 
+
 class Fireball(Projectile):
 
     gravitates = True
 
+    launch_sound = 'sounds/woosh fireball.ogg', 0.5
     image_dir = 'sprites/attacks/fireball'
     animation_regexes = [
         ("raining_death", r"^fireball-\d+-sm.png$"),
@@ -28,6 +30,7 @@
     gravitates = False
     friction_coeff = (1.2, 1.2) # negative friction
 
+    launch_sound = 'sounds/lightning.ogg', 0.25
     image_dir = 'sprites/attacks'
     animation_regexes = [
         ('frightening', r"^lightning.png$"),
@@ -48,6 +51,7 @@
     gravitates = False
     friction_coeff = (1.0, 1.0) # no friction
 
+    launch_sound = 'sounds/woosh.ogg', 0.5
     image_dir = 'sprites/attacks'
     animation_regexes = [
         ('draining', r"^energy_drain.png$"),