use audio obj auto sfx scanning feature

This commit is contained in:
Frank DeMarco 2020-10-05 20:15:32 -04:00
parent b09ff54d3b
commit 7b92f7ee12
3 changed files with 31 additions and 33 deletions

3
.gitmodules vendored
View File

@ -0,0 +1,3 @@
[submodule "lib/pgfw"]
path = lib/pgfw
url = makar:/var/www/git/pgfw

60
NS.py
View File

@ -25,7 +25,6 @@ from lib.pgfw.pgfw.Game import Game
from lib.pgfw.pgfw.GameChild import GameChild
from lib.pgfw.pgfw.Sprite import Sprite, RainbowSprite
from lib.pgfw.pgfw.Animation import Animation
from lib.pgfw.pgfw.Audio import SoundEffect
from lib.pgfw.pgfw.extension import (
get_step, get_step_relative, get_delta, reflect_angle,
render_box, get_hsla_color, get_hue_shifted_surface,
@ -61,7 +60,6 @@ class NS(Game, Animation):
})
Animation.__init__(self, self)
mixer.init(44100, -16, self.CHANNEL_COUNT, 4096)
self.load_sfx()
self.subscribe(self.respond, KEYDOWN)
self.subscribe(self.respond, KEYUP)
self.subscribe(self.respond)
@ -97,11 +95,6 @@ class NS(Game, Animation):
self.most_recent_time = None
clear()
def load_sfx(self):
sfx = self.sfx = {}
for path in iglob(self.get_resource("sfx/") + "*.wav"):
sfx[basename(path.split(".")[0])] = SoundEffect(self, path)
def serial_enabled(self):
return self.get_configuration("input", "serial") and not self.check_command_line("-no-serial")
@ -255,7 +248,7 @@ class Button(Sprite):
colored = rects[3], rects[2]
elif edge == NS.W:
colored = rects[0], rects[3]
for lightness in xrange(30, 90, 5):
for lightness in range(30, 90, 5):
frame = Surface((width, width), SRCALPHA)
for topleft in (0, 0), (step, 0), (step, step), (0, step):
rect = Rect(topleft, (rect_width, rect_width))
@ -263,7 +256,7 @@ class Button(Sprite):
border_color.a = 179
frame.fill(border_color, rect)
frame.fill((0, 0, 0, 0), rect.inflate(-border * 2, -border * 2))
for ii in xrange(2):
for ii in range(2):
original_color = Color(*colors[ii])
original_color.a = 255
edited_color = Color(0, 0, 0)
@ -338,7 +331,7 @@ class Title(GameChild):
self.text.load_from_path(self.get_resource("Title_text.png"), True, False, (255, 0, 0))
self.text.location.center = dsr.centerx, dsr.bottom - 100
self.angle = choice((pi / 4, 3 * pi / 4, 5 * pi / 4, 7 * pi / 4))
self.button_sound = self.get_game().sfx["button"]
self.button_sound = self.get_audio().sfx["button"]
self.buttons = Button(self, NS.N, 10, 4), Button(self, NS.NW, 10, 4)
self.buttons[0].location.center = 277, 381
self.buttons[1].location.center = 453, 381
@ -364,7 +357,7 @@ class Title(GameChild):
def draw_scores(self):
step = 75
ds = self.get_display_surface()
lines = map(int, file(self.get_resource("scores")).readlines())
lines = map(int, open(self.get_resource("scores")).readlines())
entries = ["BEST"] + sorted(lines)[:9]
for ii, entry in enumerate(entries):
if ii == 0 or ii == 5:
@ -425,7 +418,7 @@ class Title(GameChild):
elif not wipe.is_playing() and self.first_pressed and \
self.get_game().platform.get_edge_pressed() == NS.NW:
wipe.start(self.activate_introduction)
self.get_game().sfx["confirm"].play()
self.get_audio().play_sfx("confirm")
elif self.first_pressed:
self.first_pressed_elapsed += self.get_game().time_filter.get_last_frame_duration()
# if self.first_pressed_elapsed > 4000:
@ -504,7 +497,7 @@ class Dialogue(Animation):
def show_text(self, text):
self.full_text = text
self.text_index = 0
self.speech_channel = self.get_game().sfx["talk"].play(-1)
self.speech_channel = self.get_audio().play_sfx("talk", -1)
self.play()
def build_frame(self):
@ -600,12 +593,13 @@ class Introduction(Animation):
# self.get_game().platform.unpress()
def speak(self):
for ii in xrange(self.words_index + 1):
for ii in range(self.words_index + 1):
self.words[ii].move(0, 12)
if ii == self.words_index and self.words[ii].location.bottom > self.get_display_surface().get_rect().bottom - 40:
if self.words_index < len(self.words) - 1:
self.words_index += 1
self.words[self.words_index].unhide()
self.get_audio().play_sfx("talk")
def start(self):
self.advance_prompt.cancel_first_press()
@ -639,7 +633,7 @@ class Introduction(Animation):
if self.skateboard.location.colliderect(self.slime_bag.location.inflate(-30, -30)):
self.halt(self.move_board)
self.play(self.take_board, delay=2000, play_once=True)
self.get_game().sfx["go"].play()
self.get_audio().play_sfx("go")
def take_board(self):
self.skateboard.hide()
@ -687,7 +681,7 @@ class Introduction(Animation):
platform = self.get_game().platform
if platform.get_edge_pressed() == self.TUTORIAL_MOVES[self.tutorial_index]:
self.tutorial_index += 1
self.get_game().sfx["land_0"].play()
self.get_audio().play_sfx("land_0")
if self.tutorial_index == len(self.TUTORIAL_MOVES):
# self.text_index += 1
# self.advance_prompt.cancel_first_press()
@ -737,7 +731,7 @@ class SkipPrompt(GameChild):
self.text.location.midleft = (
self.buttons[2].location.right + 5,
self.buttons[2].location.centery)
self.button_sound = self.get_game().sfx["button"]
self.button_sound = self.get_audio().sfx["button"]
def reset(self):
self.press_index = 0
@ -761,7 +755,7 @@ class SkipPrompt(GameChild):
self.pluses[1].hide()
elif self.press_index == 2 and platform.get_edge_pressed() == NS.W:
self.callback()
self.get_game().sfx["confirm"].play()
self.get_audio().play_sfx("confirm")
elif self.press_index > 0:
self.press_elapsed += self.get_game().time_filter.get_last_frame_duration()
if self.press_elapsed > 4000:
@ -812,12 +806,12 @@ class AdvancePrompt(GameChild):
self.first_pressed = True
self.buttons[0].hide()
self.plus.hide()
self.get_game().sfx["button"].play()
self.get_audio().play_sfx("button")
def check_second_press(self):
pressed = self.first_pressed and self.get_game().platform.get_edge_pressed() == NS.NW
if pressed:
self.get_game().sfx["confirm"].play()
self.get_audio().play_sfx("confirm")
return pressed
def update(self):
@ -840,7 +834,7 @@ class Wipe(Animation):
Animation.__init__(self, parent)
self.image = load(self.get_resource("Ink.png")).convert()
self.image.set_colorkey(self.TRANSPARENT_COLOR)
self.sound = self.get_game().sfx["wipe"]
self.sound = self.get_audio().sfx["wipe"]
def reset(self):
self.deactivate()
@ -880,7 +874,7 @@ class Wipe(Animation):
ds = self.get_display_surface()
dsr = ds.get_rect()
frame = self.image.copy()
for y in xrange(0, dsr.h, dsr.h / self.BLIND_COUNT):
for y in range(0, dsr.h, dsr.h // self.BLIND_COUNT):
if self.up:
frame.fill(self.TRANSPARENT_COLOR, (0, y, dsr.w, self.blind_height))
else:
@ -1103,7 +1097,7 @@ class Light(Animation):
return self.points
def draw_glow(self):
for ii, y in enumerate(xrange(0, self.glow_index, 3)):
for ii, y in enumerate(range(0, self.glow_index, 3)):
shifted = []
for point in self.get_points():
shifted.append((point[0], point[1] - y))
@ -1204,9 +1198,9 @@ class Chemtrails(Sprite):
self.timer.reset()
if not boss.is_playing(boss.show_end_dialogue):
boss.combo()
self.get_game().sfx["complete_pattern_3"].play()
self.get_audio().play_sfx("complete_pattern_3")
else:
self.get_game().sfx["land_0"].play()
self.get_audio().play_sfx("land_0")
self.get_game().platform.reset_lights()
def orient(self):
@ -1274,7 +1268,7 @@ class Life(Meter):
self.setup(background, rect, 70, (255, 0, 0), 3, "scrapeIcons/scrapeIcons_03.png")
def decrease(self):
self.get_game().sfx["hurt"].play()
self.get_audio().play_sfx("hurt")
self.change(-1)
if self.amount <= 0:
self.amount = 0
@ -1590,7 +1584,7 @@ class Boss(Animation):
def add_score(self):
self.get_game().set_most_recent_time(self.time_elapsed)
file(self.get_resource("scores"), "a").write(str(self.time_elapsed) + "\n")
open(self.get_resource("scores"), "a").write(str(self.time_elapsed) + "\n")
def show_end_dialogue(self):
dialogue = self.get_game().dialogue
@ -1690,7 +1684,7 @@ class Countdown(GameChild):
self.game_over.add_frame(font.render("GAME OVER", True, (0, 0, 0), (255, 255, 255)))
self.game_over.location.center = dsr.centerx, dsr.centery - 40
self.glyphs = []
for ii in xrange(10):
for ii in range(10):
glyph = Sprite(self)
frame = Surface((140, 140))
frame.fill((255, 255, 255))
@ -1742,7 +1736,7 @@ class Sword(Animation):
swords.append([[], [], [], [], [], []])
for path in sorted(iglob(join(self.get_resource(root), "*.png"))):
base = load(self.get_resource(path)).convert_alpha()
for position in xrange(6):
for position in range(6):
if position == NS.N or position == NS.S:
rotated = rotate(base, 270)
elif position == NS.NW:
@ -1764,7 +1758,7 @@ class Sword(Animation):
surface.fill(color_b, (0, rect.centery, rect.w, rect.h / 2), BLEND_RGBA_MIN)
swords[-1][position].append(surface)
masks = self.masks = []
for alpha in xrange(16, 255, 16):
for alpha in range(16, 255, 16):
surface = Surface((300, 300), SRCALPHA)
surface.fill((255, 255, 255, alpha))
masks.append(surface)
@ -1802,7 +1796,7 @@ class Sword(Animation):
else:
sprite.location.center = dsr.centerx - offset, dsr.centery - 100
self.sprites.append(sprite)
self.get_game().sfx["brandish"].play()
self.get_audio().play_sfx("brandish")
self.play(self.lower, delay=400, play_once=True)
if len(self.parent.unbrandished) > 0:
self.play(self.brandish, delay=self.get_configuration("time", "sword-delay"),
@ -1861,8 +1855,8 @@ class Health(Meter):
self.parent.damage()
if self.amount <= 0:
self.amount = 0
self.get_game().sfx["complete_pattern_1"].play()
self.get_game().sfx["defeat"].play()
self.get_audio().play_sfx("complete_pattern_1")
self.get_audio().play_sfx("defeat")
self.get_game().boss.finish_battle(True)
else:
self.parent.play(self.parent.cancel_flash, delay=1000, play_once=True)

1
lib/pgfw Submodule

@ -0,0 +1 @@
Subproject commit 5f2b26852e9fe8e910793cee46c14b8cbccaf962