Implement (pseudo) surround sound
This commit is contained in:
parent
59501c6c44
commit
097357347c
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue