Add enemy spawn sound

This commit is contained in:
Nguyễn Gia Phong 2018-01-26 20:49:10 +07:00
parent f483f62ff5
commit 66d77f78b6
6 changed files with 8 additions and 3 deletions

View File

@ -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):

View File

@ -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')

View File

@ -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)."""

View File

@ -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()

Binary file not shown.

View File

@ -7,7 +7,7 @@ with open('README.rst') as f:
setup(
name='brutalmaze',
version='0.3.4',
version='0.3.5',
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',