diff --git a/data/textures/ui_icons/audioOff.png b/data/textures/ui_icons/audioOff.png new file mode 100644 index 0000000..191e1a4 Binary files /dev/null and b/data/textures/ui_icons/audioOff.png differ diff --git a/data/textures/ui_icons/audioOn.png b/data/textures/ui_icons/audioOn.png new file mode 100644 index 0000000..43c2aa7 Binary files /dev/null and b/data/textures/ui_icons/audioOn.png differ diff --git a/data/ui/ui.ui b/data/ui/ui.ui index 2fb95e0..3a3f92d 100644 --- a/data/ui/ui.ui +++ b/data/ui/ui.ui @@ -211,6 +211,64 @@ "scroll_bar_height": 80, "scroll_bar_leeway": 60, "scroll_bar_leeway_fix_speed": 200 + }, + { + "name": "mute_button", + "type": "button", + "anchor": [1, 0], + "pos": [-180, 75], + "size": [100, 100], + "up_entities": [ + { + "parent": "mute_button", + "type": "texture", + "texture": "data/textures/ui_icons/audioOn.png", + "anchor": [0.5, 0.5], + "pos": [0, 0], + "size": [100, 100], + "overlay_color": [0, 0, 0, 1] + } + ], + "down_entities": [ + { + "parent": "mute_button", + "type": "texture", + "texture": "data/textures/ui_icons/audioOn.png", + "anchor": [0.5, 0.5], + "pos": [0, 0], + "size": [100, 100], + "overlay_color": [0.3, 0.3, 0.3, 1] + } + ] + }, + { + "name": "unmute_button", + "type": "button", + "anchor": [1, 0], + "pos": [-180, 75], + "size": [100, 100], + "up_entities": [ + { + "parent": "unmute_button", + "type": "texture", + "texture": "data/textures/ui_icons/audioOff.png", + "anchor": [0.5, 0.5], + "pos": [0, 0], + "size": [100, 100], + "overlay_color": [0, 0, 0, 1] + } + ], + "down_entities": [ + { + "parent": "unmute_button", + "type": "texture", + "texture": "data/textures/ui_icons/audioOff.png", + "anchor": [0.5, 0.5], + "pos": [0, 0], + "size": [100, 100], + "overlay_color": [0.3, 0.3, 0.3, 1] + } + ] }, { "name": "pause_button", diff --git a/src/golf/game.c b/src/golf/game.c index 9182fdc..475ecc1 100644 --- a/src/golf/game.c +++ b/src/golf/game.c @@ -22,6 +22,8 @@ static golf_graphics_t *graphics; static golf_inputs_t *inputs; static golf_config_t *game_cfg; +bool game_muted = false; + golf_game_t *golf_game_get(void) { return &game; } @@ -268,8 +270,9 @@ static void _golf_game_update_state_watching_ball(float dt) { } golf_storage_save(); } - - golf_audio_start_sound("ball_in_hole", "data/audio/confirmation_002.ogg", 1, false, true); + if (!game_muted) { + golf_audio_start_sound("ball_in_hole", "data/audio/confirmation_002.ogg", 1, false, true); + } } else if (game.ball.is_out_of_bounds) { game.ball.pos = game.ball.start_pos; @@ -282,7 +285,9 @@ static void _golf_game_update_state_watching_ball(float dt) { game.cam.angle = game.cam.start_angle; game.cam.auto_rotate = false; game.state = GOLF_GAME_STATE_WAITING_FOR_AIM; - golf_audio_start_sound("ball_out_of_bounds", "data/audio/error_008.ogg", 1, false, true); + if (!game_muted) { + golf_audio_start_sound("ball_out_of_bounds", "data/audio/error_008.ogg", 1, false, true); + } } else if (!game.ball.is_moving) { game.state = GOLF_GAME_STATE_WAITING_FOR_AIM; @@ -578,7 +583,9 @@ static void _physics_tick(float dt) { if (contact->impulse_mag > 1 && contact->cull_dot < -0.15f) { if (game.ball.time_since_impact_sound > 0.1f) { - golf_audio_start_sound("ball_impact", "data/audio/footstep_grass_004.ogg", 1, false, true); + if (!game_muted) { + golf_audio_start_sound("ball_impact", "data/audio/footstep_grass_004.ogg", 1, false, true); + } game.ball.time_since_impact_sound = 0; } } @@ -700,7 +707,9 @@ static void _physics_tick(float dt) { } if (game.ball.time_out_of_water < 0.1f) { - golf_audio_start_sound("ball_in_water", "data/audio/in_water.ogg", 0.1f, true, false); + if (!game_muted) { + golf_audio_start_sound("ball_in_water", "data/audio/in_water.ogg", 0.1f, true, false); + } } else { golf_audio_stop_sound("ball_in_water", 0.2f); @@ -1028,8 +1037,9 @@ void golf_game_hit_ball(vec2 aim_delta) { game.cam.start_angle = game.cam.angle; game.physics.collision_history.length = 0; - - golf_audio_start_sound("hit_ball", "data/audio/impactPlank_medium_000.ogg", 1, false, true); + if (!game_muted) { + golf_audio_start_sound("hit_ball", "data/audio/impactPlank_medium_000.ogg", 1, false, true); + } } void golf_game_pause(void) { diff --git a/src/golf/game.h b/src/golf/game.h index 0fb506e..ce2dbb3 100644 --- a/src/golf/game.h +++ b/src/golf/game.h @@ -92,4 +92,6 @@ void golf_game_hit_ball(vec2 aim_delta); void golf_game_pause(void); void golf_game_resume(void); +extern bool game_muted; + #endif diff --git a/src/golf/ui.c b/src/golf/ui.c index 4fa0c5f..81def76 100644 --- a/src/golf/ui.c +++ b/src/golf/ui.c @@ -502,7 +502,9 @@ static bool _golf_ui_button_name(golf_ui_layout_t *layout, const char *name) { } if (clicked) { - golf_audio_start_sound("button_click", "data/audio/drop_003.ogg", 1, false, true); + if (!game_muted) { + golf_audio_start_sound("button_click", "data/audio/drop_003.ogg", 1, false, true); + } } return clicked; @@ -1006,7 +1008,9 @@ static void _golf_ui_main_menu(float dt) { } int clicked_button_num = _golf_ui_level_select_scroll_box_name(layout, "level_select_scroll_box", dt); if (clicked_button_num >= 0) { - golf_audio_start_sound("button_click", "data/audio/drop_003.ogg", 1, false, true); + if (!game_muted) { + golf_audio_start_sound("button_click", "data/audio/drop_003.ogg", 1, false, true); + } _golf_ui_start_fade_out(false, true, clicked_button_num, false); } } @@ -1170,6 +1174,15 @@ static void _golf_ui_in_game(float dt) { if (_golf_ui_button_name(layout, "pause_button")) { golf_game_pause(); } + if (game_muted) { + if (_golf_ui_button_name(layout, "unmute_button")) { + game_muted = false; + } + } else { + if (_golf_ui_button_name(layout, "mute_button")) { + game_muted = true; + } + } } float temp_val;