parent
600c72d0d4
commit
2813a0856f
|
@ -16,7 +16,7 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with Brutal Maze. If not, see <https://www.gnu.org/licenses/>.
|
# along with Brutal Maze. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
__version__ = '0.9.0'
|
__version__ = '0.9.1'
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from argparse import ArgumentParser, FileType, RawTextHelpFormatter
|
from argparse import ArgumentParser, FileType, RawTextHelpFormatter
|
||||||
|
@ -32,7 +32,7 @@ from threading import Thread
|
||||||
with redirect_stdout(StringIO()): import pygame
|
with redirect_stdout(StringIO()): import pygame
|
||||||
from pygame import KEYDOWN, MOUSEBUTTONUP, QUIT, VIDEORESIZE
|
from pygame import KEYDOWN, MOUSEBUTTONUP, QUIT, VIDEORESIZE
|
||||||
from pygame.time import Clock, get_ticks
|
from pygame.time import Clock, get_ticks
|
||||||
from palace import free, use_context, Device, Context
|
from palace import free, use_context, Device, Context, Buffer
|
||||||
from appdirs import AppDirs
|
from appdirs import AppDirs
|
||||||
|
|
||||||
from .constants import SETTINGS, ICON, SFX, SFX_NOISE, HERO_SPEED, MIDDLE
|
from .constants import SETTINGS, ICON, SFX, SFX_NOISE, HERO_SPEED, MIDDLE
|
||||||
|
@ -136,9 +136,10 @@ class Game:
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
if self.actx is not None:
|
if self.actx is not None:
|
||||||
use_context(self.actx)
|
use_context(self.actx)
|
||||||
self.actx.listener.position = MIDDLE, 0, MIDDLE
|
self.actx.listener.position = MIDDLE, -MIDDLE, 0
|
||||||
self.actx.listener.gain = not self._mute
|
self.actx.listener.gain = not self._mute
|
||||||
play(SFX_NOISE)
|
self._source = Buffer(SFX_NOISE).play()
|
||||||
|
self._source.looping = True
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, traceback):
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
|
@ -146,7 +147,8 @@ class Game:
|
||||||
if not self.hero.dead: self.maze.dump_records()
|
if not self.hero.dead: self.maze.dump_records()
|
||||||
if self.actx is not None:
|
if self.actx is not None:
|
||||||
free(SFX)
|
free(SFX)
|
||||||
clean_sources()
|
clean_sources(stopped=False)
|
||||||
|
self._source.destroy()
|
||||||
use_context(None)
|
use_context(None)
|
||||||
self.actx.destroy()
|
self.actx.destroy()
|
||||||
self.actx.device.close()
|
self.actx.device.close()
|
||||||
|
|
|
@ -93,20 +93,22 @@ def json_rec(directory):
|
||||||
def play(sound: str, x: float = MIDDLE, y: float = MIDDLE,
|
def play(sound: str, x: float = MIDDLE, y: float = MIDDLE,
|
||||||
gain: float = 1.0) -> None:
|
gain: float = 1.0) -> None:
|
||||||
"""Play a sound at the given position."""
|
"""Play a sound at the given position."""
|
||||||
buffer = Buffer(sound)
|
source = Buffer(sound).play()
|
||||||
source = buffer.play()
|
|
||||||
source.spatialize = True
|
source.spatialize = True
|
||||||
source.position = x, 0, y
|
source.position = x, -y, 0
|
||||||
source.gain = gain
|
source.gain = gain
|
||||||
sources.append(source)
|
sources.append(source)
|
||||||
|
|
||||||
|
|
||||||
def clean_sources() -> None:
|
def clean_sources(stopped=True) -> None:
|
||||||
"""Destroyed stopped sources."""
|
"""Destroyed stopped sources.
|
||||||
|
|
||||||
|
If stopped is set to False, clean all sources.
|
||||||
|
"""
|
||||||
global sources
|
global sources
|
||||||
sources, tmp = [], sources
|
sources, tmp = [], sources
|
||||||
for source in tmp:
|
for source in tmp:
|
||||||
if source.playing:
|
if stopped and source.playing:
|
||||||
sources.append(source)
|
sources.append(source)
|
||||||
else:
|
else:
|
||||||
source.destroy()
|
source.destroy()
|
||||||
|
|
Loading…
Reference in New Issue