diff options
author | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2018-01-26 20:49:10 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2018-01-26 20:49:10 +0700 |
commit | 66d77f78b6c56bae34d66b1022b915ed8257a705 (patch) | |
tree | 9530a3f57a3fd28807232af71456971919037b6d /brutalmaze | |
parent | f483f62ff5b3549146e2f2ad97960ff35d87b076 (diff) | |
download | brutalmaze-66d77f78b6c56bae34d66b1022b915ed8257a705.tar.gz |
Add enemy spawn sound
Diffstat (limited to 'brutalmaze')
-rw-r--r-- | brutalmaze/characters.py | 2 | ||||
-rw-r--r-- | brutalmaze/constants.py | 1 | ||||
-rw-r--r-- | brutalmaze/maze.py | 4 | ||||
-rw-r--r-- | brutalmaze/misc.py | 2 | ||||
-rw-r--r-- | brutalmaze/soundfx/spawn.ogg | bin | 0 -> 8810 bytes |
5 files changed, 7 insertions, 2 deletions
diff --git a/brutalmaze/characters.py b/brutalmaze/characters.py index a7e0513..d28ea0b 100644 --- a/brutalmaze/characters.py +++ b/brutalmaze/characters.py @@ -169,6 +169,8 @@ class Enemy: if get_distance(x - self.maze.x, y - self.maze.y) <= mind: return False self.awake = True + play(self.maze.sfx_spawn, self.maze.get_distance(*self.get_pos()), + self.get_angle() + pi) return True def fire(self): diff --git a/brutalmaze/constants.py b/brutalmaze/constants.py index 5e96922..21d821b 100644 --- a/brutalmaze/constants.py +++ b/brutalmaze/constants.py @@ -25,6 +25,7 @@ from pkg_resources import resource_filename ICON = image.load(resource_filename('brutalmaze', 'icon.png')) MUSIC = resource_filename('brutalmaze', 'soundfx/music.ogg') +SFX_SPAWN = resource_filename('brutalmaze', 'soundfx/spawn.ogg') SFX_SLASH_ENEMY = resource_filename('brutalmaze', 'soundfx/slash-enemy.ogg') SFX_SLASH_HERO = resource_filename('brutalmaze', 'soundfx/slash-hero.ogg') SFX_SHOT_ENEMY = resource_filename('brutalmaze', 'soundfx/shot-enemy.ogg') diff --git a/brutalmaze/maze.py b/brutalmaze/maze.py index b958299..2123a74 100644 --- a/brutalmaze/maze.py +++ b/brutalmaze/maze.py @@ -25,7 +25,7 @@ from random import choice, getrandbits, uniform import pygame from pygame import RESIZABLE -from pygame.mixer import Sound, set_num_channels +from pygame.mixer import Sound from pygame.time import get_ticks from .characters import Hero, new_enemy @@ -105,6 +105,7 @@ class Maze: self.next_move = self.next_slashfx = 0 self.slashd = self.hero.R + self.distance/SQRT2 + self.sfx_spawn = Sound(SFX_SPAWN) self.sfx_slash = Sound(SFX_SLASH_ENEMY) self.sfx_shot = Sound(SFX_SHOT_ENEMY) self.sfx_lose = Sound(SFX_LOSE) @@ -126,7 +127,6 @@ class Maze: walls.remove((x, y)) else: self.map[x][y] = WALL - set_num_channels(int(num * 3)) def get_pos(self, x, y): """Return coordinate of the center of the grid (x, y).""" diff --git a/brutalmaze/misc.py b/brutalmaze/misc.py index 6f79c0b..eb2d45c 100644 --- a/brutalmaze/misc.py +++ b/brutalmaze/misc.py @@ -85,6 +85,8 @@ def choices(d): def play(sound, volume, angle=None): """Play a pygame.mixer.Sound at the given volume.""" + if pygame.mixer.find_channel() is None: + pygame.mixer.set_num_channels(pygame.mixer.get_num_channels() + 1) if angle is None: sound.set_volume(volume) sound.play() diff --git a/brutalmaze/soundfx/spawn.ogg b/brutalmaze/soundfx/spawn.ogg new file mode 100644 index 0000000..fb1d2a1 --- /dev/null +++ b/brutalmaze/soundfx/spawn.ogg Binary files differ |