From 2863639aa4f18bffd8456c5d78c9ec1bf3d6b80a Mon Sep 17 00:00:00 2001 From: Compendium Date: Tue, 31 Jul 2012 17:06:25 +0200 Subject: Added options for volume control (-v, --volume) --- README | 1 + nyan.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/README b/README index 4028347..9b5536f 100644 --- a/README +++ b/README @@ -6,5 +6,6 @@ Usage: nyancat [OPTIONS] -nc, --nocursor Don't show the cursor (default) -sc, --cursor, --showcursor Show the cursor -ns, --nosound Don't play sound + -v, --volume Sets Volume, if enabled, from 0 - 128 -r, --resolution Make next two arguments the screen resolution to use (0 and 0 for full resolution) (800x600 default) -hw, -sw Use hardware or software SDL rendering, respectively. Hardware is default diff --git a/nyan.c b/nyan.c index d7ebdbb..790405d 100644 --- a/nyan.c +++ b/nyan.c @@ -76,6 +76,7 @@ static SDL_Event event; static int running = 1; static int SURF_TYPE = SDL_HWSURFACE; static int sound = 1; +static int sound_volume = 128; static int fullscreen = 1; static int catsize = 0; static int cursor = 0; @@ -259,6 +260,16 @@ handle_args(int argc, char **argv) { cursor = 1; else if(!strcmp(argv[i], "-ns") || !strcmp(argv[i], "--nosound")) sound = 0; + else if((!strcmp(argv[i], "-v") || !strcmp(argv[i], "--volume")) && i < argc - 1) { + int vol = atoi(argv[++i]); + if(vol >= 0 && vol <= 128){ + sound_volume = vol; + } + else { + puts("Arguments for Volume are not valid. Disabling sound."); + sound = 0; + } + } else if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) usage(argv[0]); else if(!strcmp(argv[i], "-c") || !strcmp(argv[i], "--catsize")) { @@ -320,6 +331,7 @@ init(void) { Mix_OpenAudio( 44100, AUDIO_S16, 2, 256 ); load_music(); Mix_PlayMusic(music, 0); + Mix_VolumeMusic(sound_volume); } /* Choose our image set */ @@ -549,6 +561,7 @@ usage(char* exname) { -nc, --nocursor Don't show the cursor (default)\n\ -sc, --cursor, --showcursor Show the cursor\n\ -ns, --nosound Don't play sound\n\ + -v, --volume Set Volume, if enabled, from 0 - 128\n\ -r, --resolution Make next two arguments the screen \n\ resolution to use (0 and 0 for full \n\ resolution) (800x600 default)\n\ -- cgit v1.2.3