mirror of
https://github.com/kristoferssolo/Tetris.git
synced 2025-10-21 20:00:35 +00:00
feat(game): volume from file
This commit is contained in:
parent
8e3ed493e0
commit
37132f54e0
@ -15,6 +15,10 @@ ccw = ["ctrl", "z", "kp3", "kp7"] # counter-clockwise
|
||||
hold = ["shift", "c", "kp0"]
|
||||
drop = ["space", "kp5"]
|
||||
|
||||
[Sound]
|
||||
music = true
|
||||
volume = 0.5
|
||||
[Volume.Music]
|
||||
enabled = true
|
||||
level = 0.01
|
||||
|
||||
[Volume.SFX]
|
||||
enabled = true
|
||||
level = 0.02
|
||||
|
||||
@ -100,7 +100,10 @@ class Game(BaseScreen):
|
||||
|
||||
def _start_background_music(self) -> None:
|
||||
"""Start playing background music."""
|
||||
if self.game_mode is GameMode.PLAYER:
|
||||
if (
|
||||
self.game_mode is GameMode.PLAYER
|
||||
and self.settings["Volume"]["Music"]["enabled"]
|
||||
):
|
||||
self.music = pygame.mixer.Sound(CONFIG.music.background)
|
||||
self.music.set_volume(CONFIG.music.volume)
|
||||
self.music.set_volume(self.settings["Volume"]["Music"]["level"])
|
||||
self.music.play(-1)
|
||||
|
||||
@ -337,13 +337,19 @@ class Tetris(BaseScreen):
|
||||
|
||||
def _initialize_sound(self) -> None:
|
||||
"""Initialize game sounds."""
|
||||
if self.game_mode is GameMode.PLAYER:
|
||||
if (
|
||||
self.game_mode is GameMode.PLAYER
|
||||
and self.settings["Volume"]["SFX"]["enabled"]
|
||||
):
|
||||
self.landing_sound = pygame.mixer.Sound(CONFIG.music.landing)
|
||||
self.landing_sound.set_volume(CONFIG.music.volume * 2)
|
||||
self.landing_sound.set_volume(self.settings["Volume"]["SFX"]["level"])
|
||||
|
||||
def _play_landing_sound(self) -> None:
|
||||
"""Play the landing sound effect."""
|
||||
if self.game_mode is GameMode.PLAYER:
|
||||
if (
|
||||
self.game_mode is GameMode.PLAYER
|
||||
and self.settings["Volume"]["SFX"]["enabled"]
|
||||
):
|
||||
self.landing_sound.play()
|
||||
|
||||
def _update_display_surface(self) -> None:
|
||||
|
||||
@ -63,7 +63,6 @@ class Window:
|
||||
class Music:
|
||||
background: Path = BASE_PATH / "assets" / "music" / "background.wav"
|
||||
landing: Path = BASE_PATH / "assets" / "music" / "landing.wav"
|
||||
volume: float = 0.01
|
||||
|
||||
|
||||
@define
|
||||
|
||||
Loading…
Reference in New Issue
Block a user