From: Tobias Gläßer Date: Mon, 29 Dec 2003 00:41:09 +0000 (+0000) Subject: incoporated patches from Duong-Khang (stereo sound!) and Ricardo Cruz (LEVELEDITOR!) , improved menu and little fixes. SVN-Revision: 73 --- diff --git a/src/badguy.h b/src/badguy.h index 2cf9bb458..a064b48fb 100644 --- a/src/badguy.h +++ b/src/badguy.h @@ -1,5 +1,5 @@ // -// C++ Interface: enemy +// Interface: enemy // // Description: // diff --git a/src/gameloop.c b/src/gameloop.c index 1c78b971e..6f1272b8f 100644 --- a/src/gameloop.c +++ b/src/gameloop.c @@ -27,7 +27,6 @@ #include "globals.h" #include "gameloop.h" #include "screen.h" -#include "sound.h" #include "setup.h" #include "high_scores.h" #include "menu.h" @@ -35,6 +34,9 @@ #include "world.h" #include "player.h" +/* extern variables */ + +extern char* soundfilenames[NUM_SOUNDS]; /* Local variables: */ @@ -307,7 +309,7 @@ int game_action(void) { tux_skidding = SKID_TIME; - play_sound(sounds[SND_SKID]); + play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER); } tux_dir = RIGHT; @@ -360,7 +362,7 @@ int game_action(void) tux_dir == RIGHT) { tux_skidding = SKID_TIME; - play_sound(sounds[SND_SKID]); + play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER); } tux_dir = LEFT; } @@ -440,9 +442,9 @@ int game_action(void) 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); } } } @@ -780,7 +782,7 @@ int game_action(void) 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++; } @@ -800,7 +802,7 @@ int game_action(void) 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++; } @@ -848,7 +850,8 @@ int game_action(void) 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); } @@ -1054,7 +1057,7 @@ int game_action(void) /* Play death sound: */ - play_sound(sounds[SND_FALL]); + play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER); } } } @@ -1172,19 +1175,19 @@ int game_action(void) 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 ^^ */ @@ -1319,7 +1322,15 @@ int game_action(void) 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); + } } } @@ -1343,7 +1354,7 @@ int game_action(void) 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); @@ -1439,7 +1450,7 @@ int game_action(void) 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) { @@ -1447,7 +1458,7 @@ int game_action(void) { /* Flatten! */ - play_sound(sounds[SND_STOMP]); + play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER); bad_guys[i].mode = FLAT; bad_guys[i].timer = 64; @@ -1459,7 +1470,7 @@ int game_action(void) /* 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; @@ -1498,7 +1509,7 @@ int game_action(void) /* 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) { @@ -1521,7 +1532,7 @@ int game_action(void) /* 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 @@ -1538,7 +1549,7 @@ int game_action(void) { bad_guys[i].dying = FALLING; bad_guys[i].ym = -8; - play_sound(sounds[SND_FALL]); + play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER); } } } @@ -1553,7 +1564,7 @@ int game_action(void) { bad_guys[i].dying = FALLING; bad_guys[i].ym = -8; - play_sound(sounds[SND_FALL]); + play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER); } } } @@ -2254,6 +2265,7 @@ int gameloop(void) /* Init the game: */ initmenu(); + menumenu = MENU_GAME; initgame(); loadshared(); loadlevel(); @@ -3391,7 +3403,7 @@ void trybreakbrick(int x, int y, int sx) 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++; } @@ -3411,7 +3423,7 @@ void trybreakbrick(int x, int y, int sx) /* Get some score: */ - play_sound(sounds[SND_BRICK]); + play_sound(sounds[SND_BRICK], SOUND_CENTER_SPEAKER); score = score + SCORE_BRICK; } } @@ -3424,7 +3436,7 @@ void bumpbrick(int x, int y, int sx) add_bouncy_brick(((x + sx + 1) / 32) * 32, (y / 32) * 32); - play_sound(sounds[SND_BRICK]); + play_sound(sounds[SND_BRICK], SOUND_CENTER_SPEAKER); } @@ -3441,7 +3453,7 @@ void tryemptybox(int x, int y, int sx) 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++; } @@ -3466,7 +3478,7 @@ void tryemptybox(int x, int y, int sx) UPGRADE_COFFEE); } - play_sound(sounds[SND_UPGRADE]); + play_sound(sounds[SND_UPGRADE], SOUND_CENTER_SPEAKER); } else if (shape(x, y, sx) == '!') { @@ -3491,7 +3503,7 @@ void trygrabdistro(int x, int y, int sx, int bounciness) 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) { @@ -3677,7 +3689,7 @@ void trybumpbadguy(int x, int y, int sx) { bad_guys[i].dying = FALLING; bad_guys[i].ym = -8; - play_sound(sounds[SND_FALL]); + play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER); } } } @@ -3693,7 +3705,7 @@ void trybumpbadguy(int x, int y, int sx) { 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); } } } @@ -3732,7 +3744,7 @@ void killtux(int mode) { tux_ym = -16; - play_sound(sounds[SND_HURT]); + play_sound(sounds[SND_HURT], SOUND_CENTER_SPEAKER); if (tux_dir == RIGHT) tux_xm = -8; @@ -3787,7 +3799,7 @@ void add_bullet(int x, int y, int dir, int xm) bullets[found].y = y; bullets[found].ym = BULLET_STARTING_YM; - play_sound(sounds[SND_SHOOT]); + play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER); } } diff --git a/src/gameloop.h b/src/gameloop.h index 4104577e7..6b6c825d2 100644 --- a/src/gameloop.h +++ b/src/gameloop.h @@ -10,134 +10,140 @@ 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); diff --git a/src/globals.h b/src/globals.h index f26dde707..ffcd5d0fe 100644 --- a/src/globals.h +++ b/src/globals.h @@ -21,7 +21,7 @@ SDL_Surface * letters_black, * letters_gold, * letters_blue, * letters_red; 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; diff --git a/src/menu.c b/src/menu.c index ef2a3d4fa..b2473acf4 100644 --- a/src/menu.c +++ b/src/menu.c @@ -22,7 +22,7 @@ #include "screen.h" #include "setup.h" #include "sound.h" - +#include "leveleditor.h" /* Set defaults */ void initmenu(void) @@ -40,10 +40,10 @@ void menu_option_sound() 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 */ @@ -58,18 +58,18 @@ void menu_option_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); } } } @@ -81,10 +81,10 @@ void menu_option_music() 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 */ @@ -114,66 +114,36 @@ void menu_option_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; @@ -181,12 +151,11 @@ int drawmenu(void) } } 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; @@ -194,39 +163,93 @@ int drawmenu(void) } } 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) @@ -240,10 +263,10 @@ int drawmenu(void) 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(); @@ -253,21 +276,123 @@ int drawmenu(void) 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; } diff --git a/src/menu.h b/src/menu.h index 90a162d10..0d9dc41ea 100644 --- a/src/menu.h +++ b/src/menu.h @@ -23,7 +23,9 @@ int show_menu; 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 { @@ -35,7 +37,9 @@ enum { /* Menus */ enum { MENU_MAIN, - MENU_OPTIONS + MENU_GAME, + MENU_OPTIONS, + MENU_LEVELEDITOR }; /* Initialize the menu variables */ diff --git a/src/player.h b/src/player.h index 1c9420eaf..74e17ba35 100644 --- a/src/player.h +++ b/src/player.h @@ -1,5 +1,5 @@ // -// C++ Interface: tux +// Interface: tux // // Description: // diff --git a/src/screen.c b/src/screen.c index eaa7d6daa..99a1acb58 100644 --- a/src/screen.c +++ b/src/screen.c @@ -122,6 +122,19 @@ void drawpart(SDL_Surface * surf, int x, int y, int w, int h, int update) 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 --- */ @@ -131,7 +144,6 @@ void drawtext(char * text, int x, int y, SDL_Surface * surf, int update) char c; SDL_Rect src, dest; - /* For each letter in the string... */ for (i = 0; i < strlen(text); i++) @@ -218,6 +230,7 @@ void drawtext(char * text, int x, int y, SDL_Surface * surf, int update) SDL_UpdateRect(screen, x, y, dest.w, 17); } + } @@ -228,6 +241,12 @@ void drawcenteredtext(char * text, int y, SDL_Surface * surf, int update) 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: --- */ diff --git a/src/screen.h b/src/screen.h index 600004a01..017d87705 100644 --- a/src/screen.h +++ b/src/screen.h @@ -24,6 +24,8 @@ SDL_Surface * load_image(char * file, int use_alpha); 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); diff --git a/src/setup.c b/src/setup.c index abca8ff88..0175fb8f2 100644 --- a/src/setup.c +++ b/src/setup.c @@ -29,7 +29,7 @@ #include "globals.h" #include "setup.h" #include "screen.h" -#include "sound.h" + /* Local function prototypes: */ @@ -273,6 +273,7 @@ void st_audio_setup(void) void st_shutdown(void) { + close_audio(); SDL_Quit(); } @@ -382,8 +383,6 @@ void parseargs(int argc, char * argv[]) 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 } @@ -396,7 +395,6 @@ void parseargs(int argc, char * argv[]) #else printf("Warning: Music feature is not compiled in \n"); #endif - } else if (strcmp(argv[i], "--debug-mode") == 0) { diff --git a/src/setup.h b/src/setup.h index e999b2a3e..1fa4706ff 100644 --- a/src/setup.h +++ b/src/setup.h @@ -10,11 +10,18 @@ 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 + diff --git a/src/sound.c b/src/sound.c index 2fcc0fd96..4cca05bdc 100644 --- a/src/sound.c +++ b/src/sound.c @@ -10,24 +10,41 @@ April 22, 2000 - December 28, 2003 */ -/* -#include -#include -#include -#include -*/ - +/* why do we need this ? #ifdef LINUX #include #include #include #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 @@ -36,7 +53,36 @@ 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(); + } } @@ -71,16 +117,29 @@ Mix_Music * load_song(char * file) } -/* --- 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; + } } } @@ -95,6 +154,7 @@ void free_chunk(Mix_Chunk *chunk) } } + int playing_music(void) { if (use_music == YES) @@ -154,29 +214,47 @@ int open_audio (int frequency, int format, int channels, int chunksize) 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) {} diff --git a/src/sound.h b/src/sound.h index 4eb702a8a..14feafa97 100644 --- a/src/sound.h +++ b/src/sound.h @@ -18,9 +18,12 @@ #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 */ @@ -31,8 +34,14 @@ enum Music_Type { 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, @@ -55,29 +64,6 @@ enum { 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 @@ -88,9 +74,10 @@ Mix_Music * level_song, * level_song_fast, * herring_song; /* 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); @@ -101,22 +88,22 @@ void free_chunk(Mix_Chunk*chunk); #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 diff --git a/src/supertux.c b/src/supertux.c index 4d18534aa..924ccb348 100644 --- a/src/supertux.c +++ b/src/supertux.c @@ -11,19 +11,7 @@ */ -#ifdef LINUX -#include -#include -#include -#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 --- */ @@ -52,7 +40,12 @@ int main(int argc, char * argv[]) { done = title(); if (!done) + { + if(game_started) done = gameloop(); + else if(level_editor_started) + done = leveleditor(1); + } } clearscreen(0, 0, 0); diff --git a/src/title.c b/src/title.c index 993095c19..db99b5ce0 100644 --- a/src/title.c +++ b/src/title.c @@ -43,6 +43,7 @@ int title(void) char str[80]; game_started = 0; + level_editor_started = 0; /* Init menu variables */ initmenu(); @@ -69,13 +70,13 @@ int title(void) /* 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) { @@ -131,18 +132,18 @@ int title(void) { /* 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: */ @@ -150,13 +151,14 @@ int title(void) 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: */ diff --git a/src/world.h b/src/world.h index 24385f752..30d1b3948 100644 --- a/src/world.h +++ b/src/world.h @@ -1,5 +1,5 @@ // -// C++ Interface: world +// Interface: world // // Description: //