mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 11:06:44 +01:00
sound volume settings
This commit is contained in:
parent
9b33a0af12
commit
13aa555481
5 changed files with 83 additions and 27 deletions
1
TODO
1
TODO
|
@ -1,7 +1,6 @@
|
|||
- moar documentation
|
||||
- moar video settings
|
||||
- command line options
|
||||
- sound volume settings
|
||||
|
||||
- playable levels :D
|
||||
- control settings
|
||||
|
|
|
@ -29,7 +29,7 @@ void FillPage(struct Game *game, int page) {
|
|||
|
||||
//if (game->intro.audiostream) al_destroy_audio_stream(game->intro.audiostream);
|
||||
game->intro.audiostream = al_load_audio_stream(filename, 4, 1024);
|
||||
al_attach_audio_stream_to_mixer(game->intro.audiostream, game->audio.fx);
|
||||
al_attach_audio_stream_to_mixer(game->intro.audiostream, game->audio.voice);
|
||||
al_set_audio_stream_playing(game->intro.audiostream, false);
|
||||
al_set_audio_stream_gain(game->intro.audiostream, 1.75);
|
||||
|
||||
|
|
18
src/main.c
18
src/main.c
|
@ -274,8 +274,9 @@ int main(int argc, char **argv){
|
|||
struct Game game;
|
||||
|
||||
game.fullscreen = atoi(GetConfigOptionDefault("SuperDerpy", "fullscreen", "1"));
|
||||
game.music = atoi(GetConfigOptionDefault("SuperDerpy", "music", "1"));
|
||||
game.fx = atoi(GetConfigOptionDefault("SuperDerpy", "fx", "1"));
|
||||
game.music = atoi(GetConfigOptionDefault("SuperDerpy", "music", "10"));
|
||||
game.voice = atoi(GetConfigOptionDefault("SuperDerpy", "voice", "10"));
|
||||
game.fx = atoi(GetConfigOptionDefault("SuperDerpy", "fx", "10"));
|
||||
game.fps = atoi(GetConfigOptionDefault("SuperDerpy", "fps", "60"));
|
||||
if (game.fps<1) game.fps=60;
|
||||
game.debug = atoi(GetConfigOptionDefault("SuperDerpy", "debug", "0"));
|
||||
|
@ -355,15 +356,18 @@ int main(int argc, char **argv){
|
|||
return -1;
|
||||
}
|
||||
|
||||
game.audio.voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2);
|
||||
game.audio.v = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2);
|
||||
game.audio.mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2);
|
||||
game.audio.fx = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2);
|
||||
game.audio.music = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2);
|
||||
al_attach_mixer_to_voice(game.audio.mixer, game.audio.voice);
|
||||
game.audio.voice = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2);
|
||||
al_attach_mixer_to_voice(game.audio.mixer, game.audio.v);
|
||||
al_attach_mixer_to_mixer(game.audio.fx, game.audio.mixer);
|
||||
al_attach_mixer_to_mixer(game.audio.music, game.audio.mixer);
|
||||
if (!game.fx) al_set_mixer_gain(game.audio.fx, 0.0);
|
||||
if (!game.music) al_set_mixer_gain(game.audio.music, 0.0);
|
||||
al_attach_mixer_to_mixer(game.audio.voice, game.audio.mixer);
|
||||
al_set_mixer_gain(game.audio.fx, game.fx/10.0);
|
||||
al_set_mixer_gain(game.audio.music, game.music/10.0);
|
||||
al_set_mixer_gain(game.audio.voice, game.music/10.0);
|
||||
|
||||
al_register_event_source(game.event_queue, al_get_display_event_source(game.display));
|
||||
al_register_event_source(game.event_queue, al_get_timer_event_source(game.timer));
|
||||
|
@ -441,7 +445,7 @@ int main(int argc, char **argv){
|
|||
al_destroy_mixer(game.audio.fx);
|
||||
al_destroy_mixer(game.audio.music);
|
||||
al_destroy_mixer(game.audio.mixer);
|
||||
al_destroy_voice(game.audio.voice);
|
||||
al_destroy_voice(game.audio.v);
|
||||
al_uninstall_audio();
|
||||
DeinitConfig();
|
||||
if (game.restart) {
|
||||
|
|
11
src/main.h
11
src/main.h
|
@ -62,7 +62,8 @@ enum menustate_enum {
|
|||
MENUSTATE_OPTIONS,
|
||||
MENUSTATE_CONTROLS,
|
||||
MENUSTATE_VIDEO,
|
||||
MENUSTATE_PAUSE
|
||||
MENUSTATE_PAUSE,
|
||||
MENUSTATE_AUDIO
|
||||
};
|
||||
|
||||
/*! \brief Resources used by Menu state. */
|
||||
|
@ -166,8 +167,9 @@ struct Game {
|
|||
ALLEGRO_TIMER *timer;
|
||||
ALLEGRO_BITMAP *console;
|
||||
bool showconsole;
|
||||
bool fx;
|
||||
bool music;
|
||||
int fx;
|
||||
int music;
|
||||
int voice;
|
||||
bool fullscreen;
|
||||
bool debug;
|
||||
int fps;
|
||||
|
@ -183,9 +185,10 @@ struct Game {
|
|||
struct Level level;
|
||||
struct Pause pause;
|
||||
struct {
|
||||
ALLEGRO_VOICE *voice;
|
||||
ALLEGRO_VOICE *v;
|
||||
ALLEGRO_MIXER *mixer;
|
||||
ALLEGRO_MIXER *music;
|
||||
ALLEGRO_MIXER *voice;
|
||||
ALLEGRO_MIXER *fx;
|
||||
} audio;
|
||||
};
|
||||
|
|
78
src/menu.c
78
src/menu.c
|
@ -25,7 +25,7 @@
|
|||
|
||||
void DrawMenuState(struct Game *game) {
|
||||
ALLEGRO_FONT *font;
|
||||
char* text;
|
||||
char* text = malloc(255*sizeof(char));
|
||||
struct ALLEGRO_COLOR color;
|
||||
switch (game->menu.menustate) {
|
||||
case MENUSTATE_MAIN:
|
||||
|
@ -44,25 +44,33 @@ void DrawMenuState(struct Game *game) {
|
|||
font = game->menu.font; if (game->menu.selected==1) font = game->menu.font_selected;
|
||||
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, "Video settings");
|
||||
font = game->menu.font; if (game->menu.selected==2) font = game->menu.font_selected;
|
||||
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, "Audio settings");
|
||||
font = game->menu.font; if (game->menu.selected==3) font = game->menu.font_selected;
|
||||
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.8, ALLEGRO_ALIGN_CENTRE, "Back");
|
||||
break;
|
||||
case MENUSTATE_AUDIO:
|
||||
font = game->menu.font; if (game->menu.selected==0) font = game->menu.font_selected;
|
||||
if (game->music) sprintf(text, "Music volume: %d0%%", game->music);
|
||||
else sprintf(text, "Music disabled");
|
||||
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;
|
||||
if (game->fx) sprintf(text, "Effects volume: %d0%%", game->fx);
|
||||
else sprintf(text, "Effects disabled");
|
||||
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;
|
||||
if (game->voice) sprintf(text, "Voice volume: %d0%%", game->voice);
|
||||
else sprintf(text, "Voice disabled");
|
||||
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;
|
||||
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.8, ALLEGRO_ALIGN_CENTRE, "Back");
|
||||
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.8, ALLEGRO_ALIGN_CENTRE, "Back");
|
||||
break;
|
||||
case MENUSTATE_VIDEO:
|
||||
if (game->menu.options.fullscreen) {
|
||||
text="Fullscreen: yes";
|
||||
sprintf(text, "Fullscreen: yes");
|
||||
color = al_map_rgba(0,0,0,128);
|
||||
}
|
||||
else {
|
||||
text="Fullscreen: no";
|
||||
sprintf(text, "Fullscreen: no");
|
||||
color = al_map_rgba(255,255,255,255);
|
||||
}
|
||||
font = game->menu.font; if (game->menu.selected==0) font = game->menu.font_selected;
|
||||
|
@ -90,6 +98,7 @@ void DrawMenuState(struct Game *game) {
|
|||
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, "Not implemented yet");
|
||||
break;
|
||||
}
|
||||
free(text);
|
||||
}
|
||||
|
||||
void Menu_Draw(struct Game *game) {
|
||||
|
@ -290,6 +299,7 @@ int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
|||
}
|
||||
|
||||
if (ev->keyboard.keycode==ALLEGRO_KEY_ENTER) {
|
||||
char *text;
|
||||
al_play_sample_instance(game->menu.click);
|
||||
switch (game->menu.menustate) {
|
||||
case MENUSTATE_MAIN:
|
||||
|
@ -314,6 +324,38 @@ int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
|||
break;
|
||||
}
|
||||
break;
|
||||
case MENUSTATE_AUDIO:
|
||||
text = malloc(255*sizeof(char));
|
||||
switch (game->menu.selected) {
|
||||
case 0:
|
||||
game->music--;
|
||||
if (game->music<0) game->music=10;
|
||||
sprintf(text, "%d", game->music);
|
||||
SetConfigOption("SuperDerpy", "music", text);
|
||||
al_set_mixer_gain(game->audio.music, game->music/10.0);
|
||||
break;
|
||||
case 1:
|
||||
game->fx--;
|
||||
if (game->fx<0) game->fx=10;
|
||||
sprintf(text, "%d", game->fx);
|
||||
SetConfigOption("SuperDerpy", "fx", text);
|
||||
al_set_mixer_gain(game->audio.fx, game->fx/10.0);
|
||||
break;
|
||||
case 2:
|
||||
game->voice--;
|
||||
if (game->voice<0) game->voice=10;
|
||||
sprintf(text, "%d", game->voice);
|
||||
SetConfigOption("SuperDerpy", "voice", text);
|
||||
al_set_mixer_gain(game->audio.voice, game->voice/10.0);
|
||||
break;
|
||||
case 3:
|
||||
game->menu.menustate=MENUSTATE_OPTIONS;
|
||||
game->menu.selected=0;
|
||||
PrintConsole(game, "menu state changed %d", game->menu.menustate);
|
||||
break;
|
||||
}
|
||||
free(text);
|
||||
break;
|
||||
case MENUSTATE_OPTIONS:
|
||||
switch (game->menu.selected) {
|
||||
case 0:
|
||||
|
@ -327,7 +369,7 @@ int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
|||
PrintConsole(game, "menu state changed %d", game->menu.menustate);
|
||||
break;
|
||||
case 2:
|
||||
if ((game->music) && (game->fx)) { game->music=0; SetConfigOption("SuperDerpy", "music", "0");
|
||||
/* if ((game->music) && (game->fx)) { game->music=0; SetConfigOption("SuperDerpy", "music", "0");
|
||||
al_set_mixer_gain(game->audio.music, 0.0);
|
||||
}
|
||||
else if (game->fx) { game->music=1; game->fx=0; SetConfigOption("SuperDerpy", "music", "1"); SetConfigOption("SuperDerpy", "fx", "0");
|
||||
|
@ -340,7 +382,10 @@ int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
|||
else { game->music=1; game->fx=1; SetConfigOption("SuperDerpy", "music", "1"); SetConfigOption("SuperDerpy", "fx", "1");
|
||||
al_set_mixer_gain(game->audio.music, 1.0);
|
||||
al_set_mixer_gain(game->audio.fx, 1.0);
|
||||
}
|
||||
}*/
|
||||
game->menu.menustate=MENUSTATE_AUDIO;
|
||||
game->menu.selected=0;
|
||||
PrintConsole(game, "menu state changed %d", game->menu.menustate);
|
||||
break;
|
||||
case 3:
|
||||
game->menu.menustate=MENUSTATE_MAIN;
|
||||
|
@ -427,6 +472,11 @@ int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
|||
game->menu.selected=0;
|
||||
PrintConsole(game, "menu state changed %d", game->menu.menustate);
|
||||
break;
|
||||
case MENUSTATE_AUDIO:
|
||||
game->menu.menustate=MENUSTATE_OPTIONS;
|
||||
game->menu.selected=0;
|
||||
PrintConsole(game, "menu state changed %d", game->menu.menustate);
|
||||
break;
|
||||
case MENUSTATE_CONTROLS:
|
||||
game->menu.menustate=MENUSTATE_OPTIONS;
|
||||
game->menu.selected=0;
|
||||
|
|
Loading…
Reference in a new issue