From a8cca71cd712f319ff0e5e99b35eb17f0156d941 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Gl=C3=A4=C3=9Fer?= Date: Mon, 29 Dec 2003 12:51:09 +0000 Subject: [PATCH] draw*text <- functions can now specify the size of the shadow :) SVN-Revision: 77 --- src/gameloop.c | 480 +++++++++++------------ src/intro.c | 14 +- src/leveleditor.c | 1112 ++++++++++++++++++++++++++--------------------------- src/menu.c | 544 +++++++++++++------------- src/screen.c | 39 +- src/screen.h | 10 +- src/title.c | 12 +- 7 files changed, 1107 insertions(+), 1104 deletions(-) diff --git a/src/gameloop.c b/src/gameloop.c index 6f1272b8f..e1f4e7324 100644 --- a/src/gameloop.c +++ b/src/gameloop.c @@ -7,7 +7,7 @@ bill@newbreedsoftware.com http://www.newbreedsoftware.com/supertux/ - April 11, 2000 - December 28, 2003 + April 11, 2000 - December 29, 2003 */ #include @@ -63,18 +63,18 @@ SDL_Surface * img_box_full, * img_box_empty, * img_mints, * img_coffee, * img_super_bkgd, * img_bullet, * img_red_glow; SDL_Surface * img_cloud[2][4]; SDL_Surface * tux_life, - * tux_right[3], * tux_left[3], - * bigtux_right[3], * bigtux_left[3], - * bigtux_right_jump, * bigtux_left_jump, - * ducktux_right, * ducktux_left, - * skidtux_right, * skidtux_left, - * firetux_right[3], * firetux_left[3], - * bigfiretux_right[3], * bigfiretux_left[3], - * bigfiretux_right_jump, * bigfiretux_left_jump, - * duckfiretux_right, * duckfiretux_left, - * skidfiretux_right, * skidfiretux_left, - * cape_right[2], * cape_left[2], - * bigcape_right[2], * bigcape_left[2]; +* tux_right[3], * tux_left[3], +* bigtux_right[3], * bigtux_left[3], +* bigtux_right_jump, * bigtux_left_jump, +* ducktux_right, * ducktux_left, +* skidtux_right, * skidtux_left, +* firetux_right[3], * firetux_left[3], +* bigfiretux_right[3], * bigfiretux_left[3], +* bigfiretux_right_jump, * bigfiretux_left_jump, +* duckfiretux_right, * duckfiretux_left, +* skidfiretux_right, * skidfiretux_left, +* cape_right[2], * cape_left[2], +* bigcape_right[2], * bigcape_left[2]; SDL_Event event; SDL_Rect src, dest; SDLKey key; @@ -551,16 +551,16 @@ int game_action(void) /* Keep tux in bounds: */ if (tux_x < 0) tux_x = 0; - else if (tux_x < 160 && scroll_x > 0 && debug_mode == YES) + else if (tux_x < 160 && scroll_x > 0 && debug_mode == YES) { - scroll_x = scroll_x - ( 160 - tux_x); - tux_x = 160; - - if(scroll_x < 0) - scroll_x = 0; - + scroll_x = scroll_x - ( 160 - tux_x); + tux_x = 160; + + if(scroll_x < 0) + scroll_x = 0; + } - else if (tux_x > 320 && scroll_x < ((level_width * 32) - 640)) + else if (tux_x > 320 && scroll_x < ((level_width * 32) - 640)) { /* Scroll the screen in past center: */ @@ -1092,13 +1092,13 @@ int game_action(void) } if (!playing_music()) - { - if (time_left <= TIME_WARNING) - play_music( level_song_fast, 1 ); - else - play_music( level_song, 1 ); - } - + { + if (time_left <= TIME_WARNING) + play_music( level_song_fast, 1 ); + else + play_music( level_song, 1 ); + } + if (tux_invincible_time > 0) tux_invincible_time--; } @@ -1907,30 +1907,30 @@ void game_draw() } - if (!tux_got_coffee) - { - if (tux_dir == RIGHT) - { - drawimage(tux_right[tux_frame], tux_x, tux_y, NO_UPDATE); - } - else - { - drawimage(tux_left[tux_frame], tux_x, tux_y, NO_UPDATE); - } - } - else - { - /* Tux got coffee! */ - - if (tux_dir == RIGHT) - { - drawimage(firetux_right[tux_frame], tux_x, tux_y, NO_UPDATE); - } - else - { - drawimage(firetux_left[tux_frame], tux_x, tux_y, NO_UPDATE); - } - } + if (!tux_got_coffee) + { + if (tux_dir == RIGHT) + { + drawimage(tux_right[tux_frame], tux_x, tux_y, NO_UPDATE); + } + else + { + drawimage(tux_left[tux_frame], tux_x, tux_y, NO_UPDATE); + } + } + else + { + /* Tux got coffee! */ + + if (tux_dir == RIGHT) + { + drawimage(firetux_right[tux_frame], tux_x, tux_y, NO_UPDATE); + } + else + { + drawimage(firetux_left[tux_frame], tux_x, tux_y, NO_UPDATE); + } + } } else { @@ -1952,143 +1952,143 @@ void game_draw() } } - if (!tux_got_coffee) - { - if (!tux_duck) - { - if (!tux_skidding) - { - if (!jumping || tux_ym > 0) - { - if (tux_dir == RIGHT) - { - drawimage(bigtux_right[tux_frame], - tux_x - 8, tux_y - 32, - NO_UPDATE); - } - else - { - drawimage(bigtux_left[tux_frame], - tux_x - 8, tux_y - 32, - NO_UPDATE); - } - } - else - { - if (tux_dir == RIGHT) - { - drawimage(bigtux_right_jump, - tux_x - 8, tux_y - 32, - NO_UPDATE); - } - else - { - drawimage(bigtux_left_jump, - tux_x - 8, tux_y - 32, - NO_UPDATE); - } - } - } - else - { - if (tux_dir == RIGHT) - { - drawimage(skidtux_right, - tux_x - 8, tux_y - 32, - NO_UPDATE); - } - else - { - drawimage(skidtux_left, - tux_x - 8, tux_y - 32, - NO_UPDATE); - } - } - } - else - { - if (tux_dir == RIGHT) - { - drawimage(ducktux_right, tux_x - 8, tux_y - 16, - NO_UPDATE); - } - else - { - drawimage(ducktux_left, tux_x - 8, tux_y - 16, - NO_UPDATE); - } - } - } - else - { - /* Tux has coffee! */ - - if (!tux_duck) - { - if (!tux_skidding) - { - if (!jumping || tux_ym > 0) - { - if (tux_dir == RIGHT) - { - drawimage(bigfiretux_right[tux_frame], - tux_x - 8, tux_y - 32, - NO_UPDATE); - } - else - { - drawimage(bigfiretux_left[tux_frame], - tux_x - 8, tux_y - 32, - NO_UPDATE); - } - } - else - { - if (tux_dir == RIGHT) - { - drawimage(bigfiretux_right_jump, - tux_x - 8, tux_y - 32, - NO_UPDATE); - } - else - { - drawimage(bigfiretux_left_jump, - tux_x - 8, tux_y - 32, - NO_UPDATE); - } - } - } - else - { - if (tux_dir == RIGHT) - { - drawimage(skidfiretux_right, - tux_x - 8, tux_y - 32, - NO_UPDATE); - } - else - { - drawimage(skidfiretux_left, - tux_x - 8, tux_y - 32, - NO_UPDATE); - } - } - } - else - { - if (tux_dir == RIGHT) - { - drawimage(duckfiretux_right, tux_x - 8, tux_y - 16, - NO_UPDATE); - } - else - { - drawimage(duckfiretux_left, tux_x - 8, tux_y - 16, - NO_UPDATE); - } - } - } - } + if (!tux_got_coffee) + { + if (!tux_duck) + { + if (!tux_skidding) + { + if (!jumping || tux_ym > 0) + { + if (tux_dir == RIGHT) + { + drawimage(bigtux_right[tux_frame], + tux_x - 8, tux_y - 32, + NO_UPDATE); + } + else + { + drawimage(bigtux_left[tux_frame], + tux_x - 8, tux_y - 32, + NO_UPDATE); + } + } + else + { + if (tux_dir == RIGHT) + { + drawimage(bigtux_right_jump, + tux_x - 8, tux_y - 32, + NO_UPDATE); + } + else + { + drawimage(bigtux_left_jump, + tux_x - 8, tux_y - 32, + NO_UPDATE); + } + } + } + else + { + if (tux_dir == RIGHT) + { + drawimage(skidtux_right, + tux_x - 8, tux_y - 32, + NO_UPDATE); + } + else + { + drawimage(skidtux_left, + tux_x - 8, tux_y - 32, + NO_UPDATE); + } + } + } + else + { + if (tux_dir == RIGHT) + { + drawimage(ducktux_right, tux_x - 8, tux_y - 16, + NO_UPDATE); + } + else + { + drawimage(ducktux_left, tux_x - 8, tux_y - 16, + NO_UPDATE); + } + } + } + else + { + /* Tux has coffee! */ + + if (!tux_duck) + { + if (!tux_skidding) + { + if (!jumping || tux_ym > 0) + { + if (tux_dir == RIGHT) + { + drawimage(bigfiretux_right[tux_frame], + tux_x - 8, tux_y - 32, + NO_UPDATE); + } + else + { + drawimage(bigfiretux_left[tux_frame], + tux_x - 8, tux_y - 32, + NO_UPDATE); + } + } + else + { + if (tux_dir == RIGHT) + { + drawimage(bigfiretux_right_jump, + tux_x - 8, tux_y - 32, + NO_UPDATE); + } + else + { + drawimage(bigfiretux_left_jump, + tux_x - 8, tux_y - 32, + NO_UPDATE); + } + } + } + else + { + if (tux_dir == RIGHT) + { + drawimage(skidfiretux_right, + tux_x - 8, tux_y - 32, + NO_UPDATE); + } + else + { + drawimage(skidfiretux_left, + tux_x - 8, tux_y - 32, + NO_UPDATE); + } + } + } + else + { + if (tux_dir == RIGHT) + { + drawimage(duckfiretux_right, tux_x - 8, tux_y - 16, + NO_UPDATE); + } + else + { + drawimage(duckfiretux_left, tux_x - 8, tux_y - 16, + NO_UPDATE); + } + } + } + } } @@ -2116,7 +2116,7 @@ void game_draw() drawtext(str, floating_scores[i].x + 16 - strlen(str) * 8, floating_scores[i].y, - letters_gold, NO_UPDATE); + letters_gold, NO_UPDATE, 1); } } @@ -2211,33 +2211,33 @@ void game_draw() /* (Status): */ sprintf(str, "%d", score); - drawtext("SCORE", 0, 0, letters_blue, NO_UPDATE); - drawtext(str, 96, 0, letters_gold, NO_UPDATE); + drawtext("SCORE", 0, 0, letters_blue, NO_UPDATE, 1); + drawtext(str, 96, 0, letters_gold, NO_UPDATE, 1); sprintf(str, "%d", highscore); - drawtext("HIGH", 0, 20, letters_blue, NO_UPDATE); - drawtext(str, 96, 20, letters_gold, NO_UPDATE); + drawtext("HIGH", 0, 20, letters_blue, NO_UPDATE, 1); + drawtext(str, 96, 20, letters_gold, NO_UPDATE, 1); if (time_left >= TIME_WARNING || (frame % 10) < 5) { sprintf(str, "%d", time_left); - drawtext("TIME", 224, 0, letters_blue, NO_UPDATE); - drawtext(str, 304, 0, letters_gold, NO_UPDATE); + drawtext("TIME", 224, 0, letters_blue, NO_UPDATE, 1); + drawtext(str, 304, 0, letters_gold, NO_UPDATE, 1); } sprintf(str, "%d", distros); - drawtext("DISTROS", 480, 0, letters_blue, NO_UPDATE); - drawtext(str, 608, 0, letters_gold, NO_UPDATE); + drawtext("DISTROS", 480, 0, letters_blue, NO_UPDATE, 1); + drawtext(str, 608, 0, letters_gold, NO_UPDATE, 1); - drawtext("LIVES", 480, 20, letters_blue, NO_UPDATE); + drawtext("LIVES", 480, 20, letters_blue, NO_UPDATE, 1); for(i=0; i < lives; ++i) { drawimage(tux_life,565+(18*i),20,NO_UPDATE); } - + if(game_pause) - drawcenteredtext("PAUSE",230,letters_red, NO_UPDATE); + drawcenteredtext("PAUSE",230,letters_red, NO_UPDATE, 1); if(show_menu) done = drawmenu(); @@ -2321,9 +2321,9 @@ int gameloop(void) switch (current_music) { case LEVEL_MUSIC: - if (time_left <= TIME_WARNING) + if (time_left <= TIME_WARNING) play_music(level_song_fast, 1); - else + else play_music(level_song, 1); break; case HERRING_MUSIC: @@ -2346,7 +2346,7 @@ int gameloop(void) 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: */ @@ -2355,9 +2355,9 @@ int gameloop(void) { time_left--; - /* Stop the music; it will start again, faster! */ - if (time_left == TIME_WARNING) - halt_music(); + /* Stop the music; it will start again, faster! */ + if (time_left == TIME_WARNING) + halt_music(); if (time_left <= 0) killtux(KILL); @@ -2563,13 +2563,13 @@ void loadlevel(void) clearscreen(0, 0, 0); sprintf(str, "LEVEL %d", level); - drawcenteredtext(str, 200, letters_red, NO_UPDATE); + drawcenteredtext(str, 200, letters_red, NO_UPDATE, 1); sprintf(str, "%s", levelname); - drawcenteredtext(str, 224, letters_gold, NO_UPDATE); + drawcenteredtext(str, 224, letters_gold, NO_UPDATE, 1); sprintf(str, "TUX x %d", lives); - drawcenteredtext(str, 256, letters_blue, NO_UPDATE); + drawcenteredtext(str, 256, letters_blue, NO_UPDATE, 1); SDL_Flip(screen); @@ -2629,7 +2629,7 @@ void loadlevelsong(void) level_song = load_song(song_path); free(song_path); - + song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + strlen(song_title) + 8 + 5)); song_subtitle = strdup(song_title); @@ -2696,22 +2696,22 @@ void loadshared(void) USE_ALPHA); firetux_right[0] = load_image(DATA_PREFIX "/images/shared/firetux-right-0.png", - USE_ALPHA); + USE_ALPHA); firetux_right[1] = load_image(DATA_PREFIX "/images/shared/firetux-right-1.png", - USE_ALPHA); + USE_ALPHA); firetux_right[2] = load_image(DATA_PREFIX "/images/shared/firetux-right-2.png", - USE_ALPHA); + USE_ALPHA); firetux_left[0] = load_image(DATA_PREFIX "/images/shared/firetux-left-0.png", - USE_ALPHA); + USE_ALPHA); firetux_left[1] = load_image(DATA_PREFIX "/images/shared/firetux-left-1.png", - USE_ALPHA); + USE_ALPHA); firetux_left[2] = load_image(DATA_PREFIX "/images/shared/firetux-left-2.png", - USE_ALPHA); + USE_ALPHA); cape_right[0] = load_image(DATA_PREFIX "/images/shared/cape-right-0.png", USE_ALPHA); @@ -2766,25 +2766,25 @@ void loadshared(void) USE_ALPHA); bigfiretux_right[0] = load_image(DATA_PREFIX "/images/shared/bigfiretux-right-0.png", - USE_ALPHA); + USE_ALPHA); bigfiretux_right[1] = load_image(DATA_PREFIX "/images/shared/bigfiretux-right-1.png", - USE_ALPHA); + USE_ALPHA); bigfiretux_right[2] = load_image(DATA_PREFIX "/images/shared/bigfiretux-right-2.png", - USE_ALPHA); + USE_ALPHA); bigfiretux_right_jump = load_image(DATA_PREFIX "/images/shared/bigfiretux-right-jump.png", USE_ALPHA); bigfiretux_left[0] = load_image(DATA_PREFIX "/images/shared/bigfiretux-left-0.png", - USE_ALPHA); + USE_ALPHA); bigfiretux_left[1] = load_image(DATA_PREFIX "/images/shared/bigfiretux-left-1.png", - USE_ALPHA); + USE_ALPHA); bigfiretux_left[2] = load_image(DATA_PREFIX "/images/shared/bigfiretux-left-2.png", - USE_ALPHA); + USE_ALPHA); bigfiretux_left_jump = load_image(DATA_PREFIX "/images/shared/bigfiretux-left-jump.png", USE_ALPHA); @@ -2823,20 +2823,20 @@ void loadshared(void) USE_ALPHA); duckfiretux_right = load_image(DATA_PREFIX - "/images/shared/duckfiretux-right.png", - USE_ALPHA); + "/images/shared/duckfiretux-right.png", + USE_ALPHA); duckfiretux_left = load_image(DATA_PREFIX - "/images/shared/duckfiretux-left.png", - USE_ALPHA); + "/images/shared/duckfiretux-left.png", + USE_ALPHA); skidfiretux_right = load_image(DATA_PREFIX - "/images/shared/skidfiretux-right.png", - USE_ALPHA); + "/images/shared/skidfiretux-right.png", + USE_ALPHA); skidfiretux_left = load_image(DATA_PREFIX - "/images/shared/skidfiretux-left.png", - USE_ALPHA); + "/images/shared/skidfiretux-left.png", + USE_ALPHA); /* Boxes: */ @@ -3035,8 +3035,8 @@ void loadshared(void) img_red_glow = load_image(DATA_PREFIX "/images/shared/red-glow.png", USE_ALPHA); - - + + /* Distros: */ @@ -3052,7 +3052,7 @@ void loadshared(void) img_distro[3] = load_image(DATA_PREFIX "/images/shared/distro-3.png", USE_ALPHA); - + /* Tux life: */ tux_life = load_image(DATA_PREFIX "/images/shared/tux-life.png", @@ -3810,13 +3810,13 @@ void drawendscreen(void) clearscreen(0, 0, 0); - drawcenteredtext("GAMEOVER", 200, letters_red, NO_UPDATE); + drawcenteredtext("GAMEOVER", 200, letters_red, NO_UPDATE, 1); sprintf(str, "SCORE: %d", score); - drawcenteredtext(str, 224, letters_gold, NO_UPDATE); + drawcenteredtext(str, 224, letters_gold, NO_UPDATE, 1); sprintf(str, "DISTROS: %d", distros); - drawcenteredtext(str, 256, letters_blue, NO_UPDATE); + drawcenteredtext(str, 256, letters_blue, NO_UPDATE, 1); SDL_Flip(screen); SDL_Delay(2000); @@ -3828,13 +3828,13 @@ void drawresultscreen(void) clearscreen(0, 0, 0); - drawcenteredtext("Result:", 200, letters_red, NO_UPDATE); + drawcenteredtext("Result:", 200, letters_red, NO_UPDATE, 1); sprintf(str, "SCORE: %d", score); - drawcenteredtext(str, 224, letters_gold, NO_UPDATE); + drawcenteredtext(str, 224, letters_gold, NO_UPDATE, 1); sprintf(str, "DISTROS: %d", distros); - drawcenteredtext(str, 256, letters_blue, NO_UPDATE); + drawcenteredtext(str, 256, letters_blue, NO_UPDATE, 1); SDL_Flip(screen); /*SDL_Delay(2000);*/ diff --git a/src/intro.c b/src/intro.c index f340c496a..b6ea153b4 100644 --- a/src/intro.c +++ b/src/intro.c @@ -141,7 +141,7 @@ int intro(void) drawimage(tux_sit, 270, 400, UPDATE); drawimage(gown_sit, 320, 400, UPDATE); - drawcenteredtext(intro_text[0], 456, letters_blue, UPDATE); + drawcenteredtext(intro_text[0], 456, letters_blue, UPDATE, 1); } @@ -149,8 +149,8 @@ int intro(void) { /* Helicopter begins to fly in: */ - erasecenteredtext(intro_text[0], 456, bkgd, UPDATE); - drawcenteredtext(intro_text[1], 456, letters_red, UPDATE); + erasecenteredtext(intro_text[0], 456, bkgd, UPDATE, 1); + drawcenteredtext(intro_text[1], 456, letters_red, UPDATE, 1); } @@ -203,8 +203,8 @@ int intro(void) drawimage(tux_upset, 270, 400, UPDATE); - erasecenteredtext(intro_text[1], 456, bkgd, UPDATE); - drawcenteredtext(intro_text[2], 456, letters_red, UPDATE); + erasecenteredtext(intro_text[1], 456, bkgd, UPDATE, 1); + drawcenteredtext(intro_text[2], 456, letters_red, UPDATE, 1); } @@ -256,8 +256,8 @@ int intro(void) drawimage(tux_mad, 270, 400, UPDATE); - erasecenteredtext(intro_text[2], 456, bkgd, UPDATE); - drawcenteredtext(intro_text[3], 456, letters_gold, UPDATE); + erasecenteredtext(intro_text[2], 456, bkgd, UPDATE, 1); + drawcenteredtext(intro_text[3], 456, letters_gold, UPDATE, 1); } diff --git a/src/leveleditor.c b/src/leveleditor.c index b07807134..48c45322e 100644 --- a/src/leveleditor.c +++ b/src/leveleditor.c @@ -7,7 +7,9 @@ * (at your option) any later version. * * * ***************************************************************************/ - + +/* December 28, 2003 - December 29, 2003 */ + /* leveleditor.c - A built-in level editor for SuperTux by Ricardo Cruz */ @@ -76,470 +78,468 @@ void showhelp(); /* FIXME: Needs to be implemented. It should ask the user for the level(file)name and then let him create a new level based on this. */ void newlevel() { - } /* FIXME: It should let select the user a level, which is in the leveldirectory and then load it. */ void selectlevel() { - } int leveleditor() { -char str[10]; - - -strcpy(levelfilename,"level1"); - -initmenu(); -menumenu = MENU_LEVELEDITOR; -show_menu = YES; - -loadshared(); -le_loadlevel(); -loadlevelgfx(); - -selection = load_image(DATA_PREFIX "/images/leveleditor/select.png", USE_ALPHA); - -int done; -done = 0; - -int x, y, i; /* for cicles */ -int pos_x, cursor_x, cursor_y, old_cursor_x, fire; - -pos_x = 0; -cursor_x = 3*32; -old_cursor_x = cursor_x; -cursor_y = 2*32; -fire = DOWN; - -SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); - -SDL_Event event; -SDLKey key; -SDLMod keymod; - -while(1) - { - SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, bkgd_red, bkgd_green, bkgd_blue)); - - keymod = SDL_GetModState(); - - while(SDL_PollEvent(&event)) - { - // testing SDL_KEYDOWN, SDL_KEYUP and SDL_QUIT events - switch(event.type) - { - case SDL_KEYDOWN: // key pressed - key = event.key.keysym.sym; - if(show_menu) - { - menu_event(key); - break; - } - switch(key) - { - case SDLK_LEFT: - if(fire == DOWN) - cursor_x -= KEY_CURSOR_SPEED; - else - cursor_x -= KEY_CURSOR_FASTSPEED; - - if(cursor_x < 0) - cursor_x = 0; - break; - case SDLK_RIGHT: - if(fire == DOWN) - cursor_x += KEY_CURSOR_SPEED; - else - cursor_x += KEY_CURSOR_FASTSPEED; - - if(cursor_x > (level_width*32) - 1) - cursor_x = (level_width*32) - 1; - break; - case SDLK_UP: - if(fire == DOWN) - cursor_y -= KEY_CURSOR_SPEED; - else - cursor_y -= KEY_CURSOR_FASTSPEED; - - if(cursor_y < 0) - cursor_y = 0; - break; - case SDLK_DOWN: - if(fire == DOWN) - cursor_y += KEY_CURSOR_SPEED; - else - cursor_y += KEY_CURSOR_FASTSPEED; - - if(cursor_y > 480-32) - cursor_y = 480-32; - break; - case SDLK_LCTRL: - fire = UP; - break; - case SDLK_F1: - showhelp(); - break; - case SDLK_HOME: - cursor_x = 0; - break; - case SDLK_END: - cursor_x = (level_width * 32) - 32; - break; - case SDLK_PERIOD: - le_change(cursor_x, cursor_y, 0, '.'); - break; - case SDLK_a: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, 'A'); - else - le_change(cursor_x, cursor_y, 0, 'a'); - break; - case SDLK_b: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, 'B'); - break; - case SDLK_c: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, 'C'); - else - le_change(cursor_x, cursor_y, 0, 'c'); - break; - case SDLK_d: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, 'D'); - else - le_change(cursor_x, cursor_y, 0, 'd'); - break; - case SDLK_e: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, 'E'); - else - le_change(cursor_x, cursor_y, 0, 'e'); - break; - case SDLK_f: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, 'F'); - else - le_change(cursor_x, cursor_y, 0, 'f'); - break; - case SDLK_g: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, 'G'); - else - le_change(cursor_x, cursor_y, 0, 'g'); - break; - case SDLK_h: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, 'H'); - else - le_change(cursor_x, cursor_y, 0, 'h'); - break; - case SDLK_i: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, 'I'); - else - le_change(cursor_x, cursor_y, 0, 'i'); - break; - case SDLK_j: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, 'J'); - else - le_change(cursor_x, cursor_y, 0, 'j'); - break; - case SDLK_x: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, 'X'); - else - le_change(cursor_x, cursor_y, 0, 'x'); - break; - case SDLK_y: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, 'Y'); - else - le_change(cursor_x, cursor_y, 0, 'y'); - break; - case SDLK_LEFTBRACKET: - le_change(cursor_x, cursor_y, 0, '['); - break; - case SDLK_RIGHTBRACKET: - le_change(cursor_x, cursor_y, 0, ']'); - break; - case SDLK_HASH: - case SDLK_3: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, '#'); - break; - case SDLK_DOLLAR: - case SDLK_4: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, '$'); - break; - case SDLK_BACKSLASH: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, '|'); - else - le_change(cursor_x, cursor_y, 0, '\\'); - break; - case SDLK_CARET: - le_change(cursor_x, cursor_y, 0, '^'); - break; - case SDLK_AMPERSAND: - case SDLK_6: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, '&'); - break; - case SDLK_EQUALS: - case SDLK_0: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, '='); - else /* let's add a bad guy */ - le_change(cursor_x, cursor_y, 0, '0'); - - for(i = 0; i < NUM_BAD_GUYS; ++i) - if (bad_guys[i].alive == NO) - { - bad_guys[i].alive = YES; - bad_guys[i].kind = BAD_BSOD; - bad_guys[i].x = (((int)cursor_x/32)*32); - bad_guys[i].y = (((int)cursor_y/32)*32); - i = NUM_BAD_GUYS; - } - break; - case SDLK_1: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, '!'); - else /* let's add a bad guy */ - le_change(cursor_x, cursor_y, 0, '1'); - - for(i = 0; i < NUM_BAD_GUYS; ++i) - if (bad_guys[i].alive == NO) - { - bad_guys[i].alive = YES; - bad_guys[i].kind = BAD_LAPTOP; - bad_guys[i].x = (((int)cursor_x/32)*32); - bad_guys[i].y = (((int)cursor_y/32)*32); - i = NUM_BAD_GUYS; - } - break; - case SDLK_2: - le_change(cursor_x, cursor_y, 0, '2'); - - for(i = 0; i < NUM_BAD_GUYS; ++i) - if (bad_guys[i].alive == NO) - { - bad_guys[i].alive = YES; - bad_guys[i].kind = BAD_MONEY; - bad_guys[i].x = (((int)cursor_x/32)*32); - bad_guys[i].y = (((int)cursor_y/32)*32); - i = NUM_BAD_GUYS; - } - break; - case SDLK_PLUS: - if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) - le_change(cursor_x, cursor_y, 0, '*'); - break; - default: - break; - } - break; - case SDL_KEYUP: // key released - switch(event.key.keysym.sym) - { - case SDLK_LCTRL: - fire = DOWN; - break; - case SDLK_ESCAPE: - if(!show_menu) - show_menu = YES; - else - show_menu = NO; - break; - default: - break; - } - break; - case SDL_MOUSEBUTTONDOWN: - if(event.button.button == SDL_BUTTON_LEFT) - { - x = event.motion.x; - y = event.motion.y; - - cursor_x = ((int)(pos_x + x) / 32) * 32; - cursor_y = ((int) y / 32) * 32; - } - break; - case SDL_MOUSEMOTION: - x = event.motion.x; - y = event.motion.y; - - cursor_x = ((int)(pos_x + x) / 32) * 32; - cursor_y = ((int) y / 32) * 32; - break; - case SDL_QUIT: // window closed - done = DONE_QUIT; - break; - default: - break; - } - } - - /* mouse movements */ - x = event.motion.x; - if(x < MOUSE_LEFT_MARGIN) - pos_x -= MOUSE_POS_SPEED; - else if(x > MOUSE_RIGHT_MARGIN) - pos_x += MOUSE_POS_SPEED; - - if(old_cursor_x != cursor_x) - { - if(cursor_x < pos_x + KEY_LEFT_MARGIN) - pos_x = cursor_x - KEY_LEFT_MARGIN; - - if(cursor_x > pos_x + KEY_RIGHT_MARGIN) - pos_x = cursor_x - KEY_RIGHT_MARGIN; - } - - if(pos_x < 0) - pos_x = 0; - if(pos_x > (level_width * 32) - 640) - pos_x = (level_width * 32) - 640; - - old_cursor_x = cursor_x; - - for (y = 0; y < 15; ++y) - for (x = 0; x < 21; ++x) - drawshape(x * 32, y * 32, tiles[y][x + (pos_x / 32)]); - - /* Draw the Bad guys: */ - for (i = 0; i < NUM_BAD_GUYS; ++i) - { -/* printf("\nbad_guys[%i].alive = %i", i, bad_guys[i].alive); */ - if(bad_guys[i].alive == NO) - continue; -/* to support frames: img_bsod_left[(frame / 5) % 4] */ - if(bad_guys[i].kind == BAD_BSOD) - drawimage(img_bsod_left[0], ((int)(bad_guys[i].x - pos_x)/32)*32, bad_guys[i].y, NO_UPDATE); - else if(bad_guys[i].kind == BAD_LAPTOP) - drawimage(img_laptop_left[0], ((int)(bad_guys[i].x - pos_x)/32)*32, bad_guys[i].y, NO_UPDATE); - else if (bad_guys[i].kind == BAD_MONEY) - drawimage(img_money_left[0], ((int)(bad_guys[i].x - pos_x)/32)*32, bad_guys[i].y, NO_UPDATE); - } - - - drawimage(selection, ((int)(cursor_x - pos_x)/32)*32, cursor_y, NO_UPDATE); - - sprintf(str, "%d", time_left); - drawtext("TIME", 324, 0, letters_blue, NO_UPDATE); - drawtext(str, 404, 0, letters_gold, NO_UPDATE); - - sprintf(str, "%s", levelname); - drawtext("NAME", 0, 0, letters_blue, NO_UPDATE); - drawtext(str, 80, 0, letters_gold, NO_UPDATE); - - drawtext("F1 for Help", 10, 430, letters_blue, NO_UPDATE); - - if(show_menu) - { - done = drawmenu(); - if(done) - return 0; - } - if(done == DONE_QUIT) - return 1; - - SDL_Delay(50); - SDL_Flip(screen); - } - -unloadlevelgfx(); -unloadshared(); - -SDL_FreeSurface(selection); - -/*if(done == DONE_SAVE)*/ /* let's save the changes */ -/* savelevel();*/ -/* -if(done == DONE_CHANGELEVEL) change level - return leveleditor(level); -*/ -return done; + char str[10]; + + + strcpy(levelfilename,"level1"); + + initmenu(); + menumenu = MENU_LEVELEDITOR; + show_menu = YES; + + loadshared(); + le_loadlevel(); + loadlevelgfx(); + + selection = load_image(DATA_PREFIX "/images/leveleditor/select.png", USE_ALPHA); + + int done; + done = 0; + + int x, y, i; /* for cicles */ + int pos_x, cursor_x, cursor_y, old_cursor_x, fire; + + pos_x = 0; + cursor_x = 3*32; + old_cursor_x = cursor_x; + cursor_y = 2*32; + fire = DOWN; + + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + + SDL_Event event; + SDLKey key; + SDLMod keymod; + + while(1) + { + SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, bkgd_red, bkgd_green, bkgd_blue)); + + keymod = SDL_GetModState(); + + while(SDL_PollEvent(&event)) + { + // testing SDL_KEYDOWN, SDL_KEYUP and SDL_QUIT events + switch(event.type) + { + case SDL_KEYDOWN: // key pressed + key = event.key.keysym.sym; + if(show_menu) + { + menu_event(key); + break; + } + switch(key) + { + case SDLK_LEFT: + if(fire == DOWN) + cursor_x -= KEY_CURSOR_SPEED; + else + cursor_x -= KEY_CURSOR_FASTSPEED; + + if(cursor_x < 0) + cursor_x = 0; + break; + case SDLK_RIGHT: + if(fire == DOWN) + cursor_x += KEY_CURSOR_SPEED; + else + cursor_x += KEY_CURSOR_FASTSPEED; + + if(cursor_x > (level_width*32) - 1) + cursor_x = (level_width*32) - 1; + break; + case SDLK_UP: + if(fire == DOWN) + cursor_y -= KEY_CURSOR_SPEED; + else + cursor_y -= KEY_CURSOR_FASTSPEED; + + if(cursor_y < 0) + cursor_y = 0; + break; + case SDLK_DOWN: + if(fire == DOWN) + cursor_y += KEY_CURSOR_SPEED; + else + cursor_y += KEY_CURSOR_FASTSPEED; + + if(cursor_y > 480-32) + cursor_y = 480-32; + break; + case SDLK_LCTRL: + fire = UP; + break; + case SDLK_F1: + showhelp(); + break; + case SDLK_HOME: + cursor_x = 0; + break; + case SDLK_END: + cursor_x = (level_width * 32) - 32; + break; + case SDLK_PERIOD: + le_change(cursor_x, cursor_y, 0, '.'); + break; + case SDLK_a: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, 'A'); + else + le_change(cursor_x, cursor_y, 0, 'a'); + break; + case SDLK_b: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, 'B'); + break; + case SDLK_c: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, 'C'); + else + le_change(cursor_x, cursor_y, 0, 'c'); + break; + case SDLK_d: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, 'D'); + else + le_change(cursor_x, cursor_y, 0, 'd'); + break; + case SDLK_e: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, 'E'); + else + le_change(cursor_x, cursor_y, 0, 'e'); + break; + case SDLK_f: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, 'F'); + else + le_change(cursor_x, cursor_y, 0, 'f'); + break; + case SDLK_g: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, 'G'); + else + le_change(cursor_x, cursor_y, 0, 'g'); + break; + case SDLK_h: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, 'H'); + else + le_change(cursor_x, cursor_y, 0, 'h'); + break; + case SDLK_i: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, 'I'); + else + le_change(cursor_x, cursor_y, 0, 'i'); + break; + case SDLK_j: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, 'J'); + else + le_change(cursor_x, cursor_y, 0, 'j'); + break; + case SDLK_x: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, 'X'); + else + le_change(cursor_x, cursor_y, 0, 'x'); + break; + case SDLK_y: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, 'Y'); + else + le_change(cursor_x, cursor_y, 0, 'y'); + break; + case SDLK_LEFTBRACKET: + le_change(cursor_x, cursor_y, 0, '['); + break; + case SDLK_RIGHTBRACKET: + le_change(cursor_x, cursor_y, 0, ']'); + break; + case SDLK_HASH: + case SDLK_3: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, '#'); + break; + case SDLK_DOLLAR: + case SDLK_4: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, '$'); + break; + case SDLK_BACKSLASH: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, '|'); + else + le_change(cursor_x, cursor_y, 0, '\\'); + break; + case SDLK_CARET: + le_change(cursor_x, cursor_y, 0, '^'); + break; + case SDLK_AMPERSAND: + case SDLK_6: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, '&'); + break; + case SDLK_EQUALS: + case SDLK_0: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, '='); + else /* let's add a bad guy */ + le_change(cursor_x, cursor_y, 0, '0'); + + for(i = 0; i < NUM_BAD_GUYS; ++i) + if (bad_guys[i].alive == NO) + { + bad_guys[i].alive = YES; + bad_guys[i].kind = BAD_BSOD; + bad_guys[i].x = (((int)cursor_x/32)*32); + bad_guys[i].y = (((int)cursor_y/32)*32); + i = NUM_BAD_GUYS; + } + break; + case SDLK_1: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, '!'); + else /* let's add a bad guy */ + le_change(cursor_x, cursor_y, 0, '1'); + + for(i = 0; i < NUM_BAD_GUYS; ++i) + if (bad_guys[i].alive == NO) + { + bad_guys[i].alive = YES; + bad_guys[i].kind = BAD_LAPTOP; + bad_guys[i].x = (((int)cursor_x/32)*32); + bad_guys[i].y = (((int)cursor_y/32)*32); + i = NUM_BAD_GUYS; + } + break; + case SDLK_2: + le_change(cursor_x, cursor_y, 0, '2'); + + for(i = 0; i < NUM_BAD_GUYS; ++i) + if (bad_guys[i].alive == NO) + { + bad_guys[i].alive = YES; + bad_guys[i].kind = BAD_MONEY; + bad_guys[i].x = (((int)cursor_x/32)*32); + bad_guys[i].y = (((int)cursor_y/32)*32); + i = NUM_BAD_GUYS; + } + break; + case SDLK_PLUS: + if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS) + le_change(cursor_x, cursor_y, 0, '*'); + break; + default: + break; + } + break; + case SDL_KEYUP: // key released + switch(event.key.keysym.sym) + { + case SDLK_LCTRL: + fire = DOWN; + break; + case SDLK_ESCAPE: + if(!show_menu) + show_menu = YES; + else + show_menu = NO; + break; + default: + break; + } + break; + case SDL_MOUSEBUTTONDOWN: + if(event.button.button == SDL_BUTTON_LEFT) + { + x = event.motion.x; + y = event.motion.y; + + cursor_x = ((int)(pos_x + x) / 32) * 32; + cursor_y = ((int) y / 32) * 32; + } + break; + case SDL_MOUSEMOTION: + x = event.motion.x; + y = event.motion.y; + + cursor_x = ((int)(pos_x + x) / 32) * 32; + cursor_y = ((int) y / 32) * 32; + break; + case SDL_QUIT: // window closed + done = DONE_QUIT; + break; + default: + break; + } + } + + /* mouse movements */ + x = event.motion.x; + if(x < MOUSE_LEFT_MARGIN) + pos_x -= MOUSE_POS_SPEED; + else if(x > MOUSE_RIGHT_MARGIN) + pos_x += MOUSE_POS_SPEED; + + if(old_cursor_x != cursor_x) + { + if(cursor_x < pos_x + KEY_LEFT_MARGIN) + pos_x = cursor_x - KEY_LEFT_MARGIN; + + if(cursor_x > pos_x + KEY_RIGHT_MARGIN) + pos_x = cursor_x - KEY_RIGHT_MARGIN; + } + + if(pos_x < 0) + pos_x = 0; + if(pos_x > (level_width * 32) - 640) + pos_x = (level_width * 32) - 640; + + old_cursor_x = cursor_x; + + for (y = 0; y < 15; ++y) + for (x = 0; x < 21; ++x) + drawshape(x * 32, y * 32, tiles[y][x + (pos_x / 32)]); + + /* Draw the Bad guys: */ + for (i = 0; i < NUM_BAD_GUYS; ++i) + { + /* printf("\nbad_guys[%i].alive = %i", i, bad_guys[i].alive); */ + if(bad_guys[i].alive == NO) + continue; + /* to support frames: img_bsod_left[(frame / 5) % 4] */ + if(bad_guys[i].kind == BAD_BSOD) + drawimage(img_bsod_left[0], ((int)(bad_guys[i].x - pos_x)/32)*32, bad_guys[i].y, NO_UPDATE); + else if(bad_guys[i].kind == BAD_LAPTOP) + drawimage(img_laptop_left[0], ((int)(bad_guys[i].x - pos_x)/32)*32, bad_guys[i].y, NO_UPDATE); + else if (bad_guys[i].kind == BAD_MONEY) + drawimage(img_money_left[0], ((int)(bad_guys[i].x - pos_x)/32)*32, bad_guys[i].y, NO_UPDATE); + } + + + drawimage(selection, ((int)(cursor_x - pos_x)/32)*32, cursor_y, NO_UPDATE); + + sprintf(str, "%d", time_left); + drawtext("TIME", 324, 0, letters_blue, NO_UPDATE, 1); + drawtext(str, 404, 0, letters_gold, NO_UPDATE, 1); + + sprintf(str, "%s", levelname); + drawtext("NAME", 0, 0, letters_blue, NO_UPDATE, 1); + drawtext(str, 80, 0, letters_gold, NO_UPDATE, 1); + + drawtext("F1 for Help", 10, 430, letters_blue, NO_UPDATE, 1); + + if(show_menu) + { + done = drawmenu(); + if(done) + return 0; + } + if(done == DONE_QUIT) + return 1; + + SDL_Delay(50); + SDL_Flip(screen); + } + + unloadlevelgfx(); + unloadshared(); + + SDL_FreeSurface(selection); + + /*if(done == DONE_SAVE)*/ /* let's save the changes */ + /* savelevel();*/ + /* + if(done == DONE_CHANGELEVEL) change level + return leveleditor(level); + */ + return done; } void le_change(int x, int y, int sx, unsigned char c) { -int xx, yy; + int xx, yy; -yy = (y / 32); -xx = ((x + sx) / 32); + yy = (y / 32); + xx = ((x + sx) / 32); -/* if there is a bad guy over there, remove it */ -int i; -for(i = 0; i < NUM_BAD_GUYS; ++i) - if (bad_guys[i].alive) - if(xx == bad_guys[i].x/32 && yy == bad_guys[i].y/32) - bad_guys[i].alive = NO; + /* if there is a bad guy over there, remove it */ + int i; + for(i = 0; i < NUM_BAD_GUYS; ++i) + if (bad_guys[i].alive) + if(xx == bad_guys[i].x/32 && yy == bad_guys[i].y/32) + bad_guys[i].alive = NO; -if (yy >= 0 && yy <= 15 && xx >= 0 && xx <= level_width) - tiles[yy][xx] = c; + if (yy >= 0 && yy <= 15 && xx >= 0 && xx <= level_width) + tiles[yy][xx] = c; } /* Save data for this level: */ void savelevel(void) { -FILE * fi; -char * filename; - -char str[80]; - -/* Save data file: */ - -filename = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + 20)); -sprintf(filename, "%s/levels/%s.dat", DATA_PREFIX, levelfilename); -fi = fopen(filename, "w"); -if (fi == NULL) - { - perror(filename); - st_shutdown(); - free(filename); - exit(-1); - } -free(filename); - - -/* sptrinf("# Level created by SuperTux built-in editor", fi); */ - -fputs(levelname, fi); -fputs("\n", fi); -fputs(leveltheme, fi); -fputs("\n", fi); -sprintf(str, "%d\n", time_left); /* time */ -fputs(str, fi); -fputs(song_title, fi); /* song filename */ -sprintf(str, "%d\n", bkgd_red); /* red background color */ -fputs(str, fi); -sprintf(str, "%d\n", bkgd_green); /* green background color */ -fputs(str, fi); -sprintf(str, "%d\n", bkgd_blue); /* blue background color */ -fputs(str, fi); -sprintf(str, "%d\n", level_width); /* level width */ -fputs(str, fi); - -int y; -for(y = 0; y < 15; ++y) - { - fputs(tiles[y], fi); - fputs("\n", fi); - } - -fclose(fi); - -drawcenteredtext("SAVED!", 240, letters_gold, NO_UPDATE); -SDL_Flip(screen); -SDL_Delay(1000); + FILE * fi; + char * filename; + + char str[80]; + + /* Save data file: */ + + filename = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + 20)); + sprintf(filename, "%s/levels/%s.dat", DATA_PREFIX, levelfilename); + fi = fopen(filename, "w"); + if (fi == NULL) + { + perror(filename); + st_shutdown(); + free(filename); + exit(-1); + } + free(filename); + + + /* sptrinf("# Level created by SuperTux built-in editor", fi); */ + + fputs(levelname, fi); + fputs("\n", fi); + fputs(leveltheme, fi); + fputs("\n", fi); + sprintf(str, "%d\n", time_left); /* time */ + fputs(str, fi); + fputs(song_title, fi); /* song filename */ + sprintf(str, "%d\n", bkgd_red); /* red background color */ + fputs(str, fi); + sprintf(str, "%d\n", bkgd_green); /* green background color */ + fputs(str, fi); + sprintf(str, "%d\n", bkgd_blue); /* blue background color */ + fputs(str, fi); + sprintf(str, "%d\n", level_width); /* level width */ + fputs(str, fi); + + int y; + for(y = 0; y < 15; ++y) + { + fputs(tiles[y], fi); + fputs("\n", fi); + } + + fclose(fi); + + drawcenteredtext("SAVED!", 240, letters_gold, NO_UPDATE, 1); + SDL_Flip(screen); + SDL_Delay(1000); } @@ -551,143 +551,143 @@ SDL_Delay(1000); void le_loadlevel(void) { -FILE * fi; -char * filename; + FILE * fi; + char * filename; -char str[80]; -char* line = malloc(sizeof(char)*10);/*[LEVEL_WIDTH + 5];*/ + char str[80]; + char* line = malloc(sizeof(char)*10);/*[LEVEL_WIDTH + 5];*/ -/* Load data file: */ + /* Load data file: */ -filename = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + 20)); -sprintf(filename, "%s/levels/%s.dat", DATA_PREFIX, levelfilename); -fi = fopen(filename, "r"); -if (fi == NULL) - { - perror(filename); - st_shutdown(); - free(filename); - exit(-1); - } -free(filename); + filename = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + 20)); + sprintf(filename, "%s/levels/%s.dat", DATA_PREFIX, levelfilename); + fi = fopen(filename, "r"); + if (fi == NULL) + { + perror(filename); + st_shutdown(); + free(filename); + exit(-1); + } + free(filename); -/* (Level title) */ -fgets(str, 20, fi); -strcpy(levelname, str); -levelname[strlen(levelname)-1] = '\0'; + /* (Level title) */ + fgets(str, 20, fi); + strcpy(levelname, str); + levelname[strlen(levelname)-1] = '\0'; -/* (Level theme) */ -fgets(str, 20, fi); -strcpy(leveltheme, str); -leveltheme[strlen(leveltheme)-1] = '\0'; + /* (Level theme) */ + fgets(str, 20, fi); + strcpy(leveltheme, str); + leveltheme[strlen(leveltheme)-1] = '\0'; -fgets(line, 10, fi); -time_left = atoi(line); -fgets(str, 60, fi); -song_title[0]='\0'; -strcpy(song_title,str); -fgets(line, 10, fi); -bkgd_red = atoi(line); -fgets(line, 10, fi); -bkgd_green= atoi(line); -fgets(line, 10, fi); -bkgd_blue = atoi(line); -fgets(line, 10, fi); -level_width = atoi(line); + fgets(line, 10, fi); + time_left = atoi(line); + fgets(str, 60, fi); + song_title[0]='\0'; + strcpy(song_title,str); + fgets(line, 10, fi); + bkgd_red = atoi(line); + fgets(line, 10, fi); + bkgd_green= atoi(line); + fgets(line, 10, fi); + bkgd_blue = atoi(line); + fgets(line, 10, fi); + level_width = atoi(line); -free(line); -line = malloc(level_width*sizeof(char)+5); + free(line); + line = malloc(level_width*sizeof(char)+5); -int x, y; -for (y = 0; y < 15; ++y) - { - fgets(line, level_width + 5, fi); - line[strlen(line) - 1] = '\0'; - free(tiles[y]); - tiles[y] = malloc((strlen(line)+5)*sizeof(char)); - strcpy(tiles[y], line); - } + int x, y; + for (y = 0; y < 15; ++y) + { + fgets(line, level_width + 5, fi); + line[strlen(line) - 1] = '\0'; + free(tiles[y]); + tiles[y] = malloc((strlen(line)+5)*sizeof(char)); + strcpy(tiles[y], line); + } -fclose(fi); + fclose(fi); -/* Activate bad guys: */ + /* Activate bad guys: */ -/* as oposed to the gameloop.c func, this one doesn't remove -the badguys from tiles */ + /* as oposed to the gameloop.c func, this one doesn't remove + the badguys from tiles */ -for (y = 0; y < 15; ++y) - for (x = 0; x < level_width; ++x) - if (tiles[y][x] >= '0' && tiles[y][x] <= '9') - add_bad_guy(x * 32, y * 32, tiles[y][x] - '0'); + for (y = 0; y < 15; ++y) + for (x = 0; x < level_width; ++x) + if (tiles[y][x] >= '0' && tiles[y][x] <= '9') + add_bad_guy(x * 32, y * 32, tiles[y][x] - '0'); -/* Set defaults: */ + /* Set defaults: */ -if(time_left == 0) - time_left = 255; + if(time_left == 0) + time_left = 255; -/* Level Intro: */ + /* Level Intro: */ -clearscreen(0, 0, 0); + clearscreen(0, 0, 0); -sprintf(str, "Editing Level %s", levelfilename); -drawcenteredtext(str, 200, letters_red, NO_UPDATE); + sprintf(str, "Editing Level %s", levelfilename); + drawcenteredtext(str, 200, letters_red, NO_UPDATE, 1); -sprintf(str, "%s", levelname); -drawcenteredtext(str, 224, letters_gold, NO_UPDATE); + sprintf(str, "%s", levelname); + drawcenteredtext(str, 224, letters_gold, NO_UPDATE, 1); -SDL_Flip(screen); + SDL_Flip(screen); -SDL_Delay(1000); + SDL_Delay(1000); } void showhelp() { -drawcenteredtext("- Help -", 30, letters_red, NO_UPDATE); -drawtext("Keys:", 80, 60, letters_gold, NO_UPDATE); - -char *text[] = { - "X/x - Brick0", - "Y/y - Brick1", - "A/B/! - Box full", - "a - Box empty", - "C-F - Cloud0", - "c-f - Cloud1", - "G-J - Bkgd0", - "g-j - Bkgd1", - "# - Solid0", - "[ - Solid1", - "= - Solid2", - "] - Solid3", - "$ - Distro", - "^ - Waves", - "* - Poletop", - "| - Pole", - "\\ - Flag", - "& - Water", - "0-2 - BadGuys", - "./Del - Remove tile", - "Esc - Menu"}; - -int i; -for(i = 0; i < sizeof(text)/sizeof(char *); i++) - drawtext(text[i], 40, 90+(i*16), letters_blue, NO_UPDATE); - -SDL_Flip(screen); - -int done; -done = 0; -SDL_Event event; - -while(done == 0) - while(SDL_PollEvent(&event)) - switch(event.type) - { - case SDL_KEYDOWN: // key pressed - done = 1; - break; - default: - break; - } + drawcenteredtext("- Help -", 30, letters_red, NO_UPDATE, 1); + drawtext("Keys:", 80, 60, letters_gold, NO_UPDATE, 1); + + char *text[] = { + "X/x - Brick0", + "Y/y - Brick1", + "A/B/! - Box full", + "a - Box empty", + "C-F - Cloud0", + "c-f - Cloud1", + "G-J - Bkgd0", + "g-j - Bkgd1", + "# - Solid0", + "[ - Solid1", + "= - Solid2", + "] - Solid3", + "$ - Distro", + "^ - Waves", + "* - Poletop", + "| - Pole", + "\\ - Flag", + "& - Water", + "0-2 - BadGuys", + "./Del - Remove tile", + "Esc - Menu"}; + + int i; + for(i = 0; i < sizeof(text)/sizeof(char *); i++) + drawtext(text[i], 40, 90+(i*16), letters_blue, NO_UPDATE, 1); + + SDL_Flip(screen); + + int done; + done = 0; + SDL_Event event; + + while(done == 0) + while(SDL_PollEvent(&event)) + switch(event.type) + { + case SDL_KEYDOWN: // key pressed + done = 1; + break; + default: + break; + } } diff --git a/src/menu.c b/src/menu.c index b2473acf4..09e242a81 100644 --- a/src/menu.c +++ b/src/menu.c @@ -7,7 +7,7 @@ tobi.web@gmx.de http://www.newbreedsoftware.com/supertux/ - December 20, 2003 + December 20, 2003 - December 29, 2003 */ #ifdef LINUX @@ -37,324 +37,350 @@ void initmenu(void) /* ---- Menu Options - Item Sound On/off ----*/ void menu_option_sound() { - if (audio_device == YES) { - if(menuitem == 1) { - if(use_sound == YES) { - drawshadedcenteredtext("Sound ON", 224, letters_red, NO_UPDATE); - } - else { - drawshadedcenteredtext("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) - drawshadedcenteredtext("Sound ON", 224, letters_blue, NO_UPDATE); + if (audio_device == YES) + { + if(menuitem == 1) + { + if(use_sound == YES) + { + drawcenteredtext("Sound ON", 224, letters_red, NO_UPDATE, 2); + } + else + { + drawcenteredtext("Sound OFF", 224, letters_red, NO_UPDATE, 2); + } + + if(menuaction == MN_HIT) + { /* Disable/Enable sound */ + if(use_sound == YES) + { + use_sound = NO; + } + else + { + use_sound = YES; + } + menu_change = YES; + } + } else - drawshadedcenteredtext("Sound OFF", 224, letters_blue, NO_UPDATE); - } - } - else { /* if audio_device != YES */ - /* let the user move over the deactivated option */ - if (menuitem == 1) { - drawshadedcenteredtext("Sound OFF", 224, letters_red, NO_UPDATE); + { + if(use_sound == YES) + drawcenteredtext("Sound ON", 224, letters_blue, NO_UPDATE, 2); + else + drawcenteredtext("Sound OFF", 224, letters_blue, NO_UPDATE, 2); + } } - else { - drawshadedcenteredtext("Sound OFF", 224, letters_black, 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, 2); + } + else + { + drawcenteredtext("Sound OFF", 224, letters_black, NO_UPDATE, 2); + } } - } } /* ---- Menu Options - Item Music On/off ----*/ void menu_option_music() { - if (audio_device == YES) { - if(menuitem == 2) { - if(use_music == YES) { - drawshadedcenteredtext("Music ON", 256, letters_red, NO_UPDATE); - } - else { - 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(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) { - drawshadedcenteredtext("Music ON", 256, letters_blue, NO_UPDATE); - } - else { - drawshadedcenteredtext("Music OFF", 256, letters_blue, NO_UPDATE); - } - } - } - else { /* if audio_device != YES */ - /* let the user move over the deactivated option */ - if (menuitem == 2) { - drawshadedcenteredtext("Music OFF", 256, letters_red, NO_UPDATE); - } - else { - drawshadedcenteredtext("Music OFF", 256, letters_black, NO_UPDATE); - } - } -} - -int menu_main(void) -{ - /* 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(menuitem == 0) + if (audio_device == YES) + { + if(menuitem == 2) + { + if(use_music == YES) { - 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; - show_menu = 0; - } + drawcenteredtext("Music ON", 256, letters_red, NO_UPDATE, 2); } else - drawshadedcenteredtext("Start 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; + drawcenteredtext("Music OFF", 256, letters_red, NO_UPDATE, 2); + } + 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, 2); + break; + case HERRING_MUSIC: + play_music(herring_song, 2); + 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 - drawshadedcenteredtext("Options", 224, letters_blue, NO_UPDATE); - - if(menuitem == 2) { - drawshadedcenteredtext("Level editor", 256, letters_red, NO_UPDATE); - if(menuaction == MN_HIT) /* Set variables, so that the level editor is executed */ + if(use_music == YES) { - level_editor_started = YES; - show_menu = 0; + drawcenteredtext("Music ON", 256, letters_blue, NO_UPDATE, 2); } - } - 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 */ + else { - return 1; + drawcenteredtext("Music OFF", 256, letters_blue, NO_UPDATE, 2); } } + } + else + { /* if audio_device != YES */ + /* let the user move over the deactivated option */ + if (menuitem == 2) + { + drawcenteredtext("Music OFF", 256, letters_red, NO_UPDATE, 2); + } else { - drawshadedcenteredtext("Quit", 288, letters_blue, NO_UPDATE); + drawcenteredtext("Music OFF", 256, letters_black, NO_UPDATE, 2); } - -return 0; + } } -int menu_game(void) +int menu_main(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 - drawshadedcenteredtext("Return To Game", 192, letters_blue, NO_UPDATE); + /* 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(menuitem == 0) + { + drawcenteredtext("Start Game", 192, letters_red, NO_UPDATE, 2); + if(menuaction == MN_HIT) /* we are ready to start the game, if this item got hit */ + { + game_started = 1; + show_menu = 0; + } + } + else + drawcenteredtext("Start Game", 192, letters_blue, NO_UPDATE, 2); - if(menuitem == 1) + if(menuitem == 1) + { + drawcenteredtext("Options", 224, letters_red, NO_UPDATE, 2); + if(menuaction == MN_HIT) /* Switch to the 'Options' menu */ { - drawshadedcenteredtext("Options", 224, letters_red, NO_UPDATE); - if(menuaction == MN_HIT) /* Switch to the 'Options' menu */ - { - menumenu = MENU_OPTIONS; - menu_change = YES; - } + menumenu = MENU_OPTIONS; + menu_change = YES; } - else - drawshadedcenteredtext("Options", 224, letters_blue, NO_UPDATE); + } + else + drawcenteredtext("Options", 224, letters_blue, NO_UPDATE, 2); - if(menuitem == 2) + if(menuitem == 2) + { + drawcenteredtext("Level editor", 256, letters_red, NO_UPDATE, 2); + if(menuaction == MN_HIT) /* Set variables, so that the level editor is executed */ { - drawshadedcenteredtext("Quit Game", 256, letters_red, NO_UPDATE); - if(menuaction == MN_HIT) /* Quit a running game */ - return 1; + level_editor_started = YES; + show_menu = 0; } - else + } + else + drawcenteredtext("Level editor", 256, letters_blue, NO_UPDATE, 2); + + if(menuitem == 3) + { + drawcenteredtext("Quit", 288, letters_red, NO_UPDATE, 2); + if(menuaction == MN_HIT) /* Quit a running game or the application */ { - drawshadedcenteredtext("Quit Game", 256, letters_blue, NO_UPDATE); + return 1; } + } + else + { + drawcenteredtext("Quit", 288, letters_blue, NO_UPDATE, 2); + } -return 0; + return 0; } -int menu_options(void) +int menu_game(void) { - if(menuitem > MENU_OPTIONS_ITEM_MAX ) - menuitem = 0; - else if(menuitem < 0) - menuitem = MENU_OPTIONS_ITEM_MAX; - - if(menuitem == 0) + /* 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) + { + drawcenteredtext("Return To Game", 192, letters_red, NO_UPDATE, 2); + 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, 2); + + if(menuitem == 1) + { + drawcenteredtext("Options", 224, letters_red, NO_UPDATE, 2); + if(menuaction == MN_HIT) /* Switch to the 'Options' menu */ { - if(use_fullscreen) - drawshadedcenteredtext("Fullscreen ON", 192, letters_red, NO_UPDATE); - else - drawshadedcenteredtext("Fullscreen OFF", 192, letters_red, NO_UPDATE); - if(menuaction == MN_HIT) /* Disable/Enable fullscreen */ - { - if(use_fullscreen) - use_fullscreen = 0; - else - use_fullscreen = 1; - st_video_setup(); - menu_change = YES; - } + menumenu = MENU_OPTIONS; + menu_change = YES; } + } + else + drawcenteredtext("Options", 224, letters_blue, NO_UPDATE, 2); + + if(menuitem == 2) + { + drawcenteredtext("Quit Game", 256, letters_red, NO_UPDATE, 2); + if(menuaction == MN_HIT) /* Quit a running game */ + return 1; + } + else + { + drawcenteredtext("Quit Game", 256, letters_blue, NO_UPDATE, 2); + } + + 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, 2); else + drawcenteredtext("Fullscreen OFF", 192, letters_red, NO_UPDATE, 2); + if(menuaction == MN_HIT) /* Disable/Enable fullscreen */ { if(use_fullscreen) - drawshadedcenteredtext("Fullscreen ON", 192, letters_blue, NO_UPDATE); + use_fullscreen = 0; else - drawshadedcenteredtext("Fullscreen OFF", 192, letters_blue, NO_UPDATE); - } + use_fullscreen = 1; + st_video_setup(); + menu_change = YES; + } + } + else + { + if(use_fullscreen) + drawcenteredtext("Fullscreen ON", 192, letters_blue, NO_UPDATE, 2); + else + drawcenteredtext("Fullscreen OFF", 192, letters_blue, NO_UPDATE, 2); + } - /* handle menu sound on/off option */ - menu_option_sound(); + /* handle menu sound on/off option */ + menu_option_sound(); - /* handle menu music on/off option */ - menu_option_music(); - - if(menuitem == 3) + /* handle menu music on/off option */ + menu_option_music(); + + if(menuitem == 3) + { + drawcenteredtext("Back", 288, letters_red, NO_UPDATE, 2); + if(menuaction == MN_HIT) /* Go back to main menu. */ { - 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; - } + if(game_started) + menumenu = MENU_GAME; + else + menumenu = MENU_MAIN; + menu_change = YES; } - else - drawshadedcenteredtext("Back", 288, letters_blue, NO_UPDATE); - -return 0; + } + else + drawcenteredtext("Back", 288, letters_blue, NO_UPDATE, 2); + + 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) + if(menuitem > MENU_LEVELEDITOR_ITEM_MAX ) + menuitem = 0; + else if(menuitem < 0) + menuitem = MENU_LEVELEDITOR_ITEM_MAX; + + if(menuitem == 0) + { + drawcenteredtext("Return To Level Editor", 192, letters_red, NO_UPDATE, 2); + if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */ + show_menu = 0; + } + else + drawcenteredtext("Return To Level Editor", 192, letters_blue, NO_UPDATE, 2); + + if(menuitem == 1) + { + drawcenteredtext("New Level", 224, letters_red, NO_UPDATE, 2); + if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */ { - drawshadedcenteredtext("Load Level", 256, letters_red, NO_UPDATE); - if(menuaction == MN_HIT) /* Quit a running game or the application */ - { - show_menu = 0; - selectlevel(); - } + show_menu = 0; + newlevel(); } - else - drawshadedcenteredtext("Load Level", 256, letters_blue, NO_UPDATE); - if(menuitem == 3) + } + else + drawcenteredtext("New Level", 224, letters_blue, NO_UPDATE, 2); + if(menuitem == 2) + { + drawcenteredtext("Load Level", 256, letters_red, NO_UPDATE, 2); + if(menuaction == MN_HIT) /* Create a new Level and load it into the level-editor. */ { - drawshadedcenteredtext("Save Level", 288, letters_red, NO_UPDATE); - if(menuaction == MN_HIT) /* Quit a running game or the application */ - { - show_menu = 0; - savelevel(); - } + show_menu = 0; + selectlevel(); } - else - drawshadedcenteredtext("Save Level", 288, letters_blue, NO_UPDATE); + } + else + drawcenteredtext("Load Level", 256, letters_blue, NO_UPDATE, 2); + if(menuitem == 3) + { + drawcenteredtext("Save Level", 288, letters_red, NO_UPDATE, 2); + if(menuaction == MN_HIT) /* Save the current level in the level-editor. */ + { + show_menu = 0; + savelevel(); + } + } + else + drawcenteredtext("Save Level", 288, letters_blue, NO_UPDATE, 2); - if(menuitem == 4) + if(menuitem == 4) + { + drawcenteredtext("Quit Level Editor", 320, letters_red, NO_UPDATE, 2); + if(menuaction == MN_HIT) /* Quit the level-editor. (to the main-menu) */ { - drawshadedcenteredtext("Quit Level Editor", 320, letters_red, NO_UPDATE); - if(menuaction == MN_HIT) /* Quit a running game or the application */ - { - return 1; - } + return 1; } - else - drawshadedcenteredtext("Quit Level Editor", 320, letters_blue, NO_UPDATE); + } + else + drawcenteredtext("Quit Level Editor", 320, letters_blue, NO_UPDATE, 2); -return 0; + return 0; } /* --- MENU --- */ @@ -369,7 +395,7 @@ int drawmenu(void) if(menuaction == MN_UP) { /* Go one menu-item up */ - --menuitem; + --menuitem; } else if(menuaction == MN_DOWN) ++menuitem; /* Go one menu-item down */ @@ -387,9 +413,9 @@ int drawmenu(void) { quit = menu_options(); } - else if(menumenu == MENU_LEVELEDITOR) + else if(menumenu == MENU_LEVELEDITOR) { - quit = menu_leveleditor(); + quit = menu_leveleditor(); } menuaction = -1; diff --git a/src/screen.c b/src/screen.c index 99a1acb58..aa20abdf6 100644 --- a/src/screen.c +++ b/src/screen.c @@ -122,23 +122,9 @@ 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 --- */ -void drawtext(char * text, int x, int y, SDL_Surface * surf, int update) +void drawtext(char * text, int x, int y, SDL_Surface * surf, int update, int shadowsize) { int i; char c; @@ -193,8 +179,8 @@ void drawtext(char * text, int x, int y, SDL_Surface * surf, int update) { /* Set destination rectangle for shadow: */ - dest.x = x + (i * 16) + 1; - dest.y = y + 1; + dest.x = x + (i * 16) + shadowsize; + dest.y = y + shadowsize; dest.w = src.w; dest.h = src.h; @@ -236,28 +222,21 @@ void drawtext(char * text, int x, int y, SDL_Surface * surf, int update) /* --- DRAW HORIZONTALLY-CENTERED TEXT: --- */ -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) +void drawcenteredtext(char * text, int y, SDL_Surface * surf, int update, int shadowsize) { - drawshadedtext(text, 320 - (strlen(text) * 8), y, surf, update); + drawtext(text, 320 - (strlen(text) * 8), y, surf, update, shadowsize); } /* --- ERASE TEXT: --- */ -void erasetext(char * text, int x, int y, SDL_Surface * surf, int update) +void erasetext(char * text, int x, int y, SDL_Surface * surf, int update, int shadowsize) { SDL_Rect dest; dest.x = x; dest.y = y; - dest.w = strlen(text) * 16 + 1; + dest.w = strlen(text) * 16 + shadowsize; dest.h = 17; if (dest.w > 640) @@ -272,7 +251,7 @@ void erasetext(char * text, int x, int y, SDL_Surface * surf, int update) /* --- ERASE CENTERED TEXT: --- */ -void erasecenteredtext(char * text, int y, SDL_Surface * surf, int update) +void erasecenteredtext(char * text, int y, SDL_Surface * surf, int update, int shadowsize) { - erasetext(text, 320 - (strlen(text) * 8), y, surf, update); + erasetext(text, 320 - (strlen(text) * 8), y, surf, update, shadowsize); } diff --git a/src/screen.h b/src/screen.h index 017d87705..ee319d2df 100644 --- a/src/screen.h +++ b/src/screen.h @@ -23,9 +23,7 @@ void updatescreen(void); 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); +void drawtext(char * text, int x, int y, SDL_Surface * surf, int update, int shadowsize); +void drawcenteredtext(char * text, int y, SDL_Surface * surf, int update, int shadowsize); +void erasetext(char * text, int x, int y, SDL_Surface * surf, int update, int shadowsize); +void erasecenteredtext(char * text, int y, SDL_Surface * surf, int update, int shadowsize); diff --git a/src/title.c b/src/title.c index db99b5ce0..2fc933dee 100644 --- a/src/title.c +++ b/src/title.c @@ -7,7 +7,7 @@ bill@newbreedsoftware.com http://www.newbreedsoftware.com/supertux/ - April 11, 2000 - December 9, 2003 + April 11, 2000 - December 29, 2003 */ #include @@ -76,7 +76,7 @@ int title(void) /* Draw the high score: */ last_highscore = load_hs(); sprintf(str, "High score: %d", last_highscore); - drawcenteredtext(str, 460, letters_red, NO_UPDATE); + drawcenteredtext(str, 460, letters_red, NO_UPDATE, 1); while (!done && !quit) { @@ -99,9 +99,9 @@ int title(void) key = event.key.keysym.sym; - /* Check for menu events */ + /* Check for menu events */ menu_event(key); - + if (key == SDLK_ESCAPE) { /* Escape: Quit: */ @@ -136,7 +136,7 @@ int title(void) /* Draw the high score: */ sprintf(str, "High score: %d", last_highscore); - drawcenteredtext(str, 460, letters_red, NO_UPDATE); + drawcenteredtext(str, 460, letters_red, NO_UPDATE, 1); } /* Don't draw menu, if quit is true */ @@ -158,7 +158,7 @@ int title(void) drawimage(anim2, 560, 270, NO_UPDATE); - SDL_Flip(screen); + SDL_Flip(screen); /* Pause: */ -- 2.11.0