From 7fc94a99a287a0d7104d75eac2aeffcff4bf4703 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Gl=C3=A4=C3=9Fer?= Date: Sat, 20 Dec 2003 12:44:23 +0000 Subject: [PATCH] Fixed FIXME. Tux doesn't die anymore, when he reaches the end of a level. Added resultscreen. SVN-Revision: 22 --- src/gameloop.c | 91 ++++++++++++++++++++++++++++++++++++---------------------- src/gameloop.h | 1 + src/sound.c | 4 +-- src/sound.h | 3 +- 4 files changed, 61 insertions(+), 38 deletions(-) diff --git a/src/gameloop.c b/src/gameloop.c index 808e142aa..4a2e48e07 100644 --- a/src/gameloop.c +++ b/src/gameloop.c @@ -149,6 +149,7 @@ void add_upgrade(int x, int y, int kind); void killtux(int mode); void add_bullet(int x, int y, int dir, int xm); void drawendscreen(void); +void drawresultscreen(void); /* --- GAME LOOP! --- */ @@ -272,6 +273,10 @@ int gameloop(void) { distros += 50; } + else if (key == SDLK_SPACE) + { + next_level = 1; + } } #ifdef JOY_YES else if (event.type == SDL_JOYAXISMOTION) @@ -318,7 +323,7 @@ int gameloop(void) /* Handle key and joystick state: */ - if (!tux_dying && !next_level) + if (!(tux_dying || next_level)) { if (right == DOWN && left == UP) { @@ -432,9 +437,7 @@ int gameloop(void) if (tux_x >= endpos && endpos != 0) { - /* FIXME: No need to kill Tux to end the level! ;^) */ next_level = 1; - tux_dying = 1; } @@ -511,48 +514,49 @@ int gameloop(void) else tux_duck = NO; } - } /* !tux_dying && !next_level */ + } /* (tux_dying || next_level) */ else { /* Tux either died, or reached the end of a level! */ + + if (use_sound) + { + if (Mix_PlayingMusic()) + Mix_HaltMusic(); + } + + + if (next_level) + { + /* End of a level! */ + level++; + next_level = 0; + drawresultscreen(); + } + else + { + tux_ym = tux_ym + GRAVITY; - if (tux_y >= 480) - { - if (use_sound) - { - if (Mix_PlayingMusic()) - Mix_HaltMusic(); - } - - if (next_level) - { - /* End of a level! */ - - level++; - next_level = 0; - } - else - { - /* He died :^( */ - - lives--; - } - /* No more lives!? */ + /* He died :^( */ + + lives--; + + /* No more lives!? */ - if (lives < 0) - { - drawendscreen(); + if (lives < 0) + { + drawendscreen(); if (score > highscore) save_hs(score); return(0); } - + } /* Either way, (re-)load the (next) level... */ @@ -560,7 +564,6 @@ int gameloop(void) unloadlevelgfx(); loadlevelgfx(); - } } /* Move tux: */ @@ -860,11 +863,10 @@ int gameloop(void) if (distros >= DISTROS_LIFEUP) { - /* FIXME: Play a special sound or flash or both! */ - distros = distros - DISTROS_LIFEUP; - lives++; - playsound(sounds[SND_LIFEUP]); + if(lives < MAX_LIVES) + lives++; + playsound(sounds[SND_LIFEUP]); /*We want to hear the sound even, if MAX_LIVES is reached*/ } @@ -2383,6 +2385,7 @@ void loadlevelgfx(void) void loadlevelsong(void) { + char * song_path; song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + @@ -3485,3 +3488,21 @@ void drawendscreen(void) SDL_Delay(2000); } +void drawresultscreen(void) +{ + char str[80]; + + clearscreen(0, 0, 0); + + drawcenteredtext("Result:", 200, letters_red, NO_UPDATE); + + sprintf(str, "SCORE: %d", score); + drawcenteredtext(str, 224, letters_gold, NO_UPDATE); + + sprintf(str, "DISTROS: %d", distros); + drawcenteredtext(str, 256, letters_blue, NO_UPDATE); + + SDL_Flip(screen); + SDL_Delay(2000); +} + diff --git a/src/gameloop.h b/src/gameloop.h index acde44267..02b6c483a 100644 --- a/src/gameloop.h +++ b/src/gameloop.h @@ -84,6 +84,7 @@ enum { #define MAX_RUN_XM 24 #define MAX_YM 24 #define MAX_JUMP_COUNT 3 +#define MAX_LIVES 4 #define WALK_SPEED 2 #define RUN_SPEED 4 diff --git a/src/sound.c b/src/sound.c index 87d1e90ec..ada78bdcf 100644 --- a/src/sound.c +++ b/src/sound.c @@ -94,7 +94,7 @@ int playing_music(void) return Mix_PlayingMusic(); } else { - // we are in --disable-sound or NOSOUND, we can't be playing music ! + /* we are in --disable-sound we can't be playing music */ return 0; } } @@ -117,7 +117,7 @@ int play_music(Mix_Music *music, int loops) return Mix_PlayMusic(music, loops); } else { - // return error since you're trying to play music in --disable-sound mode + /* return error since you're trying to play music in --disable-sound mode */ return -1; } } diff --git a/src/sound.h b/src/sound.h index 485abd402..825fdd709 100644 --- a/src/sound.h +++ b/src/sound.h @@ -13,7 +13,8 @@ #ifndef SUPERTUX_SOUND_H #define SUPERTUX_SOUND_H -#define NUM_SOUNDS 16 // all the sounds we have + /*all the sounds we have*/ +#define NUM_SOUNDS 16 #ifndef NOSOUND -- 2.11.0