Skip to content

Commit 6aec647

Browse files
committed
Handle audio driver selection for Pyodide
1 parent 7cf720b commit 6aec647

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

arcade/sound.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99
from pyglet.media import Source
1010

1111
from arcade.resources import resolve
12+
from arcade.utils import is_pyodide
1213

1314
if os.environ.get("ARCADE_SOUND_BACKENDS"):
1415
pyglet.options.audio = tuple(v.strip() for v in os.environ["ARCADE_SOUND_BACKENDS"].split(","))
16+
elif is_pyodide():
17+
# Pyglet will also detect Pyodide and auto select the driver for it, but the driver tuple needs to be empty for that to happen
18+
pyglet.options.audio = ()
1519
else:
1620
pyglet.options.audio = ("openal", "xaudio2", "directsound", "pulse", "silent")
1721

webplayground/platformer/package/main.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,11 @@ def __init__(self):
229229
self.shoot_timer = 0
230230

231231
# Load sounds
232-
# self.collect_coin_sound = arcade.load_sound(":resources:sounds/coin1.wav")
233-
# self.jump_sound = arcade.load_sound(":resources:sounds/jump1.wav")
234-
# self.gameover_sound = arcade.load_sound(":resources:sounds/gameover1.wav")
235-
# self.shoot_sound = arcade.load_sound(":resources:sounds/hurt5.wav")
236-
# self.hit_sound = arcade.load_sound(":resources:sounds/hit5.wav")
232+
self.collect_coin_sound = arcade.load_sound(":resources:sounds/coin1.wav")
233+
self.jump_sound = arcade.load_sound(":resources:sounds/jump1.wav")
234+
self.gameover_sound = arcade.load_sound(":resources:sounds/gameover1.wav")
235+
self.shoot_sound = arcade.load_sound(":resources:sounds/hurt5.wav")
236+
self.hit_sound = arcade.load_sound(":resources:sounds/hit5.wav")
237237

238238
def setup(self):
239239
"""Set up the game here. Call this function to restart the game."""
@@ -364,7 +364,7 @@ def on_update(self, delta_time):
364364

365365
if self.can_shoot:
366366
if self.shoot_pressed:
367-
# arcade.play_sound(self.shoot_sound)
367+
arcade.play_sound(self.shoot_sound)
368368
bullet = arcade.Sprite(
369369
":resources:images/space_shooter/laserBlue01.png",
370370
scaling=0.8,
@@ -422,7 +422,7 @@ def on_update(self, delta_time):
422422
collision.remove_from_sprite_lists()
423423
self.score += 150
424424

425-
# arcade.play_sound(self.hit_sound)
425+
arcade.play_sound(self.hit_sound)
426426

427427
return
428428

@@ -438,14 +438,14 @@ def on_update(self, delta_time):
438438

439439
for collision in player_collision_list:
440440
if self.scene["Enemies"] in collision.sprite_lists:
441-
# arcade.play_sound(self.gameover_sound)
441+
arcade.play_sound(self.gameover_sound)
442442
game_over = GameOverView()
443443
self.window.show_view(game_over)
444444
return
445445
else:
446446
# Our collision is a coin, remove it
447447
collision.remove_from_sprite_lists()
448-
# arcade.play_sound(self.collect_coin_sound)
448+
arcade.play_sound(self.collect_coin_sound)
449449
self.score += 75
450450
self.score_text.text = f"Score: {self.score}"
451451

@@ -464,7 +464,7 @@ def process_keychange(self):
464464
self.player_sprite.change_y = PLAYER_MOVEMENT_SPEED
465465
elif self.physics_engine.can_jump(y_distance=10):
466466
self.player_sprite.change_y = PLAYER_JUMP_SPEED
467-
# arcade.play_sound(self.jump_sound)
467+
arcade.play_sound(self.jump_sound)
468468
elif self.down_pressed and not self.up_pressed:
469469
if self.physics_engine.is_on_ladder():
470470
self.player_sprite.change_y = -PLAYER_MOVEMENT_SPEED

0 commit comments

Comments
 (0)