diff options
author | RaindropsSys <contact@minteck.org> | 2023-09-02 15:32:03 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-09-02 15:32:03 +0200 |
commit | 6a20ab31ef4d9f6bb0e008b9f1b8d3fbeb6bd956 (patch) | |
tree | d425cdef328ed268fb149d6e2b139c9b2c26dbd2 /src/audio.py | |
parent | c2f1ed6a85c3895483d36af0f64e2829c3fa3263 (diff) | |
download | blocks-6a20ab31ef4d9f6bb0e008b9f1b8d3fbeb6bd956.tar.gz blocks-6a20ab31ef4d9f6bb0e008b9f1b8d3fbeb6bd956.tar.bz2 blocks-6a20ab31ef4d9f6bb0e008b9f1b8d3fbeb6bd956.zip |
Updated 13 files and added 2 files (automated)
Diffstat (limited to 'src/audio.py')
-rw-r--r-- | src/audio.py | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/audio.py b/src/audio.py index baba6da..1d8f725 100644 --- a/src/audio.py +++ b/src/audio.py @@ -1,6 +1,8 @@ import pygame import random +enable_audio = False + pygame.mixer.pre_init(48000, -16, 2, 2048) pygame.mixer.init() pygame.mixer.set_num_channels(3) @@ -55,38 +57,46 @@ sfx = { } def play_intro(): - return + if not enable_audio: + return pygame.mixer.Channel(0).play(intro) def play_music(): - return + if not enable_audio: + return 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_menu(force=False): - return + if not enable_audio: + return if not pygame.mixer.Channel(1).get_busy() or force: pygame.mixer.Channel(1).set_volume(0.5) pygame.mixer.Channel(1).play(menu) def stop(channel=1): - return + if not enable_audio: + return pygame.mixer.Channel(channel).stop() def pause_music(): - return + if not enable_audio: + return pygame.mixer.Channel(1).pause() def unpause_music(): - return + if not enable_audio: + return pygame.mixer.Channel(1).unpause() def play_sfx(id): - return + if not enable_audio: + return pygame.mixer.Channel(2).play(random.choice(sfx[id])) def wait_for_sfx(): - return + if not enable_audio: + return while pygame.mixer.Channel(2).get_busy(): - pass
\ No newline at end of file + pass |