Play a sound, when tux gets a new live. Improved 'make clean'.
SVN-Revision: 17
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 <neoneurone@users.sf.net>
+
* Added high score feature.
Adam Czachorowski <gislan@o2.pl>
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:
Version 0.0.5
-December 9, 2003
-
+December 17, 2003
+
NOTICE! THIS GAME IS UNDER CONSTRUCTION!
Things you'll notice:
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.
-------------
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!)
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
----------------
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 <tobi.web@gmx.de>)
+ High score (by Adam Czachorowski <gislan@o2.pl>)
\ No newline at end of file
#include <SDL.h>
#include <SDL_image.h>
-#ifndef NOSOUND
-#include <SDL_mixer.h>
-#endif
-
#ifdef LINUX
#include <pwd.h>
#include <sys/types.h>
SND_EXCELLENT,
SND_COFFEE,
SND_SHOOT,
- NUM_SOUNDS
+ SND_LIFEUP
};
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"
};
* 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];
{
tux_size = !tux_size;
}
+ else if (key == SDLK_END)
+ {
+ distros += 50;
+ }
}
#ifdef JOY_YES
else if (event.type == SDL_JOYAXISMOTION)
tux_dir == LEFT)
{
tux_skidding = SKID_TIME;
-#ifndef NOSOUND
+
playsound(sounds[SND_SKID]);
-#endif
+
}
tux_dir = RIGHT;
}
tux_dir == RIGHT)
{
tux_skidding = SKID_TIME;
-#ifndef NOSOUND
playsound(sounds[SND_SKID]);
-#endif
}
tux_dir = LEFT;
}
{
jumping = YES;
-#ifndef NOSOUND
if (tux_size == SMALL)
playsound(sounds[SND_JUMP]);
else
playsound(sounds[SND_BIGJUMP]);
-#endif
}
}
}
if (tux_y >= 480)
{
-#ifndef NOSOUND
if (use_sound)
{
if (Mix_PlayingMusic())
Mix_HaltMusic();
}
-#endif
if (next_level)
{
if (distro_counter <= 0)
change(tux_x, tux_y, scroll_x, 'a');
-#ifndef NOSOUND
playsound(sounds[SND_DISTRO]);
-#endif
score = score + SCORE_DISTRO;
distros++;
}
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++;
}
distros = distros - DISTROS_LIFEUP;
lives++;
+ playsound(sounds[SND_LIFEUP]);
}
/* Play death sound: */
-#ifndef NOSOUND
playsound(sounds[SND_FALL]);
-#endif
}
}
}
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;
}
{
bad_guys[i].dir = !bad_guys[i].dir;
-#ifndef NOSOUND
if (bad_guys[i].mode == KICK)
playsound(sounds[SND_RICOCHET]);
-#endif
}
}
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);
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)
{
bad_guys[i].y,
25 * score_multiplier);
-#ifndef NOSOUND
/* playsound(sounds[SND_SQUISH]); */
-#endif
}
else if (bad_guys[i].kind == -1)
{
{
bad_guys[i].dying = FALLING;
bad_guys[i].ym = -8;
-#ifndef NOSOUND
playsound(sounds[SND_FALL]);
-#endif
}
}
}
{
bad_guys[i].dying = FALLING;
bad_guys[i].ym = -8;
-#ifndef NOSOUND
playsound(sounds[SND_FALL]);
-#endif
}
}
}
/* Keep playing music: */
-#ifndef NOSOUND
if (use_sound)
{
if (!Mix_PlayingMusic())
Mix_PlayMusic(song, 1);
}
}
-#endif
/* Pause til next frame: */
}
while (!done && !quit);
-#ifndef NOSOUND
if (use_sound)
{
if (Mix_PlayingMusic())
Mix_HaltMusic();
}
-#endif
unloadlevelgfx();
unloadlevelsong();
{
char * song_path;
-#ifndef NOSOUND
song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) +
strlen(song_title) + 8));
song = load_song(DATA_PREFIX "/music/ji_turn.it");
free(song_path);
-#endif
}
void unloadlevelsong(void)
{
-#ifndef NOSOUND
if (use_sound)
{
Mix_FreeMusic(song);
}
-#endif
}
void loadshared(void)
{
-#ifndef NOSOUND
int i;
-#endif
/* Tuxes: */
/* Sound effects: */
-#ifndef NOSOUND
if (use_sound)
{
for (i = 0; i < NUM_SOUNDS; i++)
sounds[i] = load_sound(soundfilenames[i]);
+
}
-#endif
}
SDL_FreeSurface(img_golden_herring);
-#ifndef NOSOUND
if (use_sound)
{
for (i = 0; i < NUM_SOUNDS; i++)
Mix_FreeChunk(sounds[i]);
}
-#endif
}
if (distro_counter <= 0)
change(x, y, sx, 'a');
-#ifndef NOSOUND
playsound(sounds[SND_DISTRO]);
-#endif
score = score + SCORE_DISTRO;
distros++;
}
/* Get some score: */
-#ifndef NOSOUND
playsound(sounds[SND_BRICK]);
-#endif
score = score + SCORE_BRICK;
}
}
add_bouncy_brick(((x + sx + 1) / 32) * 32,
(y / 32) * 32);
-#ifndef NOSOUND
playsound(sounds[SND_BRICK]);
-#endif
}
add_bouncy_distro(((x + sx + 1) / 32) * 32,
(y / 32) * 32 - 32);
-#ifndef NOSOUND
playsound(sounds[SND_DISTRO]);
-#endif
score = score + SCORE_DISTRO;
distros++;
}
UPGRADE_COFFEE);
}
-#ifndef NOSOUND
playsound(sounds[SND_UPGRADE]);
-#endif
}
else if (shape(x, y, sx) == '!')
{
if (shape(x, y, sx) == '$')
{
change(x, y, sx, '.');
-#ifndef NOSOUND
playsound(sounds[SND_DISTRO]);
-#endif
if (bounciness == BOUNCE)
{
{
bad_guys[i].dying = FALLING;
bad_guys[i].ym = -8;
-#ifndef NOSOUND
playsound(sounds[SND_FALL]);
-#endif
}
}
}
{
upgrades[i].xm = -upgrades[i].xm;
upgrades[i].ym = -8;
-#ifndef NOSOUND
playsound(sounds[SND_BUMP_UPGRADE]);
-#endif
}
}
}
{
tux_ym = -16;
-#ifndef NOSOUND
playsound(sounds[SND_HURT]);
-#endif
if (tux_dir == RIGHT)
tux_xm = -8;
bullets[found].y = y;
bullets[found].ym = BULLET_STARTING_YM;
-#ifndef NOSOUND
playsound(sounds[SND_SHOOT]);
-#endif
}
}
#include <SDL.h>
#include <SDL_image.h>
-#ifndef NOSOUND
-#include <SDL_mixer.h>
-#endif
-
SDL_Surface * screen;
SDL_Surface * letters_black, * letters_gold, * letters_blue, * letters_red;
#include <SDL.h>
#include <SDL_image.h>
-#ifndef NOSOUND
-#include <SDL_mixer.h>
-#endif
-
#ifdef LINUX
#include <pwd.h>
#include <sys/types.h>
#include <SDL.h>
#include <SDL_image.h>
-#ifndef NOSOUND
-#include <SDL_mixer.h>
-#endif
-
#ifdef LINUX
#include <pwd.h>
#include <sys/types.h>
#include <SDL.h>
#include <SDL_image.h>
-#ifndef NOSOUND
-#include <SDL_mixer.h>
-#endif
-
#ifdef LINUX
#include <pwd.h>
#include <sys/types.h>
#include "globals.h"
#include "setup.h"
#include "screen.h"
+#include "sound.h"
/* Local function prototypes: */
/* 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: */
/* Set defaults: */
use_fullscreen = NO;
+ #ifndef NOSOUND
use_sound = YES;
-
+ #else
+ use_sound = NO;
+ #endif
/* Parse arguments: */
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! */
/* 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);
April 22, 2000 - July 15, 2002
*/
-#ifndef NOSOUND
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <SDL.h>
#include <SDL_image.h>
-#include <SDL_mixer.h>
-
#ifdef LINUX
#include <pwd.h>
#include <sys/types.h>
#include "sound.h"
#include "setup.h"
+#ifndef NOSOUND
/* --- LOAD A SOUND --- */
}
-/* --- PLAY A SOUND --- */
-
-void playsound(Mix_Chunk * snd)
-{
- Mix_PlayChannel(-1, snd, 0);
-}
-
-
/* --- LOAD A SONG --- */
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
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 <SDL_mixer.h>
+
+// 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*/
#include <SDL.h>
#include <SDL_image.h>
-#ifndef NOSOUND
-#include <SDL_mixer.h>
-#endif
-
#ifdef LINUX
#include <pwd.h>
#include <sys/types.h>
#include <SDL.h>
#include <SDL_image.h>
-#ifndef NOSOUND
-#include <SDL_mixer.h>
-#endif
-
#ifdef LINUX
#include <pwd.h>
#include <sys/types.h>