--- /dev/null
+//
+// C++ Interface: enemy
+//
+// Description:
+//
+//
+// Author: Tobias Glaesser <tobi.web@gmx.de> (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+
+/* Types: */
+
+
+
+typedef struct bad_guy_type
+ {
+ int alive;
+ int mode;
+ int dying;
+ int timer;
+ int kind;
+ int seen;
+ int dir;
+ int x;
+ int y;
+ int xm;
+ int ym;
+ unsigned int time_updated;
+ }
+bad_guy_type;
#include "setup.h"
#include "high_scores.h"
#include "menu.h"
-
+#include "enemy.h"
+#include "world.h"
+#include "player.h"
/* Sound files: */
{
drawimage(tux_life,565+(18*i),20,NO_UPDATE);
}
- /*drawtext(str, 608, 0, letters_gold, NO_UPDATE);*/
-
+
if(game_pause)
drawcenteredtext("PAUSE",230,letters_red, NO_UPDATE);
now_time = SDL_GetTicks();
if (now_time < last_time + FPS)
- SDL_Delay(last_time + FPS - now_time);
+ SDL_Delay(last_time + FPS - now_time);
/* Handle time: */
/* Sound effects: */
- /* if (use_sound) // this can help speeding up a little, but
- we shouldn't take care about "use_sound" here, it's load_sound's job
- / Send a mail to neoneurone@users.sf.net, if you have another opinion. :)
- */
+ /* if (use_sound) // this will introduce SERIOUS bugs here ! because "load_sound"
+ // initialize sounds[i] with the correct pointer's value:
+ // NULL or something else. And it will be dangerous to
+ // play with not-initialized pointers.
+ // This is also true with if (use_music)
+ Send a mail to me: neoneurone@users.sf.net, if you have another opinion. :)
+ */
for (i = 0; i < NUM_SOUNDS; i++)
sounds[i] = load_sound(soundfilenames[i]);
#define SCORE_DISTRO 25
-/* Types: */
-
-typedef struct bouncy_distro_type {
- int alive, x, y, ym;
-} bouncy_distro_type;
-
-typedef struct broken_brick_type {
- int alive, x, y, xm, ym;
-} broken_brick_type;
-
-typedef struct bouncy_brick_type {
- int alive, x, y, offset, offset_m, shape;
-} bouncy_brick_type;
-
-typedef struct bad_guy_type {
- int alive, mode, dying, timer, kind, seen, dir, x, y, xm, ym;
-} bad_guy_type;
-
-typedef struct floating_score_type {
- int alive, timer, x, y, value;
-} floating_score_type;
-
-typedef struct upgrade_type {
- int alive, kind, height, x, y, xm, ym;
-} upgrade_type;
-
-typedef struct bullet_type {
- int alive, x, y, xm, ym;
-} bullet_type;
-
-
/* Function prototypes: */
int gameloop(void);
menuaction = -1;
}
+/* ---- Menu Options - Item Sound On/off ----*/
+void menu_option_sound()
+{
+ if (audio_device == YES) {
+ if(menuitem == 1) {
+ if(use_sound == YES) {
+ drawcenteredtext("Sound ON", 224, letters_red, NO_UPDATE);
+ }
+ else {
+ drawcenteredtext("Sound OFF", 224, letters_red, NO_UPDATE);
+ }
+
+ if(menuaction == MN_HIT) { /* Disable/Enable sound */
+ if(use_sound == YES) {
+ use_sound = NO;
+ }
+ else {
+ use_sound = YES;
+ }
+ menu_change = YES;
+ }
+ }
+ else {
+ if(use_sound == YES)
+ drawcenteredtext("Sound ON", 224, letters_blue, NO_UPDATE);
+ else
+ drawcenteredtext("Sound OFF", 224, letters_blue, NO_UPDATE);
+ }
+ }
+ else { /* if audio_device != YES */
+ /* let the user move over the deactivated option */
+ if (menuitem == 1) {
+ drawcenteredtext("Sound OFF", 224, letters_red, NO_UPDATE);
+ }
+ else {
+ drawcenteredtext("Sound OFF", 224, letters_black, NO_UPDATE);
+ }
+ }
+}
+
+
+/* ---- Menu Options - Item Music On/off ----*/
+void menu_option_music()
+{
+ if (audio_device == YES) {
+ if(menuitem == 2) {
+ if(use_music == YES) {
+ drawcenteredtext("Music ON", 256, letters_red, NO_UPDATE);
+ }
+ else {
+ drawcenteredtext("Music OFF", 256, letters_red, NO_UPDATE);
+ }
+ if(menuaction == MN_HIT) { /* Disable/Enable music */
+ if(use_music == YES) { /* In the menu no music is played, so we have to check only use_music */
+ if(playing_music())
+ halt_music();
+ use_music = NO;
+ }
+ else {
+ use_music = YES;
+ if (!playing_music()) {
+ switch (current_music) {
+ case LEVEL_MUSIC:
+ play_music(level_song, 1);
+ break;
+ case HERRING_MUSIC:
+ play_music(herring_song, 1);
+ break;
+ case HURRYUP_MUSIC: // keep the compiler happy
+ case NO_MUSIC: // keep the compiler happy for the moment :-)
+ {}
+ /*default:*/
+ }
+ }
+ }
+ menu_change = YES;
+ }
+ } /* if menuitem != 2 : print normal blue font */
+ else {
+ if(use_music == YES) {
+ drawcenteredtext("Music ON", 256, letters_blue, NO_UPDATE);
+ }
+ else {
+ drawcenteredtext("Music OFF", 256, letters_blue, NO_UPDATE);
+ }
+ }
+ }
+ else { /* if audio_device != YES */
+ /* let the user move over the deactivated option */
+ if (menuitem == 2) {
+ drawcenteredtext("Music OFF", 256, letters_red, NO_UPDATE);
+ }
+ else {
+ drawcenteredtext("Music OFF", 256, letters_black, NO_UPDATE);
+ }
+ }
+}
+
/* --- MENU --- */
/* Draw the menu and execute the (menu)events */
int drawmenu(void)
if(menumenu == MENU_MAIN)
{
/* Does the menu item exist? If not, we reset to the most down item */
- if(menuitem > 2)
- menuitem = 2;
+ if(menuitem >= MENU_MAIN_ITEM_MAX)
+ menuitem = MENU_MAIN_ITEM_MAX - 1;
/*The menu looks different, when the game is started */
if(game_started)
}
else if(menumenu == MENU_OPTIONS)
{
- if(menuitem > 2)
- menuitem = 2;
+ if(menuitem >= MENU_OPTIONS_ITEM_MAX )
+ menuitem = MENU_OPTIONS_ITEM_MAX - 1;
if(menuitem == 0)
{
drawcenteredtext("Fullscreen OFF", 192, letters_blue, NO_UPDATE);
}
- if (audio_device == YES)
- {
- if(menuitem == 1)
- {
- if(use_sound)
- drawcenteredtext("Sound ON", 224, letters_red, NO_UPDATE);
- else
- drawcenteredtext("Sound OFF", 224, letters_red, NO_UPDATE);
- if(menuaction == MN_HIT) /* Disable/Enable sound */
- {
- if(use_sound)
- {
- if(playing_music())
- halt_music();
- use_sound = 0;
- }
- else
- {
- use_sound = 1;
- if (playing_music())
- {
- switch (current_music)
- {
- case LEVEL_MUSIC:
- play_music(level_song, 1);
- break;
- case HERRING_MUSIC:
- play_music(herring_song, 1);
- break;
- case HURRYUP_MUSIC: // keep the compiler happy
- case NO_MUSIC: // keep the compiler happy for the moment :-)
- {}
-
- /*default:*/
- }
- }
- }
- menu_change = YES;
- }
- }
- else
- {
- if(use_sound)
- drawcenteredtext("Sound ON", 224, letters_blue, NO_UPDATE);
- else
- drawcenteredtext("Sound OFF", 224, letters_blue, NO_UPDATE);
- }
- }
- else /* if audio_device != YES */
- {
- /* let the user move over the deactivated option */
- if (menuitem == 1)
- drawcenteredtext("Sound OFF", 224, letters_red, NO_UPDATE);
- else
- drawcenteredtext("Sound OFF", 224, letters_black, NO_UPDATE);
- }
+ /* handle menu sound on/off option */
+ menu_option_sound();
- if(menuitem == 2)
+ /* handle menu music on/off option */
+ menu_option_music();
+
+ if(menuitem == 3)
{
- drawcenteredtext("Back", 256, letters_red, NO_UPDATE);
+ drawcenteredtext("Back", 288, letters_red, NO_UPDATE);
if(menuaction == MN_HIT) /* Go back to main menu. */
{
menumenu = MENU_MAIN;
}
}
else
- drawcenteredtext("Back", 256, letters_blue, NO_UPDATE);
+ drawcenteredtext("Back", 288, letters_blue, NO_UPDATE);
}
int show_menu;
int menu_change;
+#define MENU_MAIN_ITEM_MAX 3
+#define MENU_OPTIONS_ITEM_MAX 4
+
/* Action done on the menu */
enum {
MN_UP,
--- /dev/null
+//
+// C++ Interface: tux
+//
+// Description:
+//
+//
+// Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+typedef struct upgrade_type
+ {
+ int alive;
+ int kind;
+ int height;
+ int x;
+ int y;
+ int xm;
+ int ym;
+ }
+upgrade_type;
+
+typedef struct bullet_type
+ {
+ int alive;
+ int x;
+ int y;
+ int xm;
+ int ym;
+ }
+bullet_type;
+
void st_setup(void)
{
- /* Set SuperTux configuration and save directories
+ /* Set SuperTux configuration and save directories */
/* Get home directory (from $HOME variable)... if we can't determine it,
use the current directory ("."): */
st_save_dir = (char *) malloc(sizeof(char) * (strlen(st_dir) + strlen("/save") + 1));
strcpy(st_save_dir,st_dir);
- strcpy(st_save_dir,"/save");
+ strcat(st_save_dir,"/save");
/* Create them. In the case they exist it won't destroy anything. */
mkdir(st_dir, 0755);
{
if (SDL_Init(SDL_INIT_AUDIO) < 0)
{
- /* only print out message if sound was not disabled at command-line */
- if (use_sound == YES)
+ /* only print out message if sound or music
+ was not disabled at command-line
+ */
+ if (use_sound == YES || use_music == YES)
{
fprintf(stderr,
"\nWarning: I could not initialize audio!\n"
"The Simple DirectMedia error that occured was:\n"
"%s\n\n", SDL_GetError());
- use_sound = NO;
}
+ /* keep the programming logic the same :-)
+ because in this case, use_sound & use_music' values are ignored
+ when there's no available audio device
+ */
+ use_sound = NO;
+ use_music = NO;
audio_device = NO;
}
}
{
if (open_audio(44100, AUDIO_S16, 2, 512) < 0)
{
- /* only print out message if sound was not disabled at command-line */
- if (use_sound == YES)
+ /* only print out message if sound or music
+ was not disabled at command-line
+ */
+ if ((use_sound == YES) || (use_music == YES))
{
fprintf(stderr,
"\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 = NO;
}
+ use_sound = NO;
+ use_music = NO;
audio_device = NO;
}
}
if (use_fullscreen == YES)
{
- screen = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN) ; /* | SDL_HWSURFACE); */
+ screen = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */
if (screen == NULL)
{
fprintf(stderr,
#ifndef NOSOUND
use_sound = YES;
+ use_music = YES;
audio_device = YES;
#else
use_sound = NO;
+ use_music = NO;
audio_device = NO;
#endif
}
else if (strcmp(argv[i], "--disable-sound") == 0)
{
- /* Disable the compiled in sound & music feature */
+ /* Disable the compiled in sound feature */
#ifndef NOSOUND
- printf("Sounds and music disabled \n");
+ printf("Sounds disabled \n");
use_sound = NO;
#else
- printf("Sounds and music feature is not compiled in \n");
+ printf("Warning: Sounds feature is not compiled in \n");
+ printf("Warning: Sounds feature is not compiled in \n");
+#endif
+ }
+ else if (strcmp(argv[i], "--disable-music") == 0)
+ {
+ /* Disable the compiled in sound feature */
+#ifndef NOSOUND
+ printf("Music disabled \n");
+ use_music = NO;
+#else
+ printf("Warning: Music feature is not compiled in \n");
#endif
}
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(" --disable-sound - If sound support was compiled in, this will\n disable sound for this session of the game.\n\n");
+
+ printf(" --disable-music - Like above, but this will disable music.\n\n");
printf(" --fullscreen - Run in fullscreen mode.\n\n");
/* Display the usage message: */
- fprintf(fi, "Usage: %s [--fullscreen] | [--disable-sound] | [--usage | --help | --version]\n",
- prog);
+ fprintf(fi, "Usage: %s [--fullscreen] [--disable-sound] [--disable-music] | [--usage | --help | --version]\n",
+ prog);
/* Quit! */
April 22, 2000 - July 15, 2002
*/
-#include <stdio.h>
+/*
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
-#include <SDL.h>
-#include <SDL_image.h>
+*/
#ifdef LINUX
#include <pwd.h>
int playing_music(void)
{
- if (use_sound)
+ if (use_music == YES)
{
return Mix_PlayingMusic();
}
else
{
- /* we are in --disable-sound we can't be playing music */
+ /* we are in --disable-music we can't be playing music */
return 0;
}
}
int halt_music(void)
{
- if ((use_sound == YES) && (audio_device == YES))
+ if ((use_music == YES) && (audio_device == YES))
{
return Mix_HaltMusic();
}
int play_music(Mix_Music *music, int loops)
{
- if ((use_sound == YES) && (audio_device == YES))
+ if ((use_music == YES) && (audio_device == YES))
{
DEBUG_MSG(__PRETTY_FUNCTION__);
return Mix_PlayMusic(music, loops);
http://www.newbreedsoftware.com/supertux/
April 22, 2000 - July 15, 2002
+
+ Current maintainer:
+ Duong-Khang NGUYEN <neoneurone@users.sf.net>
*/
#ifndef SUPERTUX_SOUND_H
/*global variable*/
int use_sound;
+int use_music;
int audio_device; /* != 0: available and initialized */
/* enum of different internal music types */
SDL_Surface * title, * anim1, * anim2;
SDL_Event event;
SDLKey key;
- int done, quit, frame, pict;
+ int done, quit, frame, pict, last_highscore;
char str[80];
game_started = 0;
/* Draw the high score: */
- sprintf(str, "High score: %d", load_hs());
+ last_highscore = load_hs();
+ sprintf(str, "High score: %d", last_highscore);
drawcenteredtext(str, 460, letters_red, UPDATE);
while (!done && !quit)
drawimage(title, 0, 0, UPDATE);
/* Draw the high score: */
- sprintf(str, "High score: %d", load_hs());
+ sprintf(str, "High score: %d", last_highscore);
drawcenteredtext(str, 460, letters_red, UPDATE);
}
--- /dev/null
+//
+// C++ Interface: world
+//
+// Description:
+//
+//
+// Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+typedef struct bouncy_distro_type /*It is easier to read the sources IMHO, if we don't write something like int a,b,c; */
+ {
+ int alive;
+ int x;
+ int y;
+ int ym;
+ }
+bouncy_distro_type;
+
+typedef struct broken_brick_type
+ {
+ int alive;
+ int x;
+ int y;
+ int xm;
+ int ym;
+ }
+broken_brick_type;
+
+typedef struct bouncy_brick_type
+ {
+ int alive;
+ int x;
+ int y;
+ int offset;
+ int offset_m;
+ int shape;
+ }
+bouncy_brick_type;
+
+typedef struct floating_score_type
+ {
+ int alive;
+ int timer;
+ int x;
+ int y;
+ int value;
+ }
+floating_score_type;
+