diff --git a/src/about.c b/src/about.c index ccb1e9b..f577441 100644 --- a/src/about.c +++ b/src/about.c @@ -16,7 +16,7 @@ void About_Draw(struct Game *game) { } void About_Load(struct Game *game) { - al_play_sample(game->about.sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL); + if (game->music) al_play_sample(game->about.sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL); ALLEGRO_EVENT ev; for(int fadeloop=0; fadeloop<256; fadeloop+=10){ al_wait_for_event(game->event_queue, &ev); diff --git a/src/intro.c b/src/intro.c index 3db1e5c..d5713d8 100644 --- a/src/intro.c +++ b/src/intro.c @@ -31,7 +31,7 @@ void Intro_Draw(struct Game *game) { } void Intro_Load(struct Game *game) { - al_play_sample(game->intro.sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL); + if (game->music) al_play_sample(game->intro.sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL); ALLEGRO_EVENT ev; for(int fadeloop=0; fadeloop<256; fadeloop+=10){ al_wait_for_event(game->event_queue, &ev); diff --git a/src/level.c b/src/level.c index 82a3fef..d8510a2 100644 --- a/src/level.c +++ b/src/level.c @@ -23,7 +23,7 @@ void Level_Draw(struct Game *game) { } void Level_Load(struct Game *game) { - al_play_sample(game->level.sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL); + if (game->music) al_play_sample(game->level.sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL); ALLEGRO_EVENT ev; for(int fadeloop=0; fadeloop<256; fadeloop+=10){ al_wait_for_event(game->event_queue, &ev); diff --git a/src/map.c b/src/map.c index 72f56cc..13268f8 100644 --- a/src/map.c +++ b/src/map.c @@ -37,7 +37,7 @@ void Map_Draw(struct Game *game) { } void Map_Load(struct Game *game) { - al_play_sample(game->map.sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL); + if (game->music) al_play_sample(game->map.sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL); ALLEGRO_EVENT ev; for(int fadeloop=0; fadeloop<256; fadeloop+=10){ al_wait_for_event(game->event_queue, &ev); @@ -51,12 +51,12 @@ void Map_Load(struct Game *game) { int Map_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { if ((((game->map.selected<4) || (game->map.selected==6)) && (ev->keyboard.keycode==ALLEGRO_KEY_LEFT)) || ((game->map.selected>4) && (game->map.selected!=6) && (ev->keyboard.keycode==ALLEGRO_KEY_RIGHT)) || ((game->map.selected==4) && (ev->keyboard.keycode==ALLEGRO_KEY_UP)) || ((game->map.selected==6) && (ev->keyboard.keycode==ALLEGRO_KEY_DOWN))) { game->map.selected--; - al_play_sample(game->map.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); + if (game->fx) al_play_sample(game->map.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); } else if (((game->map.selected<3) && (ev->keyboard.keycode==ALLEGRO_KEY_RIGHT)) || ((game->map.selected==4) && (ev->keyboard.keycode==ALLEGRO_KEY_LEFT)) || ((game->map.selected==3) && (ev->keyboard.keycode==ALLEGRO_KEY_DOWN)) || ((game->map.selected==5) && (ev->keyboard.keycode==ALLEGRO_KEY_UP))) { game->map.selected++; - al_play_sample(game->map.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); + if (game->fx) al_play_sample(game->map.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); } else if ((ev->keyboard.keycode==ALLEGRO_KEY_LEFT) || (ev->keyboard.keycode==ALLEGRO_KEY_RIGHT) || (ev->keyboard.keycode==ALLEGRO_KEY_UP) || (ev->keyboard.keycode==ALLEGRO_KEY_DOWN)) { - al_play_sample(game->map.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); + if (game->fx) al_play_sample(game->map.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); } else if (ev->keyboard.keycode==ALLEGRO_KEY_ENTER) { PrintConsole(game, "Selecting level %d...", game->map.selected); UnloadGameState(game); diff --git a/src/menu.c b/src/menu.c index 8aa1544..4e1edc6 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1,5 +1,6 @@ #include #include +#include "config.h" #include "menu.h" void Menu_Draw(struct Game *game) { @@ -35,13 +36,22 @@ void Menu_Draw(struct Game *game) { ALLEGRO_FONT *font; char* text; font = game->menu.font; if (game->menu.selected==0) font = game->menu.font_selected; - text = "Start game"; if (game->menu.options) text="Fullscreen: on"; + text = "Start game"; if (game->menu.options) text="Control settings"; al_draw_text_with_shadow(font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.5, ALLEGRO_ALIGN_CENTRE, text); font = game->menu.font; if (game->menu.selected==1) font = game->menu.font_selected; - text = "Options"; if (game->menu.options) text="Music: on"; + text = "Options"; if (game->menu.options) text="Video settings"; al_draw_text_with_shadow(font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.6, ALLEGRO_ALIGN_CENTRE, text); font = game->menu.font; if (game->menu.selected==2) font = game->menu.font_selected; - text = "About"; if (game->menu.options) text="Sounds: on"; + text = "About"; if (game->menu.options) { + if ((game->music) && (game->fx)) + text="Sounds: all"; + else if (game->music) + text="Sounds: music only"; + else if (game->fx) + text="Sounds: fx only"; + else + text="Sounds: none"; + } al_draw_text_with_shadow(font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.7, ALLEGRO_ALIGN_CENTRE, text); font = game->menu.font; if (game->menu.selected==3) font = game->menu.font_selected; text = "Exit"; if (game->menu.options) text="Back"; @@ -163,9 +173,13 @@ void Menu_Unload(struct Game *game) { al_destroy_sample(game->menu.click_sample); } +void play_samples(struct Game *game) { + if (game->music) al_play_sample(game->menu.sample, 0.8, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL); + if (game->fx) al_play_sample(game->menu.rain_sample, 0.7, -0.3, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL); +} + void Menu_Load(struct Game *game) { - al_play_sample(game->menu.sample, 0.8, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL); - al_play_sample(game->menu.rain_sample, 0.7, -0.3, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL); + play_samples(game); game->menu.menu_fade_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display)); ALLEGRO_EVENT ev; @@ -187,28 +201,36 @@ void Menu_Load(struct Game *game) { int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { if (ev->keyboard.keycode==ALLEGRO_KEY_UP) { game->menu.selected--; - al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); + if (game->fx) al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); } else if (ev->keyboard.keycode==ALLEGRO_KEY_DOWN) { game->menu.selected++; - al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); + if (game->fx) al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); } else if ((!game->menu.options) && (((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->menu.selected==3)) || (ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE))) { - al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); + if (game->fx) al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); return 1; } else if ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (!game->menu.options) && (game->menu.selected==0)) { - al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); + if (game->fx) al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); UnloadGameState(game); game->gamestate = GAMESTATE_LOADING; game->loadstate = GAMESTATE_INTRO; } else if ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (!game->menu.options) && (game->menu.selected==2)) { - al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); + if (game->fx) al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); UnloadGameState(game); game->gamestate = GAMESTATE_LOADING; game->loadstate = GAMESTATE_ABOUT; } else if (((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (!game->menu.options) && (game->menu.selected==1)) || (((game->menu.options) && ((ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE))) || (((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->menu.selected==3))))) { - al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); + if (game->fx) al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); game->menu.options=!game->menu.options; game->menu.selected=0; PrintConsole(game, "options state changed %d", game->menu.options); + } else if ((game->menu.options) && (game->menu.selected==2)) { + al_stop_samples(); + if ((game->music) && (game->fx)) { game->music=0; SetConfigOption("[SuperDerpy]", "music", "0"); } + else if (game->fx) { game->music=1; game->fx=0; SetConfigOption("[SuperDerpy]", "music", "1"); SetConfigOption("[SuperDerpy]", "fx", "0"); } + else if (game->music) { game->music=0; SetConfigOption("[SuperDerpy]", "music", "0"); } + else { game->music=1; game->fx=1; SetConfigOption("[SuperDerpy]", "music", "1"); SetConfigOption("[SuperDerpy]", "fx", "1"); } + if (game->fx) al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); + play_samples(game); } if (game->menu.selected==-1) game->menu.selected=3; if (game->menu.selected==4) game->menu.selected=0;