From a6e764aab14a8157ba5b59c3d271a2073f9eae80 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Gl=C3=A4=C3=9Fer?= Date: Fri, 19 Dec 2003 21:40:22 +0000 Subject: [PATCH] Implemented --help and --disable-sound (patch by Duong-Khang NGUYEN ) , cleaned up some #define NOSOUNDs. Play a sound, when tux gets a new live. Improved 'make clean'. SVN-Revision: 17 --- CHANGES.txt | 7 +++-- Makefile | 6 ++-- README.txt | 35 ++++++++++++----------- TODO.txt | 10 ++++--- src/gameloop.c | 87 +++++++------------------------------------------------- src/globals.h | 4 --- src/intro.c | 4 --- src/screen.c | 4 --- src/setup.c | 65 ++++++++++++++++++++++++++++++------------ src/sound.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- src/sound.h | 42 +++++++++++++++++++++++++++ src/supertux.c | 4 --- src/title.c | 4 --- 13 files changed, 210 insertions(+), 152 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 59cfcc11a..86244bd75 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,8 +4,11 @@ by Bill Kendrick bill@newbreedsoftware.com http://www.newbreedsoftware.com/supertux/ -0.0.5 - ??? ------------ +0.0.5 - December 19th, 2003 - ??? +--------------------------- + * command-line option "--disable-sound" and "--help" now work + Duong-Khang NGUYEN + * Added high score feature. Adam Czachorowski diff --git a/Makefile b/Makefile index bc5a80af8..050f8211a 100644 --- a/Makefile +++ b/Makefile @@ -78,9 +78,9 @@ win32: chmod 644 SDL*.dll clean: - -rm supertux supertux.exe - -rm obj/*.o - -rm SDL*.dll + -rm -f supertux supertux.exe + -rm -f obj/*.o + -rm -f SDL*.dll # Main executable: diff --git a/README.txt b/README.txt index bdb2e22be..77396168b 100644 --- a/README.txt +++ b/README.txt @@ -6,8 +6,8 @@ http://www.newbreedsoftware.com/supertux/ Version 0.0.5 -December 9, 2003 - +December 17, 2003 + NOTICE! THIS GAME IS UNDER CONSTRUCTION! Things you'll notice: @@ -51,8 +51,6 @@ RUNNING THE GAME The program accepts some options: -UNDER CONSTRUCTION - --disable-sound - If sound support was compiled in, this will disable it for this session of the game. @@ -82,24 +80,25 @@ SCREEN LAYOUT ------------- UNDER CONSTRUCTION - +----------------------------------------+ - |SCORE 1230 TIME 128 DISTROS 93 | - | | - | | - | | - | | - | | - | | - | | - | | - | | - | | - +----------------------------------------+ + +-------------------------------------------------+ + |SCORE 1230 TIME 128 DISTROS 93 | + |HIGH 100 | + | | + | | + | | + | | + | | + | | + | | + | | + | | + +-------------------------------------------------+ Status ------ Your score is displayed at the upper left. + Under your current score is the last highscore. The amount of time you have left to complete this level is displayed in the center at the top of the screen. (Note: Time is NOT in seconds!) @@ -146,6 +145,8 @@ SCORING the first and onto the second, it's worth 100 points. If you also get the third, it's worth 150 points. + You can also score by shooting at the ennemies. Don't forget to drink + the coffee in order to get the ability to fire. GAME OVER SCREEN ---------------- diff --git a/TODO.txt b/TODO.txt index b21cc16ed..244dbf14d 100644 --- a/TODO.txt +++ b/TODO.txt @@ -6,16 +6,18 @@ http://www.newbreedsoftware.com/supertux/ Version 0.0.5 -December 9, 2003 +December 17, 2003 TO DO ----- Different, better and more music - One-ups More enemies Redo laptop enemy graphics More levels Play as Gown, rescuing Tux - End game on game over - High score + +DONE +----- + One-ups, End game on game over (by Tobias Glaesser ) + High score (by Adam Czachorowski ) \ No newline at end of file diff --git a/src/gameloop.c b/src/gameloop.c index 97a5f2be5..808e142aa 100644 --- a/src/gameloop.c +++ b/src/gameloop.c @@ -18,10 +18,6 @@ #include #include -#ifndef NOSOUND -#include -#endif - #ifdef LINUX #include #include @@ -55,7 +51,7 @@ enum { SND_EXCELLENT, SND_COFFEE, SND_SHOOT, - NUM_SOUNDS + SND_LIFEUP }; char * soundfilenames[NUM_SOUNDS] = { @@ -73,7 +69,8 @@ char * soundfilenames[NUM_SOUNDS] = { DATA_PREFIX "/sounds/upgrade.wav", DATA_PREFIX "/sounds/excellent.wav", DATA_PREFIX "/sounds/coffee.wav", - DATA_PREFIX "/sounds/shoot.wav" + DATA_PREFIX "/sounds/shoot.wav", + DATA_PREFIX "/sounds/lifeup.wav" }; @@ -108,10 +105,6 @@ SDL_Surface * tux_right[3], * tux_left[3], * bigcape_right[2], * bigcape_left[2], * ducktux_right, * ducktux_left, * skidtux_right, * skidtux_left; -#ifndef NOSOUND -Mix_Chunk * sounds[NUM_SOUNDS]; -Mix_Music * song; -#endif unsigned char * tiles[15]; bouncy_distro_type bouncy_distros[NUM_BOUNCY_DISTROS]; broken_brick_type broken_bricks[NUM_BROKEN_BRICKS]; @@ -275,6 +268,10 @@ int gameloop(void) { tux_size = !tux_size; } + else if (key == SDLK_END) + { + distros += 50; + } } #ifdef JOY_YES else if (event.type == SDL_JOYAXISMOTION) @@ -331,9 +328,9 @@ int gameloop(void) tux_dir == LEFT) { tux_skidding = SKID_TIME; -#ifndef NOSOUND + playsound(sounds[SND_SKID]); -#endif + } tux_dir = RIGHT; } @@ -385,9 +382,7 @@ int gameloop(void) tux_dir == RIGHT) { tux_skidding = SKID_TIME; -#ifndef NOSOUND playsound(sounds[SND_SKID]); -#endif } tux_dir = LEFT; } @@ -468,12 +463,10 @@ int gameloop(void) { jumping = YES; -#ifndef NOSOUND if (tux_size == SMALL) playsound(sounds[SND_JUMP]); else playsound(sounds[SND_BIGJUMP]); -#endif } } } @@ -527,13 +520,11 @@ int gameloop(void) if (tux_y >= 480) { -#ifndef NOSOUND if (use_sound) { if (Mix_PlayingMusic()) Mix_HaltMusic(); } -#endif if (next_level) { @@ -804,9 +795,7 @@ int gameloop(void) if (distro_counter <= 0) change(tux_x, tux_y, scroll_x, 'a'); -#ifndef NOSOUND playsound(sounds[SND_DISTRO]); -#endif score = score + SCORE_DISTRO; distros++; } @@ -826,9 +815,7 @@ int gameloop(void) if (distro_counter <= 0) change(tux_x + 31, tux_y, scroll_x, 'a'); -#ifndef NOSOUND playsound(sounds[SND_DISTRO]); -#endif score = score + SCORE_DISTRO; distros++; } @@ -877,6 +864,7 @@ int gameloop(void) distros = distros - DISTROS_LIFEUP; lives++; + playsound(sounds[SND_LIFEUP]); } @@ -1082,9 +1070,7 @@ int gameloop(void) /* Play death sound: */ -#ifndef NOSOUND playsound(sounds[SND_FALL]); -#endif } } } @@ -1175,25 +1161,19 @@ int gameloop(void) if (upgrades[i].kind == UPGRADE_MINTS) { -#ifndef NOSOUND playsound(sounds[SND_EXCELLENT]); -#endif tux_size = BIG; super_bkgd_time = 8; } else if (upgrades[i].kind == UPGRADE_COFFEE) { -#ifndef NOSOUND playsound(sounds[SND_COFFEE]); -#endif tux_got_coffee = YES; super_bkgd_time = 4; } else if (upgrades[i].kind == UPGRADE_HERRING) { -#ifndef NOSOUND playsound(sounds[SND_HERRING]); -#endif tux_invincible_time = 200; super_bkgd_time = 4; } @@ -1322,10 +1302,8 @@ int gameloop(void) { bad_guys[i].dir = !bad_guys[i].dir; -#ifndef NOSOUND if (bad_guys[i].mode == KICK) playsound(sounds[SND_RICOCHET]); -#endif } } @@ -1349,9 +1327,7 @@ int gameloop(void) bad_guys[j].dying = FALLING; bad_guys[j].ym = -8; -#ifndef NOSOUND playsound(sounds[SND_FALL]); -#endif add_score(bad_guys[i].x - scroll_x, bad_guys[i].y, 100); @@ -1448,9 +1424,7 @@ int gameloop(void) add_score(bad_guys[i].x - scroll_x, bad_guys[i].y, 50 * score_multiplier); -#ifndef NOSOUND playsound(sounds[SND_SQUISH]); -#endif } else if (bad_guys[i].kind == BAD_LAPTOP) { @@ -1484,9 +1458,7 @@ int gameloop(void) bad_guys[i].y, 25 * score_multiplier); -#ifndef NOSOUND /* playsound(sounds[SND_SQUISH]); */ -#endif } else if (bad_guys[i].kind == -1) { @@ -1548,9 +1520,7 @@ int gameloop(void) { bad_guys[i].dying = FALLING; bad_guys[i].ym = -8; -#ifndef NOSOUND playsound(sounds[SND_FALL]); -#endif } } } @@ -1565,9 +1535,7 @@ int gameloop(void) { bad_guys[i].dying = FALLING; bad_guys[i].ym = -8; -#ifndef NOSOUND playsound(sounds[SND_FALL]); -#endif } } } @@ -2153,7 +2121,6 @@ int gameloop(void) /* Keep playing music: */ -#ifndef NOSOUND if (use_sound) { if (!Mix_PlayingMusic()) @@ -2161,7 +2128,6 @@ int gameloop(void) Mix_PlayMusic(song, 1); } } -#endif /* Pause til next frame: */ @@ -2183,13 +2149,11 @@ int gameloop(void) } while (!done && !quit); -#ifndef NOSOUND if (use_sound) { if (Mix_PlayingMusic()) Mix_HaltMusic(); } -#endif unloadlevelgfx(); unloadlevelsong(); @@ -2421,7 +2385,6 @@ void loadlevelsong(void) { char * song_path; -#ifndef NOSOUND song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + strlen(song_title) + 8)); @@ -2430,7 +2393,6 @@ void loadlevelsong(void) song = load_song(DATA_PREFIX "/music/ji_turn.it"); free(song_path); -#endif } @@ -2457,12 +2419,10 @@ void unloadlevelgfx(void) void unloadlevelsong(void) { -#ifndef NOSOUND if (use_sound) { Mix_FreeMusic(song); } -#endif } @@ -2470,9 +2430,7 @@ void unloadlevelsong(void) void loadshared(void) { -#ifndef NOSOUND int i; -#endif /* Tuxes: */ @@ -2792,13 +2750,12 @@ void loadshared(void) /* Sound effects: */ -#ifndef NOSOUND if (use_sound) { for (i = 0; i < NUM_SOUNDS; i++) sounds[i] = load_sound(soundfilenames[i]); + } -#endif } @@ -2888,13 +2845,11 @@ void unloadshared(void) SDL_FreeSurface(img_golden_herring); -#ifndef NOSOUND if (use_sound) { for (i = 0; i < NUM_SOUNDS; i++) Mix_FreeChunk(sounds[i]); } -#endif } @@ -3111,9 +3066,7 @@ void trybreakbrick(int x, int y, int sx) if (distro_counter <= 0) change(x, y, sx, 'a'); -#ifndef NOSOUND playsound(sounds[SND_DISTRO]); -#endif score = score + SCORE_DISTRO; distros++; } @@ -3133,9 +3086,7 @@ void trybreakbrick(int x, int y, int sx) /* Get some score: */ -#ifndef NOSOUND playsound(sounds[SND_BRICK]); -#endif score = score + SCORE_BRICK; } } @@ -3148,9 +3099,7 @@ void bumpbrick(int x, int y, int sx) add_bouncy_brick(((x + sx + 1) / 32) * 32, (y / 32) * 32); -#ifndef NOSOUND playsound(sounds[SND_BRICK]); -#endif } @@ -3167,9 +3116,7 @@ void tryemptybox(int x, int y, int sx) add_bouncy_distro(((x + sx + 1) / 32) * 32, (y / 32) * 32 - 32); -#ifndef NOSOUND playsound(sounds[SND_DISTRO]); -#endif score = score + SCORE_DISTRO; distros++; } @@ -3194,9 +3141,7 @@ void tryemptybox(int x, int y, int sx) UPGRADE_COFFEE); } -#ifndef NOSOUND playsound(sounds[SND_UPGRADE]); -#endif } else if (shape(x, y, sx) == '!') { @@ -3221,9 +3166,7 @@ void trygrabdistro(int x, int y, int sx, int bounciness) if (shape(x, y, sx) == '$') { change(x, y, sx, '.'); -#ifndef NOSOUND playsound(sounds[SND_DISTRO]); -#endif if (bounciness == BOUNCE) { @@ -3409,9 +3352,7 @@ void trybumpbadguy(int x, int y, int sx) { bad_guys[i].dying = FALLING; bad_guys[i].ym = -8; -#ifndef NOSOUND playsound(sounds[SND_FALL]); -#endif } } } @@ -3427,9 +3368,7 @@ void trybumpbadguy(int x, int y, int sx) { upgrades[i].xm = -upgrades[i].xm; upgrades[i].ym = -8; -#ifndef NOSOUND playsound(sounds[SND_BUMP_UPGRADE]); -#endif } } } @@ -3468,9 +3407,7 @@ void killtux(int mode) { tux_ym = -16; -#ifndef NOSOUND playsound(sounds[SND_HURT]); -#endif if (tux_dir == RIGHT) tux_xm = -8; @@ -3525,9 +3462,7 @@ void add_bullet(int x, int y, int dir, int xm) bullets[found].y = y; bullets[found].ym = BULLET_STARTING_YM; -#ifndef NOSOUND playsound(sounds[SND_SHOOT]); -#endif } } diff --git a/src/globals.h b/src/globals.h index c25c85ff3..9425bee96 100644 --- a/src/globals.h +++ b/src/globals.h @@ -17,10 +17,6 @@ #include #include -#ifndef NOSOUND -#include -#endif - SDL_Surface * screen; SDL_Surface * letters_black, * letters_gold, * letters_blue, * letters_red; diff --git a/src/intro.c b/src/intro.c index 47de7260e..f340c496a 100644 --- a/src/intro.c +++ b/src/intro.c @@ -18,10 +18,6 @@ #include #include -#ifndef NOSOUND -#include -#endif - #ifdef LINUX #include #include diff --git a/src/screen.c b/src/screen.c index 5f0be628b..eaa7d6daa 100644 --- a/src/screen.c +++ b/src/screen.c @@ -18,10 +18,6 @@ #include #include -#ifndef NOSOUND -#include -#endif - #ifdef LINUX #include #include diff --git a/src/setup.c b/src/setup.c index 0c09c085e..39e6688da 100644 --- a/src/setup.c +++ b/src/setup.c @@ -18,10 +18,6 @@ #include #include -#ifndef NOSOUND -#include -#endif - #ifdef LINUX #include #include @@ -32,6 +28,7 @@ #include "globals.h" #include "setup.h" #include "screen.h" +#include "sound.h" /* Local function prototypes: */ @@ -141,20 +138,18 @@ void st_setup(void) /* Open sound: */ -#ifndef NOSOUND if (use_sound == YES) { - if (Mix_OpenAudio(11025, AUDIO_S16, 2, 512) < 0) + if (Mix_OpenAudio(44100, AUDIO_S16, 2, 512) < 0) { fprintf(stderr, - "\nWarning: I could not set up audio for 11025 Hz " + "\nWarning: I could not set up audio for 44100 Hz " "16-bit stereo.\n" "The Simple DirectMedia error that occured was:\n" "%s\n\n", SDL_GetError()); - use_sound = 0; + use_sound = NO; } } -#endif /* Open display: */ @@ -283,8 +278,11 @@ void parseargs(int argc, char * argv[]) /* Set defaults: */ use_fullscreen = NO; + #ifndef NOSOUND use_sound = YES; - + #else + use_sound = NO; + #endif /* Parse arguments: */ @@ -310,14 +308,45 @@ void parseargs(int argc, char * argv[]) printf("Super Tux - version " VERSION "\n"); exit(0); } + else if (strcmp(argv[i], "--disable-sound") == 0) + { + /* Disable the compiled in sound & music feature */ + #ifndef NOSOUND + printf("Sounds and music disabled \n"); + use_sound = NO; + #else + printf("Sounds and music feature is not compiled in \n"); + #endif + } else if (strcmp(argv[i], "--help") == 0) - { - /* Show version: */ - - printf("Super Tux - Help summary\n"); - printf("[ under construction ]\n"); - exit(0); - } + { /* Show help: */ + + printf("Super Tux " VERSION "\n\n"); + + printf("---------- Command-line options ----------\n\n"); + + printf(" --disable-sound - If sound support was compiled in, this will\n disable it for this session of the game.\n\n"); + + printf(" --fullscreen - Run in fullscreen mode.\n\n"); + + printf(" --help - Display a help message summarizing command-line\n options, license and game controls.\n\n"); + + printf(" --usage - Display a brief message summarizing command-line options.\n\n"); + + printf(" --version - Display the version of SuperTux you're running.\n\n\n"); + + + printf("---------- License ----------\n\n"); + printf(" This program comes with ABSOLUTELY NO WARRANTY.\n"); + printf(" This is free software, and you are welcome to redistribute\n"); + printf(" or modify it under certain conditions. See the file \n"); + printf(" \"COPYING.txt\" for more details.\n\n\n"); + + printf("---------- Game controls ----------\n\n"); + printf(" Please see the file \"README.txt\"\n\n"); + + exit(0); + } else { /* Unknown - complain! */ @@ -345,7 +374,7 @@ void usage(char * prog, int ret) /* Display the usage message: */ - fprintf(fi, "Usage: %s [--fullscreen] | [--usage | --help | --version]\n", + fprintf(fi, "Usage: %s [--fullscreen] | [--disable-sound] | [--usage | --help | --version]\n", prog); diff --git a/src/sound.c b/src/sound.c index 69c980bc1..87d1e90ec 100644 --- a/src/sound.c +++ b/src/sound.c @@ -10,8 +10,6 @@ April 22, 2000 - July 15, 2002 */ -#ifndef NOSOUND - #include #include #include @@ -20,8 +18,6 @@ #include #include -#include - #ifdef LINUX #include #include @@ -33,6 +29,7 @@ #include "sound.h" #include "setup.h" +#ifndef NOSOUND /* --- LOAD A SOUND --- */ @@ -54,14 +51,6 @@ Mix_Chunk * load_sound(char * file) } -/* --- PLAY A SOUND --- */ - -void playsound(Mix_Chunk * snd) -{ - Mix_PlayChannel(-1, snd, 0); -} - - /* --- LOAD A SONG --- */ Mix_Music * load_song(char * file) @@ -81,4 +70,81 @@ Mix_Music * load_song(char * file) return (sng); } + +/* --- PLAY A SOUND --- */ + + void playsound(Mix_Chunk * snd) + { + // this won't call the function if the user has disabled sound + if (use_sound) { + Mix_PlayChannel(-1, snd, 0); + } +} + + +void free_chunk(Mix_Chunk *chunk) +{ + if (use_sound) + Mix_FreeChunk( chunk ); +} + +int playing_music(void) +{ + if (use_sound) { + return Mix_PlayingMusic(); + } + else { + // we are in --disable-sound or NOSOUND, we can't be playing music ! + return 0; + } +} + + +int halt_music(void) +{ + if (use_sound) { + return Mix_HaltMusic(); + } + else { + return 0; + } +} + + +int play_music(Mix_Music *music, int loops) +{ + if (use_sound) { + return Mix_PlayMusic(music, loops); + } + else { + // return error since you're trying to play music in --disable-sound mode + return -1; + } +} + + +void free_music(Mix_Music *music) +{ + if (use_sound) + Mix_FreeMusic( music ); +} + +#else + +void* load_sound(void* file) { return NULL; } +void playsound(void * snd) {} +void* load_song(void* file) { return NULL; } +int Mix_PlayingMusic() { return 0; } +void Mix_HaltMusic() {} +int Mix_PlayMusic() { return -1; } +void Mix_FreeMusic() {} +void Mix_FreeChunk() {} +int Mix_OpenAudio(int a, int b, int c, int d) { return -1; } + +int playing_music() { return 0; } +void halt_music() {} +int play_music(int *music, int loops) { return 0;} +void free_music(int *music) {} +void free_chunk(int *chunk) {} + #endif diff --git a/src/sound.h b/src/sound.h index 52c8eadf8..485abd402 100644 --- a/src/sound.h +++ b/src/sound.h @@ -10,11 +10,53 @@ April 22, 2000 - July 15, 2002 */ +#ifndef SUPERTUX_SOUND_H +#define SUPERTUX_SOUND_H + +#define NUM_SOUNDS 16 // all the sounds we have #ifndef NOSOUND +#include + +// variables for stocking the sound and music +Mix_Chunk* sounds[NUM_SOUNDS]; +Mix_Music* song; + +// functions handling the sound and music Mix_Chunk * load_sound(char * file); void playsound(Mix_Chunk * snd); Mix_Music * load_song(char * file); +int playing_music(void); +int halt_music(void); +int play_music(Mix_Music*music, int loops); +void free_music(Mix_Music*music); +void free_chunk(Mix_Chunk*chunk); + +#else + +//fake variables +void* sounds[NUM_SOUNDS]; +void* song; + +// fake sound handlers +void* load_sound(void* file); +void playsound(void * snd); +void* load_song(void* file); +int Mix_PlayingMusic(); +void Mix_HaltMusic(); +int Mix_PlayMusic(); +void Mix_FreeMusic(); +void Mix_FreeChunk(); +int Mix_OpenAudio(int a, int b, int c, int d); + +int playing_music(); +void halt_music(); +int play_music(int *music, int loops); +void free_music(int *music);; +void free_chunk(int *chunk); + #endif + +#endif /*SUPERTUX_SOUND_H*/ diff --git a/src/supertux.c b/src/supertux.c index 105b5bdb7..89216aa3c 100644 --- a/src/supertux.c +++ b/src/supertux.c @@ -19,10 +19,6 @@ #include #include -#ifndef NOSOUND -#include -#endif - #ifdef LINUX #include #include diff --git a/src/title.c b/src/title.c index 5de4bb8d4..ec6f32e5d 100644 --- a/src/title.c +++ b/src/title.c @@ -18,10 +18,6 @@ #include #include -#ifndef NOSOUND -#include -#endif - #ifdef LINUX #include #include -- 2.11.0