From e54ac640f1d3f7071a48032e924b04529cbd358f Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Thu, 31 Aug 2023 21:00:30 +0200 Subject: Initial commit --- src/audio.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/audio.py (limited to 'src/audio.py') diff --git a/src/audio.py b/src/audio.py new file mode 100644 index 0000000..ceb7cad --- /dev/null +++ b/src/audio.py @@ -0,0 +1,58 @@ +import pygame +import random + +pygame.mixer.pre_init(48000, -16, 2, 2048) +pygame.mixer.init() +pygame.mixer.set_num_channels(3) + +intro = pygame.mixer.Sound("./assets/sounds/intro.mp3") +bgm = [ + pygame.mixer.Sound("./assets/music/bgm1.mp3"), + pygame.mixer.Sound("./assets/music/bgm2.mp3"), + pygame.mixer.Sound("./assets/music/bgm3.mp3"), + pygame.mixer.Sound("./assets/music/bgm4.mp3"), + pygame.mixer.Sound("./assets/music/bgm5.mp3") +] + +sfx = { + "glass": [ + pygame.mixer.Sound("./assets/sounds/game/block_glass_1.ogg"), + pygame.mixer.Sound("./assets/sounds/game/block_glass_2.ogg"), + pygame.mixer.Sound("./assets/sounds/game/block_glass_3.ogg") + ], + "grass": [ + pygame.mixer.Sound("./assets/sounds/game/block_grass_1.ogg"), + pygame.mixer.Sound("./assets/sounds/game/block_grass_2.ogg"), + pygame.mixer.Sound("./assets/sounds/game/block_grass_3.ogg"), + pygame.mixer.Sound("./assets/sounds/game/block_grass_4.ogg") + ], + "stone": [ + pygame.mixer.Sound("./assets/sounds/game/block_stone_1.ogg"), + pygame.mixer.Sound("./assets/sounds/game/block_stone_2.ogg"), + pygame.mixer.Sound("./assets/sounds/game/block_stone_3.ogg"), + pygame.mixer.Sound("./assets/sounds/game/block_stone_4.ogg") + ], + "wood": [ + pygame.mixer.Sound("./assets/sounds/game/block_wood_1.ogg"), + pygame.mixer.Sound("./assets/sounds/game/block_wood_2.ogg"), + pygame.mixer.Sound("./assets/sounds/game/block_wood_3.ogg"), + pygame.mixer.Sound("./assets/sounds/game/block_wood_4.ogg") + ], + "none": [ + pygame.mixer.Sound("./assets/sounds/game/none_1.ogg"), + pygame.mixer.Sound("./assets/sounds/game/none_2.ogg"), + pygame.mixer.Sound("./assets/sounds/game/none_3.ogg"), + pygame.mixer.Sound("./assets/sounds/game/none_4.ogg") + ] +} + +def play_intro(): + pygame.mixer.Channel(0).play(intro) + +def play_music(): + if not pygame.mixer.Channel(1).get_busy(): + pygame.mixer.Channel(1).set_volume(0.5) + pygame.mixer.Channel(1).play(random.choice(bgm)) + +def play_sfx(id): + pygame.mixer.Channel(2).play(random.choice(sfx[id])) \ No newline at end of file -- cgit