Make all sound playing fail-safe
This commit is contained in:
parent
fca23ea3ce
commit
1b2dc5e169
|
@ -79,7 +79,7 @@ class Hero:
|
||||||
self.wound -= HEAL_SPEED / self.spin_speed / HERO_HP
|
self.wound -= HEAL_SPEED / self.spin_speed / HERO_HP
|
||||||
if self.wound < 0: self.wound = 0.0
|
if self.wound < 0: self.wound = 0.0
|
||||||
if time > self.next_beat:
|
if time > self.next_beat:
|
||||||
self.sfx_heart.play()
|
play(self.sfx_heart)
|
||||||
self.next_beat = time + MIN_BEAT*(2 - self.wound/HERO_HP)
|
self.next_beat = time + MIN_BEAT*(2 - self.wound/HERO_HP)
|
||||||
|
|
||||||
if self.slashing and time >= self.next_strike:
|
if self.slashing and time >= self.next_strike:
|
||||||
|
|
|
@ -365,4 +365,4 @@ class Maze:
|
||||||
self.hero.dead = True
|
self.hero.dead = True
|
||||||
self.hero.slashing = self.hero.firing = False
|
self.hero.slashing = self.hero.firing = False
|
||||||
self.vx = self.vy = 0.0
|
self.vx = self.vy = 0.0
|
||||||
self.sfx_lose.play()
|
play(self.sfx_lose)
|
||||||
|
|
|
@ -83,13 +83,14 @@ def choices(d):
|
||||||
if num <= w: return population[i]
|
if num <= w: return population[i]
|
||||||
|
|
||||||
|
|
||||||
def play(sound, volume, angle=None):
|
def play(sound, volume=1.0, angle=None):
|
||||||
"""Play a pygame.mixer.Sound at the given volume."""
|
"""Play a pygame.mixer.Sound at the given volume."""
|
||||||
if pygame.mixer.find_channel() is None:
|
if pygame.mixer.find_channel() is None:
|
||||||
pygame.mixer.set_num_channels(pygame.mixer.get_num_channels() + 1)
|
pygame.mixer.set_num_channels(pygame.mixer.get_num_channels() + 1)
|
||||||
|
|
||||||
|
channel = sound.play()
|
||||||
if angle is None:
|
if angle is None:
|
||||||
sound.set_volume(volume)
|
channel.set_volume(volume)
|
||||||
sound.play()
|
|
||||||
else:
|
else:
|
||||||
delta = cos(angle)
|
delta = cos(angle)
|
||||||
volumes = [volume * (1-delta), volume * (1+delta)]
|
volumes = [volume * (1-delta), volume * (1+delta)]
|
||||||
|
@ -98,5 +99,4 @@ def play(sound, volume, angle=None):
|
||||||
volumes[i - 1] += v - 1
|
volumes[i - 1] += v - 1
|
||||||
volumes[i] = 1.0
|
volumes[i] = 1.0
|
||||||
sound.set_volume(1.0)
|
sound.set_volume(1.0)
|
||||||
channel = sound.play()
|
|
||||||
channel.set_volume(*volumes)
|
channel.set_volume(*volumes)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -7,7 +7,7 @@ with open('README.rst') as f:
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='brutalmaze',
|
name='brutalmaze',
|
||||||
version='0.4.1',
|
version='0.4.2',
|
||||||
description='A hash and slash game with fast-paced action and a minimalist art style',
|
description='A hash and slash game with fast-paced action and a minimalist art style',
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
url='https://github.com/McSinyx/brutalmaze',
|
url='https://github.com/McSinyx/brutalmaze',
|
||||||
|
|
Loading…
Reference in New Issue