about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--brutalmaze/characters.py15
-rw-r--r--brutalmaze/maze.py10
-rw-r--r--brutalmaze/misc.py17
-rwxr-xr-xsetup.py2
4 files changed, 31 insertions, 13 deletions
diff --git a/brutalmaze/characters.py b/brutalmaze/characters.py
index 6cb78df..a7e0513 100644
--- a/brutalmaze/characters.py
+++ b/brutalmaze/characters.py
@@ -181,9 +181,8 @@ class Enemy:
             or randrange((self.maze.hero.slashing+self.maze.isfast()+1) * 3)):
             return False
         self.next_strike = get_ticks() + ATTACK_SPEED
-        self.maze.bullets.append(Bullet(
-            self.maze.surface, x, y,
-            atan2(self.maze.y - y, self.maze.x - x), self.color))
+        self.maze.bullets.append(
+            Bullet(self.maze.surface, x, y, self.get_angle() + pi, self.color))
         return True
 
     def move(self, speed=ENEMY_SPEED):
@@ -222,6 +221,14 @@ class Enemy:
         if self.spin_queue: self.maze.hit_hero(wound, self.color)
         return wound
 
+    def get_angle(self, reversed=False):
+        """Return the angle of the vector whose initial point is
+        the center of the screen and terminal point is the center of
+        the enemy.
+        """
+        x, y = self.get_pos()
+        return atan2(y - self.maze.y, x - self.maze.x)
+
     def draw(self):
         """Draw the enemy."""
         radious = self.maze.distance/SQRT2 - self.awake*2
@@ -237,7 +244,7 @@ class Enemy:
             if not self.spin_queue and not self.fire() and not self.move():
                 self.spin_queue = randsign() * self.spin_speed
                 if not self.maze.hero.dead:
-                    play(self.sfx_slash, self.get_slash())
+                    play(self.sfx_slash, self.get_slash(), self.get_angle())
             if abs(self.spin_queue) > 0.5:
                 self.angle += sign(self.spin_queue) * pi / 2 / self.spin_speed
                 self.spin_queue -= sign(self.spin_queue)
diff --git a/brutalmaze/maze.py b/brutalmaze/maze.py
index 3b0ee6d..f9ea6ce 100644
--- a/brutalmaze/maze.py
+++ b/brutalmaze/maze.py
@@ -20,7 +20,7 @@
 __doc__ = 'brutalmaze module for the maze class'
 
 from collections import deque
-from math import pi, atan2, log
+from math import pi, log
 from random import choice, getrandbits, uniform
 
 import pygame
@@ -224,7 +224,7 @@ class Maze:
             if d > 0:
                 wound, time = d * SQRT2 / self.distance, get_ticks()
                 if time >= self.next_slashfx:
-                    play(self.sfx_slash, wound)
+                    play(self.sfx_slash, wound, enemy.get_angle())
                     self.next_slashfx = time + ATTACK_SPEED
                 enemy.hit(wound / self.hero.spin_speed)
                 if enemy.wound >= ENEMY_HP:
@@ -262,15 +262,15 @@ class Maze:
                             self.score += enemy.wound
                             enemy.die()
                             self.enemies.pop(j)
-                        play(self.sfx_shot, wound)
+                        play(self.sfx_shot, wound, bullet.angle)
                         fallen.append(i)
                         break
             elif bullet.get_distance(self.x, self.y) < self.distance:
                 if self.hero.spin_queue:
-                    play(bullet.sfx_missed, wound)
+                    play(bullet.sfx_missed, wound, bullet.angle + pi)
                 else:
                     self.hit_hero(wound, bullet.color)
-                    play(bullet.sfx_hit, wound)
+                    play(bullet.sfx_hit, wound, bullet.angle + pi)
                 fallen.append(i)
         for i in reversed(fallen): self.bullets.pop(i)
 
diff --git a/brutalmaze/misc.py b/brutalmaze/misc.py
index 431b5e6..6f79c0b 100644
--- a/brutalmaze/misc.py
+++ b/brutalmaze/misc.py
@@ -83,7 +83,18 @@ def choices(d):
         if num <= w: return population[i]
 
 
-def play(sound, volume):
+def play(sound, volume, angle=None):
     """Play a pygame.mixer.Sound at the given volume."""
-    sound.set_volume(volume)
-    sound.play()
+    if angle is None:
+        sound.set_volume(volume)
+        sound.play()
+    else:
+        delta = cos(angle)
+        volumes = [volume * (1-delta), volume * (1+delta)]
+        for i, v in enumerate(volumes):
+            if v > 1:
+                volumes[i - 1] += v - 1
+                volumes[i] = 1.0
+        sound.set_volume(1.0)
+        channel = sound.play()
+        channel.set_volume(*volumes)
diff --git a/setup.py b/setup.py
index 8a2e802..2f9e07a 100755
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@ with open('README.rst') as f:
 
 setup(
     name='brutalmaze',
-    version='0.3.3',
+    version='0.3.4',
     description='A hash and slash game with fast-paced action and a minimalist art style',
     long_description=long_description,
     url='https://github.com/McSinyx/brutalmaze',