diff --git a/settings.toml b/settings.toml index f608da0..47b2aaf 100644 --- a/settings.toml +++ b/settings.toml @@ -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 diff --git a/src/game/screens/game.py b/src/game/screens/game.py index b764c27..371001f 100644 --- a/src/game/screens/game.py +++ b/src/game/screens/game.py @@ -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) diff --git a/src/game/screens/tetris.py b/src/game/screens/tetris.py index 409212a..fd3367a 100644 --- a/src/game/screens/tetris.py +++ b/src/game/screens/tetris.py @@ -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: diff --git a/src/utils/config.py b/src/utils/config.py index 27a0a97..8ff77aa 100644 --- a/src/utils/config.py +++ b/src/utils/config.py @@ -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