//
-// C++ Interface: enemy
+// Interface: enemy
//
// Description:
//
#include "globals.h"
#include "gameloop.h"
#include "screen.h"
-#include "sound.h"
#include "setup.h"
#include "high_scores.h"
#include "menu.h"
#include "world.h"
#include "player.h"
+/* extern variables */
+
+extern char* soundfilenames[NUM_SOUNDS];
/* Local variables: */
{
tux_skidding = SKID_TIME;
- play_sound(sounds[SND_SKID]);
+ play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
}
tux_dir = RIGHT;
tux_dir == RIGHT)
{
tux_skidding = SKID_TIME;
- play_sound(sounds[SND_SKID]);
+ play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
}
tux_dir = LEFT;
}
jumping = YES;
if (tux_size == SMALL)
- play_sound(sounds[SND_JUMP]);
+ play_sound(sounds[SND_JUMP], SOUND_CENTER_SPEAKER);
else
- play_sound(sounds[SND_BIGJUMP]);
+ play_sound(sounds[SND_BIGJUMP], SOUND_CENTER_SPEAKER);
}
}
}
if (distro_counter <= 0)
change(tux_x, tux_y, scroll_x, 'a');
- play_sound(sounds[SND_DISTRO]);
+ play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
score = score + SCORE_DISTRO;
distros++;
}
if (distro_counter <= 0)
change(tux_x + 31, tux_y, scroll_x, 'a');
- play_sound(sounds[SND_DISTRO]);
+ play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
score = score + SCORE_DISTRO;
distros++;
}
distros = distros - DISTROS_LIFEUP;
if(lives < MAX_LIVES)
lives++;
- play_sound(sounds[SND_LIFEUP]); /*We want to hear the sound even, if MAX_LIVES is reached*/
+ /*We want to hear the sound even, if MAX_LIVES is reached*/
+ play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER);
}
/* Play death sound: */
- play_sound(sounds[SND_FALL]);
+ play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
}
}
}
if (upgrades[i].kind == UPGRADE_MINTS)
{
- play_sound(sounds[SND_EXCELLENT]);
+ play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
tux_size = BIG;
super_bkgd_time = 8;
}
else if (upgrades[i].kind == UPGRADE_COFFEE)
{
- play_sound(sounds[SND_COFFEE]);
+ play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
tux_got_coffee = YES;
super_bkgd_time = 4;
}
else if (upgrades[i].kind == UPGRADE_HERRING)
{
- play_sound(sounds[SND_HERRING]);
+ play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
tux_invincible_time = TUX_INVINCIBLE_TIME;
super_bkgd_time = 4;
/* play the herring song ^^ */
bad_guys[i].dir = !bad_guys[i].dir;
if (bad_guys[i].mode == KICK)
- play_sound(sounds[SND_RICOCHET]);
+ {
+ /* handle stereo sound */
+ if (tux_x + scroll_x > bad_guys[i].x)
+ play_sound(sounds[SND_RICOCHET], SOUND_LEFT_SPEAKER);
+ else if (tux_x + scroll_x < bad_guys[i].x)
+ play_sound(sounds[SND_RICOCHET], SOUND_RIGHT_SPEAKER);
+ else
+ play_sound(sounds[SND_RICOCHET], SOUND_CENTER_SPEAKER);
+ }
}
}
bad_guys[j].dying = FALLING;
bad_guys[j].ym = -8;
- play_sound(sounds[SND_FALL]);
+ play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
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);
- play_sound(sounds[SND_SQUISH]);
+ play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
}
else if (bad_guys[i].kind == BAD_LAPTOP)
{
{
/* Flatten! */
- play_sound(sounds[SND_STOMP]);
+ play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
bad_guys[i].mode = FLAT;
bad_guys[i].timer = 64;
/* Kick! */
bad_guys[i].mode = KICK;
- play_sound(sounds[SND_KICK]);
+ play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
if (tux_x + scroll_x <= bad_guys[i].x)
bad_guys[i].dir = RIGHT;
/* Kick: */
bad_guys[i].mode = KICK;
- play_sound(sounds[SND_KICK]);
+ play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
if (tux_x + scroll_x <= bad_guys[i].x)
{
/* Step on (stop being kicked) */
bad_guys[i].mode = FLAT;
- play_sound(sounds[SND_STOMP]);
+ play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
bad_guys[i].timer = 64;
}
else
{
bad_guys[i].dying = FALLING;
bad_guys[i].ym = -8;
- play_sound(sounds[SND_FALL]);
+ play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
}
}
}
{
bad_guys[i].dying = FALLING;
bad_guys[i].ym = -8;
- play_sound(sounds[SND_FALL]);
+ play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
}
}
}
/* Init the game: */
initmenu();
+ menumenu = MENU_GAME;
initgame();
loadshared();
loadlevel();
if (distro_counter <= 0)
change(x, y, sx, 'a');
- play_sound(sounds[SND_DISTRO]);
+ play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
score = score + SCORE_DISTRO;
distros++;
}
/* Get some score: */
- play_sound(sounds[SND_BRICK]);
+ play_sound(sounds[SND_BRICK], SOUND_CENTER_SPEAKER);
score = score + SCORE_BRICK;
}
}
add_bouncy_brick(((x + sx + 1) / 32) * 32,
(y / 32) * 32);
- play_sound(sounds[SND_BRICK]);
+ play_sound(sounds[SND_BRICK], SOUND_CENTER_SPEAKER);
}
add_bouncy_distro(((x + sx + 1) / 32) * 32,
(y / 32) * 32 - 32);
- play_sound(sounds[SND_DISTRO]);
+ play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
score = score + SCORE_DISTRO;
distros++;
}
UPGRADE_COFFEE);
}
- play_sound(sounds[SND_UPGRADE]);
+ play_sound(sounds[SND_UPGRADE], SOUND_CENTER_SPEAKER);
}
else if (shape(x, y, sx) == '!')
{
if (shape(x, y, sx) == '$')
{
change(x, y, sx, '.');
- play_sound(sounds[SND_DISTRO]);
+ play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
if (bounciness == BOUNCE)
{
{
bad_guys[i].dying = FALLING;
bad_guys[i].ym = -8;
- play_sound(sounds[SND_FALL]);
+ play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
}
}
}
{
upgrades[i].xm = -upgrades[i].xm;
upgrades[i].ym = -8;
- play_sound(sounds[SND_BUMP_UPGRADE]);
+ play_sound(sounds[SND_BUMP_UPGRADE], SOUND_CENTER_SPEAKER);
}
}
}
{
tux_ym = -16;
- play_sound(sounds[SND_HURT]);
+ play_sound(sounds[SND_HURT], SOUND_CENTER_SPEAKER);
if (tux_dir == RIGHT)
tux_xm = -8;
bullets[found].y = y;
bullets[found].ym = BULLET_STARTING_YM;
- play_sound(sounds[SND_SHOOT]);
+ play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);
}
}
April 11, 2000 - December 28, 2003
*/
+#if !defined( SUPERTUX_GAMELOOP_H )
+#define SUPERTUX_GAMELOOP_H 1
-/* Direction (keyboard/joystick) states: */
+ #include "sound.h"
-#define UP 0
-#define DOWN 1
+ /* Direction (keyboard/joystick) states: */
+ #define UP 0
+ #define DOWN 1
-/* Directions: */
-#define LEFT 0
-#define RIGHT 1
+ /* Directions: */
+ #define LEFT 0
+ #define RIGHT 1
-/* Sizes: */
-#define SMALL 0
-#define BIG 1
+ /* Sizes: */
+ #define SMALL 0
+ #define BIG 1
-/* Bounciness of distros: */
-#define NO_BOUNCE 0
-#define BOUNCE 1
+ /* Bounciness of distros: */
+ #define NO_BOUNCE 0
+ #define BOUNCE 1
-/* One-ups... */
-#define DISTROS_LIFEUP 100
+ /* One-ups... */
+ #define DISTROS_LIFEUP 100
-/* When to alert player they're low on time! */
-#define TIME_WARNING 50
+ /* When to alert player they're low on time! */
+ #define TIME_WARNING 50
-/* Dying types: */
-/* ---- NO 0 */
-#define SQUISHED 1
-#define FALLING 2
+ /* Dying types: */
+ /* ---- NO 0 */
+ #define SQUISHED 1
+ #define FALLING 2
-/* Enemy modes: */
-#define NORMAL 0
-#define FLAT 1
-#define KICK 2
+ /* Enemy modes: */
+ #define NORMAL 0
+ #define FLAT 1
+ #define KICK 2
-/* Hurt modes: */
-#define KILL 0
-#define SHRINK 1
+ /* Hurt modes: */
+ #define KILL 0
+ #define SHRINK 1
-/* Upgrade types: */
-enum {
- UPGRADE_MINTS,
- UPGRADE_COFFEE,
- UPGRADE_HERRING
-};
+ /* Upgrade types: */
+ enum {
+ UPGRADE_MINTS,
+ UPGRADE_COFFEE,
+ UPGRADE_HERRING
+ };
-/* Bad guy kinds: */
-enum {
- BAD_BSOD,
- BAD_LAPTOP,
- BAD_MONEY
-};
+ /* Bad guy kinds: */
+ enum {
+ BAD_BSOD,
+ BAD_LAPTOP,
+ BAD_MONEY
+ };
-/* Speed constraints: */
-#define MAX_WALK_XM 16
-#define MAX_RUN_XM 24
-#define MAX_YM 24
-#define MAX_JUMP_COUNT 3
-#define MAX_LIVES 4
+ /* Speed constraints: */
-#define WALK_SPEED 2
-#define RUN_SPEED 4
-#define JUMP_SPEED 8
-#define BULLET_STARTING_YM 8
-#define BULLET_XM 16
+ #define MAX_WALK_XM 16
+ #define MAX_RUN_XM 24
+ #define MAX_YM 24
+ #define MAX_JUMP_COUNT 3
+ #define MAX_LIVES 4
-#define GRAVITY 2
-#define YM_FOR_JUMP 40
-#define KILL_BOUNCE_YM 8
+ #define WALK_SPEED 2
+ #define RUN_SPEED 4
+ #define JUMP_SPEED 8
+ #define BULLET_STARTING_YM 8
+ #define BULLET_XM 16
-#define SKID_XM 8
-#define SKID_TIME 8
+ #define GRAVITY 2
+ #define YM_FOR_JUMP 40
+ #define KILL_BOUNCE_YM 8
+ #define SKID_XM 8
+ #define SKID_TIME 8
-#define BOUNCY_BRICK_MAX_OFFSET 8
-#define BOUNCY_BRICK_SPEED 4
+ #define BOUNCY_BRICK_MAX_OFFSET 8
+ #define BOUNCY_BRICK_SPEED 4
-/* Times: */
-#define TUX_SAFE_TIME 16
-#define TUX_INVINCIBLE_TIME 200
+ /* Times: */
-/* Size constraints: */
+ #define TUX_SAFE_TIME 16
+ #define TUX_INVINCIBLE_TIME 200
-#define OFFSCREEN_DISTANCE 256
+ /* Size constraints: */
-#define LEVEL_WIDTH 375
+ #define OFFSCREEN_DISTANCE 256
+ #define LEVEL_WIDTH 375
-/* Array sizes: */
-#define NUM_BOUNCY_DISTROS 8
-#define NUM_BROKEN_BRICKS 32
-#define NUM_BOUNCY_BRICKS 4
-#define NUM_BAD_GUYS 128
-#define NUM_FLOATING_SCORES 6
-#define NUM_UPGRADES 2
-#define NUM_BULLETS 3
+ /* Array sizes: */
+ #define NUM_BOUNCY_DISTROS 8
+ #define NUM_BROKEN_BRICKS 32
+ #define NUM_BOUNCY_BRICKS 4
+ #define NUM_BAD_GUYS 128
+ #define NUM_FLOATING_SCORES 6
+ #define NUM_UPGRADES 2
+ #define NUM_BULLETS 3
-/* Scores: */
-#define SCORE_BRICK 5
-#define SCORE_DISTRO 25
+ /* Scores: */
+ #define SCORE_BRICK 5
+ #define SCORE_DISTRO 25
-/* Function prototypes: */
+ /* Function prototypes: */
+
+ int gameloop(void);
+
+#endif
-int gameloop(void);
int use_joystick, use_fullscreen, debug_mode;
-int game_started;
+int game_started, level_editor_started;
/* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */
char *st_dir, *st_save_dir;
#include "screen.h"
#include "setup.h"
#include "sound.h"
-
+#include "leveleditor.h"
/* Set defaults */
void initmenu(void)
if (audio_device == YES) {
if(menuitem == 1) {
if(use_sound == YES) {
- drawcenteredtext("Sound ON", 224, letters_red, NO_UPDATE);
+ drawshadedcenteredtext("Sound ON", 224, letters_red, NO_UPDATE);
}
else {
- drawcenteredtext("Sound OFF", 224, letters_red, NO_UPDATE);
+ drawshadedcenteredtext("Sound OFF", 224, letters_red, NO_UPDATE);
}
if(menuaction == MN_HIT) { /* Disable/Enable sound */
}
else {
if(use_sound == YES)
- drawcenteredtext("Sound ON", 224, letters_blue, NO_UPDATE);
+ drawshadedcenteredtext("Sound ON", 224, letters_blue, NO_UPDATE);
else
- drawcenteredtext("Sound OFF", 224, letters_blue, NO_UPDATE);
+ drawshadedcenteredtext("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);
+ drawshadedcenteredtext("Sound OFF", 224, letters_red, NO_UPDATE);
}
else {
- drawcenteredtext("Sound OFF", 224, letters_black, NO_UPDATE);
+ drawshadedcenteredtext("Sound OFF", 224, letters_black, NO_UPDATE);
}
}
}
if (audio_device == YES) {
if(menuitem == 2) {
if(use_music == YES) {
- drawcenteredtext("Music ON", 256, letters_red, NO_UPDATE);
+ drawshadedcenteredtext("Music ON", 256, letters_red, NO_UPDATE);
}
else {
- drawcenteredtext("Music OFF", 256, letters_red, NO_UPDATE);
+ drawshadedcenteredtext("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 menuitem != 2 : print normal blue font */
else {
if(use_music == YES) {
- drawcenteredtext("Music ON", 256, letters_blue, NO_UPDATE);
+ drawshadedcenteredtext("Music ON", 256, letters_blue, NO_UPDATE);
}
else {
- drawcenteredtext("Music OFF", 256, letters_blue, NO_UPDATE);
+ drawshadedcenteredtext("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);
+ drawshadedcenteredtext("Music OFF", 256, letters_red, NO_UPDATE);
}
else {
- drawcenteredtext("Music OFF", 256, letters_black, NO_UPDATE);
+ drawshadedcenteredtext("Music OFF", 256, letters_black, NO_UPDATE);
}
}
}
-/* --- MENU --- */
-/* Draw the menu and execute the (menu)events */
-int drawmenu(void)
+int menu_main(void)
{
- int quit = 0;
-
- menu_change = NO;
-
-
- if(menuaction == MN_UP)
- {
- /* Go one menu-item up, if possible */
- if(menuitem > 0)
- --menuitem;
- }
- else if(menuaction == MN_DOWN)
- ++menuitem; /* Go one menu-item down */
-
-
- if(menumenu == MENU_MAIN)
- {
- /* Does the menu item exist? If not, we reset to the most down item */
- if(menuitem >= MENU_MAIN_ITEM_MAX)
- menuitem = MENU_MAIN_ITEM_MAX - 1;
-
+ /* Does the menu item exist? If not, we reset to the most down item */
+ if(menuitem > MENU_MAIN_ITEM_MAX)
+ menuitem =0;
+ else if(menuitem < 0)
+ menuitem = MENU_MAIN_ITEM_MAX;
+
/*The menu looks different, when the game is started */
- if(game_started)
- {
- if(menuitem == 0)
- {
- drawcenteredtext("Return To Game", 192, letters_red, NO_UPDATE);
- if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
- show_menu = 0;
- }
- else
- drawcenteredtext("Return To Game", 192, letters_blue, NO_UPDATE);
- }
- else
- {
if(menuitem == 0)
{
- drawcenteredtext("Start Game", 192, letters_red, NO_UPDATE);
+ drawshadedcenteredtext("Start Game", 192, letters_red, NO_UPDATE);
if(menuaction == MN_HIT) /* we are ready to start the game, if this item got hit */
{
game_started = 1;
}
}
else
- drawcenteredtext("Start Game", 192, letters_blue, NO_UPDATE);
- }
+ drawshadedcenteredtext("Start Game", 192, letters_blue, NO_UPDATE);
if(menuitem == 1)
{
- drawcenteredtext("Options", 224, letters_red, NO_UPDATE);
+ drawshadedcenteredtext("Options", 224, letters_red, NO_UPDATE);
if(menuaction == MN_HIT) /* Switch to the 'Options' menu */
{
menumenu = MENU_OPTIONS;
}
}
else
- drawcenteredtext("Options", 224, letters_blue, NO_UPDATE);
+ drawshadedcenteredtext("Options", 224, letters_blue, NO_UPDATE);
if(menuitem == 2)
{
- if(game_started)
- drawcenteredtext("Quit Game", 256, letters_red, NO_UPDATE);
- else
- drawcenteredtext("Quit", 256, letters_red, NO_UPDATE);
+ drawshadedcenteredtext("Level editor", 256, letters_red, NO_UPDATE);
+ if(menuaction == MN_HIT) /* Set variables, so that the level editor is executed */
+ {
+ level_editor_started = YES;
+ show_menu = 0;
+ }
+ }
+ else
+ drawshadedcenteredtext("Level editor", 256, letters_blue, NO_UPDATE);
+
+ if(menuitem == 3)
+ {
+ drawshadedcenteredtext("Quit", 288, letters_red, NO_UPDATE);
if(menuaction == MN_HIT) /* Quit a running game or the application */
{
- quit = 1;
+ return 1;
}
}
else
{
- if(game_started)
- drawcenteredtext("Quit Game", 256, letters_blue, NO_UPDATE);
+ drawshadedcenteredtext("Quit", 288, letters_blue, NO_UPDATE);
+ }
+
+return 0;
+}
+
+int menu_game(void)
+{
+ /* Does the menu item exist? If not, we reset to the most down item */
+ if(menuitem > MENU_GAME_ITEM_MAX)
+ menuitem = 0;
+ else if(menuitem < 0)
+ menuitem = MENU_GAME_ITEM_MAX;
+
+ /*The menu looks different, when the game is started */
+ if(menuitem == 0)
+ {
+ drawshadedcenteredtext("Return To Game", 192, letters_red, NO_UPDATE);
+ if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
+ show_menu = 0;
+ }
else
- drawcenteredtext("Quit", 256, letters_blue, NO_UPDATE);
+ drawshadedcenteredtext("Return To Game", 192, letters_blue, NO_UPDATE);
+
+ if(menuitem == 1)
+ {
+ drawshadedcenteredtext("Options", 224, letters_red, NO_UPDATE);
+ if(menuaction == MN_HIT) /* Switch to the 'Options' menu */
+ {
+ menumenu = MENU_OPTIONS;
+ menu_change = YES;
+ }
}
+ else
+ drawshadedcenteredtext("Options", 224, letters_blue, NO_UPDATE);
- }
- else if(menumenu == MENU_OPTIONS)
- {
- if(menuitem >= MENU_OPTIONS_ITEM_MAX )
- menuitem = MENU_OPTIONS_ITEM_MAX - 1;
+ if(menuitem == 2)
+ {
+ drawshadedcenteredtext("Quit Game", 256, letters_red, NO_UPDATE);
+ if(menuaction == MN_HIT) /* Quit a running game */
+ return 1;
+ }
+ else
+ {
+ drawshadedcenteredtext("Quit Game", 256, letters_blue, NO_UPDATE);
+ }
+return 0;
+}
+
+int menu_options(void)
+{
+ if(menuitem > MENU_OPTIONS_ITEM_MAX )
+ menuitem = 0;
+ else if(menuitem < 0)
+ menuitem = MENU_OPTIONS_ITEM_MAX;
+
if(menuitem == 0)
{
if(use_fullscreen)
- drawcenteredtext("Fullscreen ON", 192, letters_red, NO_UPDATE);
+ drawshadedcenteredtext("Fullscreen ON", 192, letters_red, NO_UPDATE);
else
- drawcenteredtext("Fullscreen OFF", 192, letters_red, NO_UPDATE);
+ drawshadedcenteredtext("Fullscreen OFF", 192, letters_red, NO_UPDATE);
if(menuaction == MN_HIT) /* Disable/Enable fullscreen */
{
if(use_fullscreen)
else
{
if(use_fullscreen)
- drawcenteredtext("Fullscreen ON", 192, letters_blue, NO_UPDATE);
+ drawshadedcenteredtext("Fullscreen ON", 192, letters_blue, NO_UPDATE);
else
- drawcenteredtext("Fullscreen OFF", 192, letters_blue, NO_UPDATE);
- }
+ drawshadedcenteredtext("Fullscreen OFF", 192, letters_blue, NO_UPDATE);
+ }
/* handle menu sound on/off option */
menu_option_sound();
if(menuitem == 3)
{
- drawcenteredtext("Back", 288, letters_red, NO_UPDATE);
+ drawshadedcenteredtext("Back", 288, letters_red, NO_UPDATE);
if(menuaction == MN_HIT) /* Go back to main menu. */
{
+ if(game_started)
+ menumenu = MENU_GAME;
+ else
menumenu = MENU_MAIN;
menu_change = YES;
}
}
else
- drawcenteredtext("Back", 288, letters_blue, NO_UPDATE);
+ drawshadedcenteredtext("Back", 288, letters_blue, NO_UPDATE);
+
+return 0;
+}
+
+/* Menu LevelEditor */
+int menu_leveleditor(void)
+{
+ if(menuitem > MENU_LEVELEDITOR_ITEM_MAX )
+ menuitem = 0;
+ else if(menuitem < 0)
+ menuitem = MENU_LEVELEDITOR_ITEM_MAX;
+
+ if(menuitem == 0)
+ {
+ drawshadedcenteredtext("Return To Level Editor", 192, letters_red, NO_UPDATE);
+ if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
+ show_menu = 0;
+ }
+ else
+ drawshadedcenteredtext("Return To Level Editor", 192, letters_blue, NO_UPDATE);
+
+ if(menuitem == 1)
+ {
+ drawshadedcenteredtext("New Level", 224, letters_red, NO_UPDATE);
+ if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
+ {
+ show_menu = 0;
+ newlevel();
+ }
+ }
+ else
+ drawshadedcenteredtext("New Level", 224, letters_blue, NO_UPDATE);
+ if(menuitem == 2)
+ {
+ drawshadedcenteredtext("Load Level", 256, letters_red, NO_UPDATE);
+ if(menuaction == MN_HIT) /* Quit a running game or the application */
+ {
+ show_menu = 0;
+ selectlevel();
+ }
+ }
+ else
+ drawshadedcenteredtext("Load Level", 256, letters_blue, NO_UPDATE);
+ if(menuitem == 3)
+ {
+ drawshadedcenteredtext("Save Level", 288, letters_red, NO_UPDATE);
+ if(menuaction == MN_HIT) /* Quit a running game or the application */
+ {
+ show_menu = 0;
+ savelevel();
+ }
+ }
+ else
+ drawshadedcenteredtext("Save Level", 288, letters_blue, NO_UPDATE);
+
+ if(menuitem == 4)
+ {
+ drawshadedcenteredtext("Quit Level Editor", 320, letters_red, NO_UPDATE);
+ if(menuaction == MN_HIT) /* Quit a running game or the application */
+ {
+ return 1;
+ }
+ }
+ else
+ drawshadedcenteredtext("Quit Level Editor", 320, letters_blue, NO_UPDATE);
+return 0;
+}
+
+/* --- MENU --- */
+/* Draw the menu and execute the (menu)events */
+int drawmenu(void)
+{
+ int quit = 0;
+
+ menu_change = NO;
+
+
+ if(menuaction == MN_UP)
+ {
+ /* Go one menu-item up */
+ --menuitem;
}
+ else if(menuaction == MN_DOWN)
+ ++menuitem; /* Go one menu-item down */
- menuaction = -1;
- SDL_Flip(screen);
+ if(menumenu == MENU_MAIN)
+ {
+ quit = menu_main();
+ }
+ else if(menumenu == MENU_GAME)
+ {
+ quit = menu_game();
+ }
+ else if(menumenu == MENU_OPTIONS)
+ {
+ quit = menu_options();
+ }
+ else if(menumenu == MENU_LEVELEDITOR)
+ {
+ quit = menu_leveleditor();
+ }
+
+ menuaction = -1;
return quit;
}
int menu_change;
#define MENU_MAIN_ITEM_MAX 3
-#define MENU_OPTIONS_ITEM_MAX 4
+#define MENU_GAME_ITEM_MAX 2
+#define MENU_OPTIONS_ITEM_MAX 3
+#define MENU_LEVELEDITOR_ITEM_MAX 4
/* Action done on the menu */
enum {
/* Menus */
enum {
MENU_MAIN,
- MENU_OPTIONS
+ MENU_GAME,
+ MENU_OPTIONS,
+ MENU_LEVELEDITOR
};
/* Initialize the menu variables */
//
-// C++ Interface: tux
+// Interface: tux
//
// Description:
//
SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
}
+/* --- DRAW SHADED TEXT ONTO THE SCREEN --- */
+
+void drawshadedtext(char * text, int x, int y, SDL_Surface * surf, int update)
+{
+ if(surf != letters_black)
+ {
+ drawtext(text, x+1, y+1, letters_black, update);
+ drawtext(text, x, y, surf, update);
+ }
+ else
+ drawtext(text, x, y, surf, update);
+
+}
/* --- DRAW TEXT ONTO THE SCREEN --- */
char c;
SDL_Rect src, dest;
-
/* For each letter in the string... */
for (i = 0; i < strlen(text); i++)
SDL_UpdateRect(screen, x, y, dest.w, 17);
}
+
}
drawtext(text, 320 - (strlen(text) * 8), y, surf, update);
}
+/* --- DRAW SHADED HORIZONTALLY-CENTERED TEXT: --- */
+
+void drawshadedcenteredtext(char * text, int y, SDL_Surface * surf, int update)
+{
+ drawshadedtext(text, 320 - (strlen(text) * 8), y, surf, update);
+}
/* --- ERASE TEXT: --- */
void drawimage(SDL_Surface * surf, int x, int y, int update);
void drawpart(SDL_Surface * surf, int x, int y, int w, int h, int update);
void drawtext(char * text, int x, int y, SDL_Surface * surf, int update);
+void drawshadedtext(char * text, int x, int y, SDL_Surface * surf, int update);
void drawcenteredtext(char * text, int y, SDL_Surface * surf, int update);
+void drawshadedcenteredtext(char * text, int y, SDL_Surface * surf, int update);
void erasetext(char * text, int x, int y, SDL_Surface * surf, int update);
void erasecenteredtext(char * text, int y, SDL_Surface * surf, int update);
#include "globals.h"
#include "setup.h"
#include "screen.h"
-#include "sound.h"
+
/* Local function prototypes: */
void st_shutdown(void)
{
+ close_audio();
SDL_Quit();
}
printf("Sounds disabled \n");
use_sound = NO;
#else
-
- printf("Warning: Sounds feature is not compiled in \n");
printf("Warning: Sounds feature is not compiled in \n");
#endif
}
#else
printf("Warning: Music feature is not compiled in \n");
#endif
-
}
else if (strcmp(argv[i], "--debug-mode") == 0)
{
April 11, 2000 - April 13, 2000
*/
-void st_directory_setup(void);
-void st_general_setup(void);
-void st_video_setup(void);
-void st_audio_setup(void);
-void st_joystick_setup(void);
-void st_shutdown(void);
-void st_abort(char * reason, char * details);
-void parseargs(int argc, char * argv[]);
+#if !defined( SUPERTUX_SETUP_H )
+#define SUPERTUX_SETUP_H 1
+
+ #include "sound.h"
+
+ void st_directory_setup(void);
+ void st_general_setup(void);
+ void st_video_setup(void);
+ void st_audio_setup(void);
+ void st_joystick_setup(void);
+ void st_shutdown(void);
+ void st_abort(char * reason, char * details);
+ void parseargs(int argc, char * argv[]);
+#endif
+
April 22, 2000 - December 28, 2003
*/
-/*
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-*/
-
+/* why do we need this ?
#ifdef LINUX
#include <pwd.h>
#include <sys/types.h>
#include <ctype.h>
#endif
+*/
#include "defines.h"
#include "globals.h"
#include "sound.h"
#include "setup.h"
+char * soundfilenames[NUM_SOUNDS] = {
+ DATA_PREFIX "/sounds/jump.wav",
+ DATA_PREFIX "/sounds/bigjump.wav",
+ DATA_PREFIX "/sounds/skid.wav",
+ DATA_PREFIX "/sounds/distro.wav",
+ DATA_PREFIX "/sounds/herring.wav",
+ DATA_PREFIX "/sounds/brick.wav",
+ DATA_PREFIX "/sounds/hurt.wav",
+ DATA_PREFIX "/sounds/squish.wav",
+ DATA_PREFIX "/sounds/fall.wav",
+ DATA_PREFIX "/sounds/ricochet.wav",
+ DATA_PREFIX "/sounds/bump-upgrade.wav",
+ DATA_PREFIX "/sounds/upgrade.wav",
+ DATA_PREFIX "/sounds/excellent.wav",
+ DATA_PREFIX "/sounds/coffee.wav",
+ DATA_PREFIX "/sounds/shoot.wav",
+ DATA_PREFIX "/sounds/lifeup.wav",
+ DATA_PREFIX "/sounds/stomp.wav",
+ DATA_PREFIX "/sounds/kick.wav"
+ };
+
+
#ifndef NOSOUND
#include <SDL_mixer.h>
int open_audio (int frequency, Uint16 format, int channels, int chunksize)
{
- return Mix_OpenAudio( frequency, format, channels, chunksize );
+ /* if success we reserved some channels and register panning effects */
+ if (Mix_OpenAudio( frequency, format, channels, chunksize ) == 0)
+ {
+ if (Mix_ReserveChannels( SOUND_RESERVED_CHANNELS )
+ != SOUND_RESERVED_CHANNELS )
+ {
+ DEBUG_MSG( "Warning: open_audio could'nt reserve channels" );
+ }
+
+ /* prepare the spanning effects, no error checking */
+ Mix_SetPanning( SOUND_LEFT_SPEAKER, 230, 24 );
+ Mix_SetPanning( SOUND_RIGHT_SPEAKER, 24, 230 );
+ return 0;
+ }
+ else
+ {
+ return -1;
+ }
+}
+
+
+/* --- CLOSE THE AUDIO DEVICE --- */
+
+void close_audio( void )
+{
+ if (audio_device == YES) {
+ Mix_UnregisterAllEffects( SOUND_LEFT_SPEAKER );
+ Mix_UnregisterAllEffects( SOUND_RIGHT_SPEAKER );
+ Mix_CloseAudio();
+ }
}
}
-/* --- PLAY A SOUND --- */
+/* --- PLAY A SOUND ON LEFT OR RIGHT OR CENTER SPEAKER --- */
-void play_sound(Mix_Chunk * snd)
+void play_sound(Mix_Chunk * snd, enum Sound_Speaker whichSpeaker)
{
/* this won't call the function if the user has disabled sound
* either via menu or via command-line option
*/
if ((use_sound == YES) && (audio_device == YES))
{
- Mix_PlayChannel(-1, snd, 0);
+ Mix_PlayChannel( whichSpeaker, snd, 0);
+
+ /* prepare for panning effects for next call */
+ /* warning: currently, I do not check for errors here */
+ switch (whichSpeaker) {
+ case SOUND_LEFT_SPEAKER:
+ Mix_SetPanning( SOUND_LEFT_SPEAKER, 230, 24 );
+ break;
+ case SOUND_RIGHT_SPEAKER:
+ Mix_SetPanning( SOUND_RIGHT_SPEAKER, 24, 230 );
+ break;
+ default: // keep the compiler happy
+ break;
+ }
}
}
}
}
+
int playing_music(void)
{
if (use_music == YES)
return -1;
}
+
+void close_audio(void)
+{}
+
+
void* load_sound(void* file)
{
return NULL;
}
-void play_sound(void * snd)
+
+
+void play_sound(void * snd, enum Sound_Speaker whichSpeaker)
{}
+
+
void* load_song(void* file)
{
return NULL;
}
+
int playing_music()
{
return 0;
}
+
+
void halt_music()
{}
+
+
int play_music(void *music, int loops)
{
return 0;
}
+
+
void free_music(void *music)
{}
+
+
void free_chunk(void *chunk)
{}
#include "defines.h" /* get YES/NO defines */
+/* used to reserve some channels for panning effects */
+#define SOUND_RESERVED_CHANNELS 2
+
/*global variable*/
-int use_sound;
-int use_music;
+int use_sound; /* handle sound on/off menu and command-line option */
+int use_music; /* handle music on/off menu and command-line option */
int audio_device; /* != 0: available and initialized */
/* enum of different internal music types */
HERRING_MUSIC
} current_music;
-/* Sound files: */
+/* panning effects: terrible :-) ! */
+enum Sound_Speaker {
+ SOUND_LEFT_SPEAKER = 0,
+ SOUND_RIGHT_SPEAKER = 1,
+ SOUND_CENTER_SPEAKER = -1
+};
+/* Sound files: */
enum {
SND_JUMP,
SND_BIGJUMP,
NUM_SOUNDS
};
-
-static char * soundfilenames[NUM_SOUNDS] = {
- DATA_PREFIX "/sounds/jump.wav",
- DATA_PREFIX "/sounds/bigjump.wav",
- DATA_PREFIX "/sounds/skid.wav",
- DATA_PREFIX "/sounds/distro.wav",
- DATA_PREFIX "/sounds/herring.wav",
- DATA_PREFIX "/sounds/brick.wav",
- DATA_PREFIX "/sounds/hurt.wav",
- DATA_PREFIX "/sounds/squish.wav",
- DATA_PREFIX "/sounds/fall.wav",
- DATA_PREFIX "/sounds/ricochet.wav",
- DATA_PREFIX "/sounds/bump-upgrade.wav",
- DATA_PREFIX "/sounds/upgrade.wav",
- DATA_PREFIX "/sounds/excellent.wav",
- DATA_PREFIX "/sounds/coffee.wav",
- DATA_PREFIX "/sounds/shoot.wav",
- DATA_PREFIX "/sounds/lifeup.wav",
- DATA_PREFIX "/sounds/stomp.wav",
- DATA_PREFIX "/sounds/kick.wav"
- };
-
-
#ifndef NOSOUND
#include <SDL_mixer.h>
/* functions handling the sound and music */
int open_audio(int frequency, Uint16 format, int channels, int chunksize);
+void close_audio( void );
Mix_Chunk * load_sound(char * file);
-void play_sound(Mix_Chunk * snd);
+void play_sound(Mix_Chunk * snd, enum Sound_Speaker whichSpeaker);
Mix_Music * load_song(char * file);
int playing_music(void);
#else
-//fake variables
+/* fake variables */
void* sounds[NUM_SOUNDS];
void* level_song, *herring_song;
-// fake sound handlers
+/* fake sound handlers */
int open_audio (int frequency, int format, int channels, int chunksize);
+void close_audio( void );
void* load_sound(void* file);
-void play_sound(void * snd);
+void play_sound(void * snd, enum Sound_Speaker whichSpeaker);
void* load_song(void* file);
int playing_music();
void halt_music();
int play_music(void *music, int loops);
void free_music(void *music);
-;
void free_chunk(void *chunk);
#endif
*/
-#ifdef LINUX
-#include <pwd.h>
-#include <sys/types.h>
-#include <ctype.h>
-#endif
-
-#include "defines.h"
-#include "globals.h"
-#include "setup.h"
-#include "intro.h"
-#include "title.h"
-#include "gameloop.h"
-#include "screen.h"
+#include "supertux.h"
/* --- MAIN --- */
{
done = title();
if (!done)
+ {
+ if(game_started)
done = gameloop();
+ else if(level_editor_started)
+ done = leveleditor(1);
+ }
}
clearscreen(0, 0, 0);
char str[80];
game_started = 0;
+ level_editor_started = 0;
/* Init menu variables */
initmenu();
/* Draw the title background: */
- drawimage(title, 0, 0, UPDATE);
+ drawimage(title, 0, 0, NO_UPDATE);
/* Draw the high score: */
last_highscore = load_hs();
sprintf(str, "High score: %d", last_highscore);
- drawcenteredtext(str, 460, letters_red, UPDATE);
+ drawcenteredtext(str, 460, letters_red, NO_UPDATE);
while (!done && !quit)
{
{
/* Draw the title background: */
- drawimage(title, 0, 0, UPDATE);
+ drawimage(title, 0, 0, NO_UPDATE);
/* Draw the high score: */
sprintf(str, "High score: %d", last_highscore);
- drawcenteredtext(str, 460, letters_red, UPDATE);
+ drawcenteredtext(str, 460, letters_red, NO_UPDATE);
}
/* Don't draw menu, if quit is true */
if(show_menu && !quit)
quit = drawmenu();
- if(game_started)
+ if(game_started || level_editor_started)
done = 1;
/* Animate title screen: */
pict = (frame / 5) % 3;
if (pict == 0)
- drawpart(title, 560, 270, 80, 75, UPDATE);
+ drawpart(title, 560, 270, 80, 75, NO_UPDATE);
else if (pict == 1)
- drawimage(anim1, 560, 270, UPDATE);
+ drawimage(anim1, 560, 270, NO_UPDATE);
else if (pict == 2)
- drawimage(anim2, 560, 270, UPDATE);
+ drawimage(anim2, 560, 270, NO_UPDATE);
+ SDL_Flip(screen);
/* Pause: */
//
-// C++ Interface: world
+// Interface: world
//
// Description:
//