From 05a38383bb378e05aadad886e87f0fe64fdc6ba0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Gl=C3=A4=C3=9Fer?= Date: Sun, 1 Feb 2004 22:29:36 +0000 Subject: [PATCH] Yet another huge code merge representing the current status of my rewrite. It includes several patches from the mailing list. SVN-Revision: 108 --- src/badguy.c | 13 +- src/defines.h | 10 +- src/gameloop.c | 173 ++++--- src/globals.h | 3 +- src/high_scores.c | 62 ++- src/high_scores.h | 5 +- src/intro.c | 20 +- src/level.c | 55 ++- src/level.h | 4 +- src/leveleditor.c | 25 +- src/menu.c | 266 ++++++----- src/menu.h | 9 +- src/player.c | 1321 ++++++++++++++++++++++++++--------------------------- src/player.h | 1 + src/scene.h | 6 +- src/screen.c | 150 +----- src/screen.h | 12 +- src/setup.c | 45 +- src/special.c | 16 +- src/special.h | 1 + src/texture.c | 323 ++++++++----- src/texture.h | 9 +- src/timer.c | 33 +- src/timer.h | 22 + src/title.c | 23 +- src/type.c | 8 +- src/type.h | 3 +- src/world.c | 23 +- 28 files changed, 1387 insertions(+), 1254 deletions(-) diff --git a/src/badguy.c b/src/badguy.c index 07b2ba258..71dcda6a5 100644 --- a/src/badguy.c +++ b/src/badguy.c @@ -4,7 +4,7 @@ // Description: // // -// Author: Tobias Glaesser , (C) 2004 +// Author: Tobias Glaesser & Bill Kendrick, (C) 2004 // // Copyright: See COPYING file that comes with this distribution // @@ -23,7 +23,6 @@ void badguy_create_bitmasks() void badguy_init(bad_guy_type* pbad, float x, float y, int kind) { - pbad->base.updated = SDL_GetTicks(); pbad->base.width = 32; pbad->base.height = 32; pbad->base.alive = YES; @@ -33,7 +32,7 @@ void badguy_init(bad_guy_type* pbad, float x, float y, int kind) pbad->base.x = x; pbad->base.y = y; pbad->base.xm = 1.3; - pbad->base.ym = 1.5; + pbad->base.ym = 4.8; pbad->dir = LEFT; pbad->seen = NO; timer_init(&pbad->timer); @@ -42,8 +41,6 @@ void badguy_init(bad_guy_type* pbad, float x, float y, int kind) void badguy_action(bad_guy_type* pbad) { - double frame_ratio = get_frame_ratio(&pbad->base); - if (pbad->base.alive) { if (pbad->seen) @@ -214,7 +211,7 @@ void badguy_action(bad_guy_type* pbad) /* Move vertically: */ - pbad->base.y = pbad->base.y + pbad->base.ym *frame_ratio; + pbad->base.y = pbad->base.y + pbad->base.ym * frame_ratio; /* Fall if we get off the ground: */ @@ -225,7 +222,7 @@ void badguy_action(bad_guy_type* pbad) { if (pbad->base.ym < MAX_YM) { - pbad->base.ym = pbad->base.ym + GRAVITY; + pbad->base.ym = pbad->base.ym + GRAVITY * frame_ratio; } } else @@ -240,7 +237,7 @@ void badguy_action(bad_guy_type* pbad) } } else - pbad->base.ym = pbad->base.ym + GRAVITY; + pbad->base.ym = pbad->base.ym + GRAVITY * frame_ratio; if (pbad->base.y > screen->h) pbad->base.alive = NO; diff --git a/src/defines.h b/src/defines.h index b2d16f1fa..19956de3f 100644 --- a/src/defines.h +++ b/src/defines.h @@ -7,7 +7,7 @@ bill@newbreedsoftware.com http://www.newbreedsoftware.com/supertux/ - April 11, 2000 - December 28, 2003 + April 11, 2000 - February 1, 2004 */ @@ -67,16 +67,16 @@ #define MAX_WALK_XM 2.3 #define MAX_RUN_XM 3.2 -#define MAX_YM 10.0 -#define MAX_JUMP_TIME 1000 +#define MAX_YM 20.0 +#define MAX_JUMP_TIME 375 #define MAX_LIVES 4.0 #define WALK_SPEED 1.0 #define RUN_SPEED 1.5 -#define JUMP_SPEED 1.5 +#define JUMP_SPEED 1.2 #define GRAVITY 1.0 -#define YM_FOR_JUMP 50.0 +#define YM_FOR_JUMP 6.0 #define KILL_BOUNCE_YM 8.0 #define SKID_XM 2.0 diff --git a/src/gameloop.c b/src/gameloop.c index 558e2d6f0..b1b550e12 100644 --- a/src/gameloop.c +++ b/src/gameloop.c @@ -3,11 +3,11 @@ Super Tux - Game Loop! - by Bill Kendrick + by Bill Kendrick & Tobias Glaesser bill@newbreedsoftware.com http://www.newbreedsoftware.com/supertux/ - April 11, 2000 - January 1st, 2004 + April 11, 2000 - February 1st, 2004 */ #include @@ -51,7 +51,6 @@ SDL_Event event; SDLKey key; char level_subset[100]; char str[60]; -timer_type time_left; float fps_fps; /* Local function prototypes: */ @@ -73,13 +72,13 @@ void levelintro(void) clearscreen(0, 0, 0); sprintf(str, "LEVEL %d", level); - drawcenteredtext(str, 200, letters_red, NO_UPDATE, 1); + text_drawf(&red_text, str, 0, 200, A_HMIDDLE, A_TOP, 1, NO_UPDATE); sprintf(str, "%s", current_level.name); - drawcenteredtext(str, 224, letters_gold, NO_UPDATE, 1); + text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1, NO_UPDATE); sprintf(str, "TUX x %d", tux.lives); - drawcenteredtext(str, 256, letters_blue, NO_UPDATE, 1); + text_drawf(&blue_text, str, 0, 256, A_HMIDDLE, A_TOP, 1, NO_UPDATE); flipscreen(); @@ -90,6 +89,8 @@ void levelintro(void) void start_timers(void) { timer_start(&time_left,current_level.time_left*1000); + st_pause_ticks_init(); + update_time = st_get_ticks(); } void activate_bad_guys(void) @@ -128,20 +129,26 @@ void game_event(void) /* Check for menu-events, if the menu is shown */ if(show_menu) - menu_event(key); + menu_event(&event.key.keysym); + + if(player_keydown_event(&tux,key)) + break; - if(player_keydown_event(&tux,key)) - break; - switch(key) { case SDLK_ESCAPE: /* Escape: Open/Close the menu: */ if(!game_pause) { if(show_menu) + { show_menu = 0; + st_pause_ticks_stop(); + } else + { show_menu = 1; + st_pause_ticks_start(); + } } break; default: @@ -150,19 +157,25 @@ void game_event(void) break; case SDL_KEYUP: /* A keyrelease! */ key = event.key.keysym.sym; - - if(player_keyup_event(&tux,key)) - break; - + + if(player_keyup_event(&tux,key)) + break; + switch(key) { case SDLK_p: if(!show_menu) { if(game_pause) + { game_pause = 0; + st_pause_ticks_stop(); + } else + { game_pause = 1; + st_pause_ticks_start(); + } } break; case SDLK_TAB: @@ -185,6 +198,14 @@ void game_event(void) if(debug_mode == YES) timer_start(&tux.invincible_timer,TUX_INVINCIBLE_TIME); break; + case SDLK_l: + if(debug_mode == YES) + --tux.lives; + break; + case SDLK_s: + if(debug_mode == YES) + score += 1000; + break; default: break; } @@ -195,7 +216,6 @@ void game_event(void) switch(event.jaxis.axis) { case JOY_X: - printf("X: %d\n", event.jaxis.value); if (event.jaxis.value < -1024) tux.input.left = DOWN; else if (event.jaxis.value > 1024) @@ -272,7 +292,7 @@ int game_action(void) level++; next_level = 0; drawresultscreen(); - player_level_begin(&tux); + player_level_begin(&tux); } else { @@ -285,7 +305,7 @@ int game_action(void) { drawendscreen(); - if (score > highscore) + if (score > hs_score) save_hs(score); unloadlevelgfx(); unloadlevelsong(); @@ -386,20 +406,29 @@ int game_action(void) /* --- GAME DRAW! --- */ -void game_draw() +void game_draw(void) { - int x, y, i; + int x, y, i, s; /* Draw screen: */ if (tux.dying && (frame % 4) == 0) clearscreen(255, 255, 255); + else if(timer_check(&super_bkgd_timer)) + texture_draw(&img_super_bkgd, 0, 0, NO_UPDATE); else { - if (timer_check(&super_bkgd_timer)) - texture_draw(&img_super_bkgd, 0, 0, NO_UPDATE); + /* Draw the real background */ + if(current_level.bkgd_image[0] != '\0') + { + s = scroll_x / 30; + texture_draw_part(&img_bkgd,s,0,0,0,img_bkgd.w - s, img_bkgd.h, NO_UPDATE); + texture_draw_part(&img_bkgd,0,0,screen->w - s ,0,s,img_bkgd.h, NO_UPDATE); + } else - clearscreen(current_level.bkgd_red, current_level.bkgd_green, current_level.bkgd_blue); + { + clearscreen(current_level.bkgd_red, current_level.bkgd_green, current_level.bkgd_blue); + } } /* Draw background: */ @@ -475,7 +504,7 @@ void game_draw() if(game_pause) - drawcenteredtext("PAUSE",230,letters_red, NO_UPDATE, 1); + text_drawf(&red_text, "PAUSE", 0, 230, A_HMIDDLE, A_TOP, 1, NO_UPDATE); if(show_menu) done = drawmenu(); @@ -493,7 +522,7 @@ int gameloop(void) { /*Uint32 last_time, now_time*/ - int fps_cnt; + int fps_cnt, jump; timer_type fps_timer, frame_timer; /* Clear screen: */ @@ -515,7 +544,7 @@ int gameloop(void) loadlevelgfx(¤t_level); activate_bad_guys(); loadlevelsong(); - highscore = load_hs(); + load_hs(); player_init(&tux); @@ -524,6 +553,7 @@ int gameloop(void) /* --- MAIN GAME LOOP!!! --- */ + jump = NO; done = 0; quit = 0; frame = 0; @@ -535,18 +565,28 @@ int gameloop(void) game_draw(); do { - /*last_time = SDL_GetTicks();*/ + jump = NO; + + /* Set the time the last update and the time of the current update */ + last_update_time = update_time; + update_time = st_get_ticks(); + + /* Calculate the movement-factor */ + frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE); + if(!timer_check(&frame_timer)) - { - timer_start(&frame_timer,25); - ++frame; - } + { + timer_start(&frame_timer,25); + ++frame; + } /* Handle events: */ tux.input.old_fire = tux.input.fire; + printf("%lf\n",frame_ratio); + game_event(); @@ -563,8 +603,18 @@ int gameloop(void) } else SDL_Delay(50); - + + if(tux.input.down == DOWN) + SDL_Delay(30); + /*Draw the current scene to the screen */ + /*If the machine running the game is too slow + skip the drawing of the frame (so the calculations are more precise and + the FPS aren't affected).*/ + /*if( ! fps_fps < 50.0 ) + game_draw(); + else + jump = YES;*/ /*FIXME: Implement this tweak right.*/ game_draw(); /* Time stops in pause mode */ @@ -573,15 +623,12 @@ int gameloop(void) continue; } - /* Pause til next frame: */ + /* Pause till next frame, if the machine running the game is too fast: */ + /* FIXME: Works great for in OpenGl mode, where the CPU doesn't have to do that much. But + the results in SDL mode aren't perfect (thought the 100 FPS are reached), even on an AMD2500+. */ + if(last_update_time >= update_time - 12 && jump != YES ) + SDL_Delay(10); - /*now_time = SDL_GetTicks(); - if (now_time < last_time + FPS) - SDL_Delay(last_time + FPS - now_time);*/ - /*printf("%d",timer_get_left(&frame_timer));*/ - /*SDL_Delay(timer_get_left(&frame_timer) );*/ - SDL_Delay(10); - /* Handle time: */ @@ -615,8 +662,8 @@ int gameloop(void) /* Calculate frames per second */ if(show_fps) { - fps_fps = ((float)1000 / (float)timer_get_gone(&fps_timer)) * (float)fps_cnt; - ++fps_cnt; + ++fps_cnt; + fps_fps = (1000.0 / (float)timer_get_gone(&fps_timer)) * (float)fps_cnt; if(!timer_check(&fps_timer)) { @@ -1189,9 +1236,9 @@ void drawshape(float x, float y, unsigned char c) else if (c >= 'c' && c <= 'f') texture_draw(&img_cloud[1][c - 'c'], x, y, NO_UPDATE); else if (c >= 'G' && c <= 'J') - texture_draw(&img_bkgd[0][c - 'G'], x, y, NO_UPDATE); + texture_draw(&img_bkgd_tile[0][c - 'G'], x, y, NO_UPDATE); else if (c >= 'g' && c <= 'j') - texture_draw(&img_bkgd[1][c - 'g'], x, y, NO_UPDATE); + texture_draw(&img_bkgd_tile[1][c - 'g'], x, y, NO_UPDATE); else if (c == '#') texture_draw(&img_solid[0], x, y, NO_UPDATE); else if (c == '[') @@ -1515,33 +1562,31 @@ void drawstatus(void) int i; sprintf(str, "%d", score); - 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, 1); - drawtext(str, 96, 20, letters_gold, NO_UPDATE, 1); + text_draw(&blue_text, "SCORE", 0, 0, 1, NO_UPDATE); + text_draw(&gold_text, str, 96, 0, 1, NO_UPDATE); + sprintf(str, "%d", hs_score); + text_draw(&blue_text, "HIGH", 0, 20, 1, NO_UPDATE); + text_draw(&gold_text, str, 96, 20, 1, NO_UPDATE); + if (timer_get_left(&time_left) > TIME_WARNING || (frame % 10) < 5) { sprintf(str, "%d", timer_get_left(&time_left) / 1000 ); - drawtext("TIME", 224, 0, letters_blue, NO_UPDATE, 1); - drawtext(str, 304, 0, letters_gold, NO_UPDATE, 1); + text_draw(&blue_text, "TIME", 224, 0, 1, NO_UPDATE); + text_draw(&gold_text, str, 304, 0, 1, NO_UPDATE); } sprintf(str, "%d", distros); - drawtext("DISTROS", screen->h, 0, letters_blue, NO_UPDATE, 1); - drawtext(str, 608, 0, letters_gold, NO_UPDATE, 1); + text_draw(&blue_text, "DISTROS", screen->h, 0, 1, NO_UPDATE); + text_draw(&gold_text, str, 608, 0, 1, NO_UPDATE); - drawtext("LIVES", screen->h, 20, letters_blue, NO_UPDATE, 1); + text_draw(&blue_text, "LIVES", screen->h, 20, 1, NO_UPDATE); if(show_fps) { - drawtext("FPS", screen->h, 40, letters_blue, NO_UPDATE, 1); sprintf(str, "%f", fps_fps); - if(use_gl) /* FIXME: We need this check as text doesn't work in OpenGl mode. */ - printf("%f\n",fps_fps); - drawtext(str, screen->h + 60, 40, letters_gold, NO_UPDATE, 1); + text_draw(&blue_text, "FPS", screen->h, 40, 1, NO_UPDATE); + text_draw(&blue_text, str, screen->h + 60, 40, 1, NO_UPDATE); } for(i=0; i < tux.lives; ++i) @@ -1557,13 +1602,13 @@ void drawendscreen(void) clearscreen(0, 0, 0); - drawcenteredtext("GAMEOVER", 200, letters_red, NO_UPDATE, 1); + text_drawf(&blue_text, "GAMEOVER", 0, 200, A_HMIDDLE, A_TOP, 1, NO_UPDATE); sprintf(str, "SCORE: %d", score); - drawcenteredtext(str, 224, letters_gold, NO_UPDATE, 1); + text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1, NO_UPDATE); sprintf(str, "DISTROS: %d", distros); - drawcenteredtext(str, 256, letters_blue, NO_UPDATE, 1); + text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1, NO_UPDATE); flipscreen(); SDL_Delay(2000); @@ -1575,13 +1620,13 @@ void drawresultscreen(void) clearscreen(0, 0, 0); - drawcenteredtext("Result:", 200, letters_red, NO_UPDATE, 1); + text_drawf(&red_text, "Result:", 0, 200, A_HMIDDLE, A_TOP, 1, NO_UPDATE); sprintf(str, "SCORE: %d", score); - drawcenteredtext(str, 224, letters_gold, NO_UPDATE, 1); + text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1, NO_UPDATE); sprintf(str, "DISTROS: %d", distros); - drawcenteredtext(str, 256, letters_blue, NO_UPDATE, 1); + text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1, NO_UPDATE); flipscreen(); SDL_Delay(2000); diff --git a/src/globals.h b/src/globals.h index b1ef329de..65f9c221b 100644 --- a/src/globals.h +++ b/src/globals.h @@ -15,9 +15,10 @@ #define SUPERTUX_GLOBALS_H #include +#include "text.h" SDL_Surface * screen; -SDL_Surface * letters_black, * letters_gold, * letters_blue, * letters_red; +text_type black_text, gold_text, blue_text, red_text; int use_gl, use_joystick, use_fullscreen, debug_mode, show_fps; diff --git a/src/high_scores.c b/src/high_scores.c index d84dcabf6..98620008a 100644 --- a/src/high_scores.c +++ b/src/high_scores.c @@ -12,6 +12,9 @@ #include "globals.h" #include "high_scores.h" +#include "menu.h" +#include "screen.h" +#include "texture.h" FILE * opendata(char * mode) { @@ -24,13 +27,15 @@ FILE * opendata(char * mode) strcpy(filename, st_dir); /* Open the high score file: */ - + #ifdef LINUX + strcat(filename, "/highscore"); #else #ifdef WIN32 - strcat(filename, "/st_highscore.dat"); - #endif + + strcat(filename, "/st_highscore.dat"); +#endif #endif @@ -38,7 +43,7 @@ FILE * opendata(char * mode) fi = fopen(filename, mode); free( filename ); - + if (fi == NULL) { fprintf(stderr, "Warning: I could not open the high score file "); @@ -55,12 +60,15 @@ FILE * opendata(char * mode) /* Load data from high score file: */ -int load_hs(void) +void load_hs(void) { FILE * fi; char temp[128]; - int score = 100; - + hs_score = 100; + int c, strl; + strcpy(hs_name, "Grandma"); + c = 0; + /* Try to open file: */ fi = opendata("r"); @@ -79,10 +87,18 @@ int load_hs(void) if (strstr(temp, "highscore=") == temp) { - score = atoi(temp + 10); + hs_score = atoi(temp + 10); - if (score == 0) - score = 100; + if (hs_score == 0) + hs_score = 100; + } + if (strstr(temp, "name=") == temp) + { + fprintf(stderr, "name found\n"); + strl = strlen("name="); + hs_name[strl-1]='\0'; + for(c = strl; c < strlen(temp); c++) + hs_name[c-strl] = temp[c]; } } } @@ -90,13 +106,32 @@ int load_hs(void) fclose(fi); } - return score; } void save_hs(int score) { - FILE * fi; + texture_type bkgd; + texture_load(&bkgd, DATA_PREFIX "/images/highscore/highscore.png", IGNORE_ALPHA); + + hs_score = score; + + /* ask for player's name */ + menumenu = MENU_HIGHSCORE; + show_menu = 1; + SDL_Event event; + while(show_menu) + { + texture_draw_bg(&bkgd, NO_UPDATE); + drawmenu(); + flipscreen(); + while(SDL_PollEvent(&event)) + if(event.type == SDL_KEYDOWN) + menu_event(&event.key.keysym); + } + + + FILE * fi; /* Try to open file: */ @@ -105,7 +140,8 @@ void save_hs(int score) { fprintf(fi, "# Supertux highscore file\n\n"); - fprintf(fi, "highscore=%d\n", score); + fprintf(fi, "name=%s\n", hs_name); + fprintf(fi, "highscore=%d\n", hs_score); fprintf(fi, "# (File automatically created.)\n"); diff --git a/src/high_scores.h b/src/high_scores.h index 1e7421f4a..0b8d91ad3 100644 --- a/src/high_scores.h +++ b/src/high_scores.h @@ -7,6 +7,9 @@ # include +int hs_score; +char hs_name[62]; /* highscores global variables*/ + void save_hs(int score); -int load_hs(); +void load_hs(); FILE * opendata(char * mode); diff --git a/src/intro.c b/src/intro.c index f5ddc35a7..a8ccb237f 100644 --- a/src/intro.c +++ b/src/intro.c @@ -7,7 +7,7 @@ bill@newbreedsoftware.com http://www.newbreedsoftware.com/supertux/ - April 11, 2000 - April 23, 2000 + April 11, 2000 - February 1st, 2004 */ #include @@ -137,7 +137,7 @@ int intro(void) texture_draw(&tux_sit, 270, 400, UPDATE); texture_draw(&gown_sit, 320, 400, UPDATE); - drawcenteredtext(intro_text[0], 456, letters_blue, UPDATE, 1); + text_drawf(&blue_text, intro_text[0], 0, -8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE); } @@ -147,14 +147,14 @@ int intro(void) /* Helicopter begins to fly in: */ erasecenteredtext(intro_text[0], 456, bkgd.sdl_surface, NO_UPDATE, 1); - drawcenteredtext(intro_text[1], 456, letters_red, NO_UPDATE, 1); + text_drawf(&blue_text, intro_text[1], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE); } if (timer_get_gone(&timer) >= 2000 && timer_get_gone(&timer) < 4000) { /* Helicopter flying in: */ - texture_draw_part(&bkgd, 0, 32, screen->w, (copter[0].h), NO_UPDATE); + texture_draw_part(&bkgd,0,32, 0, 32, screen->w, (copter[0].h), NO_UPDATE); texture_draw(&copter[i % 2], (float)(timer_get_gone(&timer) - 2000) / 5 - (copter[0].w), 32, @@ -185,7 +185,7 @@ int intro(void) if (timer_get_gone(&timer) >= 4000 && timer_get_gone(&timer) < 8000) { /* Helicopter sits: */ - texture_draw_part(&bkgd, 0, 32, screen->w, (copter[0].h), NO_UPDATE); + texture_draw_part(&bkgd,0,32, 0, 32, screen->w, (copter[0].h), NO_UPDATE); texture_draw(&copter[i % 2], 400 - (copter[0].w), 32, NO_UPDATE); update_rect(screen, 0, 32, screen->w, (copter[0].h)); @@ -201,7 +201,7 @@ int intro(void) erasecenteredtext(intro_text[1], 456, bkgd.sdl_surface, UPDATE, 1); - drawcenteredtext(intro_text[2], 456, letters_red, UPDATE, 1); + text_drawf(&blue_text, intro_text[2], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE); } @@ -210,7 +210,7 @@ int intro(void) /* Beam gown up! */ texture_draw_part(&bkgd, - 320, + 320, 32 + (copter[0].h), 320, 32 + (copter[0].h), (gown_upset.w), 368 + (gown_upset.h) - (copter[0].h), NO_UPDATE); @@ -255,7 +255,7 @@ int intro(void) texture_draw(&tux_mad, 270, 400, UPDATE); erasecenteredtext(intro_text[2], 456, bkgd.sdl_surface, UPDATE, 1); - drawcenteredtext(intro_text[3], 456, letters_gold, UPDATE, 1); + text_drawf(&blue_text, intro_text[3], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE); } @@ -263,7 +263,7 @@ int intro(void) { /* Helicopter starting to speed off: */ - texture_draw_part(&bkgd, 0, 32, screen->w, (copter_squish.h), NO_UPDATE); + texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_squish.h), NO_UPDATE); texture_draw(&copter_squish, 400 - (copter[0].w), 32, @@ -277,7 +277,7 @@ int intro(void) { /* Helicopter speeding off: */ - texture_draw_part(&bkgd, 0, 32, screen->w, (copter_stretch.h), NO_UPDATE); + texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_stretch.h), NO_UPDATE); texture_draw(&copter_stretch, (timer_get_gone(&timer) - 8250) /*(i - (8250 / FPS)) * 30*/ + 400 - (copter[0].w), diff --git a/src/level.c b/src/level.c index ccc3cc559..50aa6b6a8 100644 --- a/src/level.c +++ b/src/level.c @@ -67,7 +67,10 @@ void loadlevel(st_level* plevel, char *subset, int level) strcpy(plevel->song_title, str); plevel->song_title[strlen(plevel->song_title)-1] = '\0'; - + /* (Level background image) */ + fgets(str, sizeof(plevel->bkgd_image), fi); + strcpy(plevel->bkgd_image, str); + plevel->bkgd_image[strlen(plevel->bkgd_image)-1] = '\0'; /* (Level background color) */ fgets(str, 10, fi); @@ -113,6 +116,17 @@ void loadlevel(st_level* plevel, char *subset, int level) } +/* Unload data for this level: */ + +void unloadlevel(st_level* plevel) +{ + free(plevel->tiles); + plevel->name[0] = '\0'; + plevel->theme[0] = '\0'; + plevel->song_title[0] = '\0'; + plevel->bkgd_image[0] = '\0'; +} + /* Load graphics: */ void loadlevelgfx(st_level *plevel) @@ -125,16 +139,26 @@ void loadlevelgfx(st_level *plevel) load_level_image(&img_solid[1],plevel->theme,"solid1.png", USE_ALPHA); load_level_image(&img_solid[2],plevel->theme,"solid2.png", USE_ALPHA); load_level_image(&img_solid[3],plevel->theme,"solid3.png", USE_ALPHA); - - load_level_image(&img_bkgd[0][0],plevel->theme,"bkgd-00.png", USE_ALPHA); - load_level_image(&img_bkgd[0][1],plevel->theme,"bkgd-01.png", USE_ALPHA); - load_level_image(&img_bkgd[0][2],plevel->theme,"bkgd-02.png", USE_ALPHA); - load_level_image(&img_bkgd[0][3],plevel->theme,"bkgd-03.png", USE_ALPHA); - - load_level_image(&img_bkgd[1][0],plevel->theme,"bkgd-10.png", USE_ALPHA); - load_level_image(&img_bkgd[1][1],plevel->theme,"bkgd-11.png", USE_ALPHA); - load_level_image(&img_bkgd[1][2],plevel->theme,"bkgd-12.png", USE_ALPHA); - load_level_image(&img_bkgd[1][3],plevel->theme,"bkgd-13.png", USE_ALPHA); + + load_level_image(&img_bkgd_tile[0][0],plevel->theme,"bkgd-00.png", USE_ALPHA); + load_level_image(&img_bkgd_tile[0][1],plevel->theme,"bkgd-01.png", USE_ALPHA); + load_level_image(&img_bkgd_tile[0][2],plevel->theme,"bkgd-02.png", USE_ALPHA); + load_level_image(&img_bkgd_tile[0][3],plevel->theme,"bkgd-03.png", USE_ALPHA); + + load_level_image(&img_bkgd_tile[1][0],plevel->theme,"bkgd-10.png", USE_ALPHA); + load_level_image(&img_bkgd_tile[1][1],plevel->theme,"bkgd-11.png", USE_ALPHA); + load_level_image(&img_bkgd_tile[1][2],plevel->theme,"bkgd-12.png", USE_ALPHA); + load_level_image(&img_bkgd_tile[1][3],plevel->theme,"bkgd-13.png", USE_ALPHA); + + if(strcmp(plevel->bkgd_image,"") != 0) + { + char fname[1024]; + snprintf(fname, 1024, "%s/background/%s", st_dir, plevel->bkgd_image); + if(!faccessible(fname)) + snprintf(fname, 1024, "%s/images/background/%s", DATA_PREFIX, plevel->bkgd_image); + texture_load(&img_bkgd, fname, IGNORE_ALPHA); + printf("%s",fname); + } } /* Free graphics data for this level: */ @@ -150,9 +174,10 @@ void unloadlevelgfx(void) for (i = 0; i < 4; i++) { texture_free(&img_solid[i]); - texture_free(&img_bkgd[0][i]); - texture_free(&img_bkgd[1][i]); + texture_free(&img_bkgd_tile[0][i]); + texture_free(&img_bkgd_tile[1][i]); } + texture_free(&img_bkgd); } /* Load a level-specific graphic... */ @@ -163,8 +188,8 @@ void load_level_image(texture_type* ptexture, char* theme, char * file, int use_ snprintf(fname, 1024, "%s/themes/%s/%s", st_dir, theme, file); if(!faccessible(fname)) - snprintf(fname, 1024, "%s/images/themes/%s/%s", DATA_PREFIX, theme, file); - + snprintf(fname, 1024, "%s/images/themes/%s/%s", DATA_PREFIX, theme, file); + texture_load(ptexture, fname, use_alpha); } diff --git a/src/level.h b/src/level.h index 264194b7e..1b31fd2b4 100644 --- a/src/level.h +++ b/src/level.h @@ -22,6 +22,7 @@ typedef struct st_level /*It is easier to read the sources IMHO, if we don't wri char name[LEVEL_NAME_MAX]; char theme[100]; char song_title[100]; + char bkgd_image[100]; unsigned char* tiles[15]; int time_left; int bkgd_red; @@ -30,9 +31,10 @@ typedef struct st_level /*It is easier to read the sources IMHO, if we don't wri int width; } st_level; -texture_type img_bkgd[2][4], img_solid[4], img_brick[2]; +texture_type img_bkgd, img_bkgd_tile[2][4], img_solid[4], img_brick[2]; void loadlevel(st_level* plevel, char * subset, int level); +void unloadlevel(st_level* plevel); void loadlevelgfx(st_level* plevel); void unloadlevelgfx(); void load_level_image(texture_type* ptexture, char* theme, char * file, int use_alpha); diff --git a/src/leveleditor.c b/src/leveleditor.c index 1f95ff97e..9981c8d17 100644 --- a/src/leveleditor.c +++ b/src/leveleditor.c @@ -8,7 +8,7 @@ * * ***************************************************************************/ -/* December 28, 2003 - January 1st, 2004 */ +/* December 28, 2003 - February 1st, 2004 */ /* leveleditor.c - A built-in level editor for SuperTux by Ricardo Cruz */ @@ -190,7 +190,7 @@ int leveleditor() key = event.key.keysym.sym; if(show_menu) { - menu_event(key); + menu_event(&event.key.keysym); break; } switch(key) @@ -479,7 +479,6 @@ switch(cursor_tile) /* 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].base.alive == NO) continue; /* to support frames: img_bsod_left[(frame / 5) % 4] */ @@ -503,14 +502,14 @@ if(show_grid) texture_draw(&selection, ((int)(cursor_x - pos_x)/32)*32, cursor_y, NO_UPDATE); sprintf(str, "%d", current_level.time_left); - drawtext("TIME", 324, 0, letters_blue, NO_UPDATE, 1); - drawtext(str, 404, 0, letters_gold, NO_UPDATE, 1); + text_draw(&blue_text, "TIME", 324, 0, 1, NO_UPDATE); + text_draw(&gold_text, str, 404, 0, 1, NO_UPDATE); sprintf(str, "%s", current_level.name); - drawtext("NAME", 0, 0, letters_blue, NO_UPDATE, 1); - drawtext(str, 80, 0, letters_gold, NO_UPDATE, 1); + text_draw(&blue_text, "NAME", 0, 0, 1, NO_UPDATE); + text_draw(&gold_text, str, 80, 0, 1, NO_UPDATE); - drawtext("F1 for Help", 10, 430, letters_blue, NO_UPDATE, 1); + text_draw(&blue_text, "F1 for Help", 10, 430, 1, NO_UPDATE); if(show_menu) { @@ -604,7 +603,7 @@ void savelevel(void) fclose(fi); - drawcenteredtext("SAVED!", 240, letters_gold, NO_UPDATE, 1); + text_drawf(&gold_text, "SAVED!", 0, 240, A_HMIDDLE, A_TOP, 1, NO_UPDATE); flipscreen(); SDL_Delay(1000); } @@ -638,14 +637,14 @@ void showhelp() "Esc - Menu"}; - drawcenteredtext("- Help -", 30, letters_red, NO_UPDATE, 2); - drawtext("Keys:", 80, 60, letters_gold, NO_UPDATE, 1); + text_drawf(&red_text, "- Help -", 0, 30, A_HMIDDLE, A_TOP, 2, NO_UPDATE); + text_draw(&gold_text, "Keys:", 80, 60, 1, NO_UPDATE); int i; for(i = 0; i < sizeof(text)/sizeof(char *); i++) - drawtext(text[i], 40, 90+(i*16), letters_blue, NO_UPDATE, 1); + text_draw(&blue_text, text[i], 40, 90+(i*16), 1, NO_UPDATE); - drawcenteredtext("Press Any Key to Continue", 460, letters_gold, NO_UPDATE, 1); + text_drawf(&gold_text, "Press Any Key to Continue", 0, 460, A_HMIDDLE, A_TOP, 1, NO_UPDATE); flipscreen(); diff --git a/src/menu.c b/src/menu.c index b16670b62..7971f7a0a 100644 --- a/src/menu.c +++ b/src/menu.c @@ -16,6 +16,8 @@ #include #endif +#include + #include "defines.h" #include "globals.h" #include "menu.h" @@ -24,6 +26,8 @@ #include "sound.h" #include "leveleditor.h" #include "gameloop.h" +#include "timer.h" +#include "high_scores.h" /* Set defaults */ void initmenu(void) @@ -33,6 +37,9 @@ void initmenu(void) menuitem = 0; menumenu = 0; menuaction = -1; + + delete_character = 0; + strcpy(input_string, ""); } /* ---- Menu Options - Item Sound On/off ----*/ @@ -44,11 +51,11 @@ void menu_option_sound() { if(use_sound == YES) { - drawcenteredtext("Sound ON", 224, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Sound ON", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE); } else { - drawcenteredtext("Sound OFF", 224, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Sound OFF", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE); } if(menuaction == MN_HIT) @@ -67,9 +74,9 @@ void menu_option_sound() else { if(use_sound == YES) - drawcenteredtext("Sound ON", 224, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "Sound ON", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE); else - drawcenteredtext("Sound OFF", 224, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "Sound OFF", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE); } } else @@ -77,11 +84,11 @@ void menu_option_sound() /* let the user move over the deactivated option */ if (menuitem == 1) { - drawcenteredtext("Sound OFF", 224, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Sound OFF", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE); } else { - drawcenteredtext("Sound OFF", 224, letters_black, NO_UPDATE, 2); + text_drawf(&red_text, "Sound OFF", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE); } } } @@ -96,11 +103,11 @@ void menu_option_music() { if(use_music == YES) { - drawcenteredtext("Music ON", 256, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Music ON", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE); } else { - drawcenteredtext("Music OFF", 256, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Music OFF", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE); } if(menuaction == MN_HIT) { /* Disable/Enable music */ @@ -115,7 +122,7 @@ void menu_option_music() use_music = YES; if (!playing_music()) { - play_current_music(); + play_current_music(); } } menu_change = YES; @@ -125,11 +132,11 @@ void menu_option_music() { if(use_music == YES) { - drawcenteredtext("Music ON", 256, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "Music ON", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE); } else { - drawcenteredtext("Music OFF", 256, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "Music OFF", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE); } } } @@ -138,11 +145,11 @@ void menu_option_music() /* let the user move over the deactivated option */ if (menuitem == 2) { - drawcenteredtext("Music OFF", 256, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Music OFF", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE); } else { - drawcenteredtext("Music OFF", 256, letters_black, NO_UPDATE, 2); + text_drawf(&black_text, "Music OFF", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE); } } } @@ -158,7 +165,7 @@ int menu_main(void) /*The menu looks different, when the game is started */ if(menuitem == 0) { - drawcenteredtext("Start Game", 192, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Start Game", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuaction == MN_HIT) /* we are ready to start the game, if this item got hit */ { game_started = 1; @@ -166,11 +173,11 @@ int menu_main(void) } } else - drawcenteredtext("Start Game", 192, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "Start Game", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuitem == 1) { - drawcenteredtext("Options", 224, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Options", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuaction == MN_HIT) /* Switch to the 'Options' menu */ { menumenu = MENU_OPTIONS; @@ -178,11 +185,11 @@ int menu_main(void) } } else - drawcenteredtext("Options", 224, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "Options", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuitem == 2) { - drawcenteredtext("Level editor", 256, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Level editor", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuaction == MN_HIT) /* Set variables, so that the level editor is executed */ { level_editor_started = YES; @@ -190,11 +197,11 @@ int menu_main(void) } } else - drawcenteredtext("Level editor", 256, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "Level editor", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuitem == 3) { - drawcenteredtext("Quit", 288, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Quit", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuaction == MN_HIT) /* Quit a running game or the application */ { return 1; @@ -202,7 +209,7 @@ int menu_main(void) } else { - drawcenteredtext("Quit", 288, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "Quit", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE); } return 0; @@ -219,42 +226,45 @@ int menu_game(void) /*The menu looks different, when the game is started */ if(menuitem == 0) { - drawcenteredtext("Return To Game", 192, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Return To Game", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */ - show_menu = 0; + { + show_menu = 0; + st_pause_ticks_stop(); + } } else - drawcenteredtext("Return To Game", 192, letters_blue, NO_UPDATE, 2); - + text_drawf(&blue_text, "Return To Game", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE); + if(menuitem == 1) { - drawcenteredtext("Save Game", 224, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Save Game", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */ - { - show_menu = 0; - savegame(); - } + { + show_menu = 0; + savegame(); + } } else - drawcenteredtext("Save Game", 224, letters_blue, NO_UPDATE, 2); - + text_drawf(&blue_text, "Save Game", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE); + if(menuitem == 2) { - drawcenteredtext("Load Game", 256, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Load Game", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */ - { - char *x = NULL; /* In C, you can do this... */ + { + char *x = NULL; /* In C, you can do this... */ - show_menu = 0; - loadgame(x); - } + show_menu = 0; + loadgame(x); + } } else - drawcenteredtext("Load Game", 256, letters_blue, NO_UPDATE, 2); - + text_drawf(&blue_text, "Load Game", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE); + if(menuitem == 3) { - drawcenteredtext("Options", 288, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Options", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuaction == MN_HIT) /* Switch to the 'Options' menu */ { menumenu = MENU_OPTIONS; @@ -262,17 +272,17 @@ int menu_game(void) } } else - drawcenteredtext("Options", 288, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "Options", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuitem == 4) { - drawcenteredtext("Quit Game", 320, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Quit Game", 0, 320, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuaction == MN_HIT) /* Quit a running game */ return 1; } else { - drawcenteredtext("Quit Game", 320, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "Quit Game", 0, 320, A_HMIDDLE, A_TOP, 2, NO_UPDATE); } return 0; @@ -288,9 +298,9 @@ int menu_options(void) if(menuitem == 0) { if(use_fullscreen) - drawcenteredtext("Fullscreen ON", 192, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Fullscreen ON", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE); else - drawcenteredtext("Fullscreen OFF", 192, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Fullscreen OFF", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuaction == MN_HIT) /* Disable/Enable fullscreen */ { if(use_fullscreen) @@ -304,9 +314,9 @@ int menu_options(void) else { if(use_fullscreen) - drawcenteredtext("Fullscreen ON", 192, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "Fullscreen ON", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE); else - drawcenteredtext("Fullscreen OFF", 192, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "Fullscreen OFF", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE); } /* handle menu sound on/off option */ @@ -317,7 +327,7 @@ int menu_options(void) if(menuitem == 3) { - drawcenteredtext("Back", 288, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Back", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuaction == MN_HIT) /* Go back to main menu. */ { if(game_started) @@ -328,7 +338,7 @@ int menu_options(void) } } else - drawcenteredtext("Back", 288, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "Back", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE); return 0; } @@ -343,16 +353,16 @@ int menu_leveleditor(void) if(menuitem == 0) { - drawcenteredtext("Return To Level Editor", 192, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Return To Level Editor", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE); 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); + text_drawf(&blue_text, "Return To Level Editor", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuitem == 1) { - drawcenteredtext("New Level", 224, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "New Level", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */ { show_menu = 0; @@ -360,10 +370,11 @@ int menu_leveleditor(void) } } else - drawcenteredtext("New Level", 224, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "New Level", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE); + if(menuitem == 2) { - drawcenteredtext("Load Level", 256, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Load Level", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuaction == MN_HIT) /* Create a new Level and load it into the level-editor. */ { show_menu = 0; @@ -371,10 +382,11 @@ int menu_leveleditor(void) } } else - drawcenteredtext("Load Level", 256, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "Load Level", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE); + if(menuitem == 3) { - drawcenteredtext("Save Level", 288, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Save Level", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuaction == MN_HIT) /* Save the current level in the level-editor. */ { show_menu = 0; @@ -382,22 +394,50 @@ int menu_leveleditor(void) } } else - drawcenteredtext("Save Level", 288, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "Save Level", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuitem == 4) { - drawcenteredtext("Quit Level Editor", 320, letters_red, NO_UPDATE, 2); + text_drawf(&red_text, "Quit Level Editor", 0, 320, A_HMIDDLE, A_TOP, 2, NO_UPDATE); if(menuaction == MN_HIT) /* Quit the level-editor. (to the main-menu) */ { return 1; } } else - drawcenteredtext("Quit Level Editor", 320, letters_blue, NO_UPDATE, 2); + text_drawf(&blue_text, "Quit Level Editor", 0, 320, A_HMIDDLE, A_TOP, 2, NO_UPDATE); return 0; } +/* Menu HighScore (ask for player's name) */ +int menu_highscore() +{ +while(delete_character > 0) /* remove charactes */ + { + hs_name[strlen(hs_name)-1] = '\0'; + delete_character--; + } + +char str[60]; +strcat(hs_name, input_string); + +text_drawf(&red_text, "Congratulations", 0, 130, A_HMIDDLE, A_TOP, 2, NO_UPDATE); +text_draw(&red_text, "Your score:", 30, 250, 1, NO_UPDATE); +sprintf(str, "%d", hs_score); +text_draw(&blue_text, str, 350, 250, 1, NO_UPDATE); + +text_draw(&red_text, "Enter your name:", 30, 280, 1, NO_UPDATE); +text_draw(&blue_text, hs_name, 350, 280, 1, NO_UPDATE); + +strcpy(input_string, ""); + +if(menuaction == MN_HIT) /* name written */ + show_menu = 0; + +return 0; +} + /* --- MENU --- */ /* Draw the menu and execute the (menu)events */ int drawmenu(void) @@ -408,30 +448,31 @@ int drawmenu(void) if(menuaction == MN_UP) - { - /* Go one menu-item up */ - --menuitem; - } + --menuitem; /* Go one menu-item up */ else if(menuaction == MN_DOWN) - ++menuitem; /* Go one menu-item down */ + ++menuitem; /* Go one menu-item down */ - if(menumenu == MENU_MAIN) - { + switch(menumenu) + { + case MENU_MAIN: quit = menu_main(); - } - else if(menumenu == MENU_GAME) - { + break; + case MENU_GAME: quit = menu_game(); - } - else if(menumenu == MENU_OPTIONS) - { + break; + case MENU_OPTIONS: quit = menu_options(); - } - else if(menumenu == MENU_LEVELEDITOR) - { + break; + case MENU_LEVELEDITOR: quit = menu_leveleditor(); - } + break; + case MENU_HIGHSCORE: + quit = menu_highscore(); + break; + default: + break; + } menuaction = -1; @@ -439,41 +480,62 @@ int drawmenu(void) } /* Check for menu event */ -void menu_event(SDLKey key) +void menu_event(SDL_keysym* keysym) { +SDLKey key = keysym->sym; +SDLMod keymod; +keymod = SDL_GetModState(); +char ch[2]; + +/* If the current unicode character is an ASCII character, + assign it to ch. */ +if ( (keysym->unicode & 0xFF80) == 0 ) { + ch[0] = keysym->unicode & 0x7F; + ch[1] = '\0'; +} +else { + /* An International Character. */ +} +switch(key) + { + case SDLK_UP: /* Menu Up */ + menuaction = MN_UP; + menu_change = YES; + break; + case SDLK_DOWN: /* Menu Down */ + menuaction = MN_DOWN; + menu_change = YES; + break; + case SDLK_SPACE: /* Menu Hit */ + case SDLK_RETURN: + menuaction = MN_HIT; + menu_change = YES; + break; + + case SDLK_DELETE: + case SDLK_BACKSPACE: + delete_character++; + break; + default: + if( key >= SDLK_0 && key <= SDLK_9) + strcat( input_string, /* (key - SDLK_0) */ ch); + else if( key >= SDLK_a && SDLK_z ) + { + strcat( input_string, ch); + } + break; + } - if (key == SDLK_UP) - { - /* Menu Up */ - - menuaction = MN_UP; - menu_change = YES; - } - else if (key == SDLK_DOWN) - { - /* Menu Down */ - - menuaction = MN_DOWN; - menu_change = YES; - } - else if (key == SDLK_SPACE || key == SDLK_RETURN) - { - /* Menu Hit */ - - menuaction = MN_HIT; - menu_change = YES; - } /* FIXME: NO JOYSTICK SUPPORT */ /*#ifdef JOY_YES else if (event.type == SDL_JOYBUTTONDOWN) { - Joystick button: Continue: - + Joystick button: Continue: + done = 1; } #endif*/ - } diff --git a/src/menu.h b/src/menu.h index 233481eb4..92a801a15 100644 --- a/src/menu.h +++ b/src/menu.h @@ -39,9 +39,14 @@ enum { MENU_MAIN, MENU_GAME, MENU_OPTIONS, - MENU_LEVELEDITOR + MENU_LEVELEDITOR, + MENU_HIGHSCORE }; +/* input implementation variables */ +int delete_character; +char input_string[62]; + /* Initialize the menu variables */ void initmenu(void); @@ -49,7 +54,7 @@ void initmenu(void); int drawmenu(void); /* Check for a menu event */ -void menu_event(SDLKey key); +void menu_event(SDL_keysym* keysym); #endif /*SUPERTUX_MENU_H*/ diff --git a/src/player.c b/src/player.c index 425e6e28c..e2f45f56b 100644 --- a/src/player.c +++ b/src/player.c @@ -4,7 +4,7 @@ // Description: // // -// Author: Tobias Glaesser , (C) 2004 +// Author: Tobias Glaesser & Bill Kendrick, (C) 2004 // // Copyright: See COPYING file that comes with this distribution // @@ -22,7 +22,6 @@ void player_init(player_type* pplayer) pplayer->base.width = 32; pplayer->base.height = 32; - pplayer->base.updated = SDL_GetTicks(); pplayer->size = SMALL; pplayer->got_coffee = NO; @@ -52,7 +51,7 @@ void player_init(player_type* pplayer) pplayer->keymap.left = SDLK_LEFT; pplayer->keymap.right = SDLK_RIGHT; pplayer->keymap.fire = SDLK_LCTRL; - + timer_init(&pplayer->invincible_timer); timer_init(&pplayer->skidding_timer); timer_init(&pplayer->safe_timer); @@ -60,64 +59,64 @@ void player_init(player_type* pplayer) int player_keydown_event(player_type* pplayer, SDLKey key) { - if(key == pplayer->keymap.right) - { - pplayer->input.right = DOWN; - return YES; - } - else if( key == pplayer->keymap.left) - { - pplayer->input.left = DOWN; - return YES; - } - else if(key == pplayer->keymap.jump) - { - pplayer->input.up = DOWN; - return YES; - } - else if(key == pplayer->keymap.duck) - { - pplayer->input.down = DOWN; - return YES; - } - else if(key == pplayer->keymap.fire) - { - pplayer->input.fire = DOWN; - return YES; - } - else - return NO; + if(key == pplayer->keymap.right) + { + pplayer->input.right = DOWN; + return YES; + } + else if( key == pplayer->keymap.left) + { + pplayer->input.left = DOWN; + return YES; + } + else if(key == pplayer->keymap.jump) + { + pplayer->input.up = DOWN; + return YES; + } + else if(key == pplayer->keymap.duck) + { + pplayer->input.down = DOWN; + return YES; + } + else if(key == pplayer->keymap.fire) + { + pplayer->input.fire = DOWN; + return YES; + } + else + return NO; } - + int player_keyup_event(player_type* pplayer, SDLKey key) { - if(key == pplayer->keymap.right) - { - pplayer->input.right = UP; - return YES; - } - else if( key == pplayer->keymap.left) - { - pplayer->input.left = UP; - return YES; - } - else if(key == pplayer->keymap.jump) - { - pplayer->input.up = UP; - return YES; - } - else if(key == pplayer->keymap.duck) - { - pplayer->input.down = UP; - return YES; - } - else if(key == pplayer->keymap.fire) - { - pplayer->input.fire = UP; - return YES; - } - else - return NO; + if(key == pplayer->keymap.right) + { + pplayer->input.right = UP; + return YES; + } + else if( key == pplayer->keymap.left) + { + pplayer->input.left = UP; + return YES; + } + else if(key == pplayer->keymap.jump) + { + pplayer->input.up = UP; + return YES; + } + else if(key == pplayer->keymap.duck) + { + pplayer->input.down = UP; + return YES; + } + else if(key == pplayer->keymap.fire) + { + pplayer->input.fire = UP; + return YES; + } + else + return NO; } void player_level_begin(player_type* pplayer) @@ -126,7 +125,7 @@ void player_level_begin(player_type* pplayer) pplayer->base.y = 240; pplayer->base.xm = 0; pplayer->base.ym = 0; - + pplayer->input.down = UP; pplayer->input.fire = UP; pplayer->input.left = UP; @@ -138,9 +137,6 @@ void player_level_begin(player_type* pplayer) void player_action(player_type* pplayer) { - - double frame_ratio = get_frame_ratio(&pplayer->base); - /* --- HANDLE TUX! --- */ player_input(pplayer); @@ -194,7 +190,9 @@ void player_action(player_type* pplayer) ++debug_int; if(debug_int > 32) DEBUG_MSG("FIXME - UNDER certain circumstances I'm hanging in a loop here!"); - + /*the circumstances are: + issolid() is true and base.ym == 0 + use of floating point varibles for base stuff*/ if (pplayer->base.ym < 0) pplayer->base.y++; else if (pplayer->base.ym > 0) @@ -212,6 +210,7 @@ void player_action(player_type* pplayer) pplayer->base.ym = 0; pplayer->jumping = NO; + pplayer->input.up = UP; } @@ -438,38 +437,44 @@ void player_action(player_type* pplayer) timer_check(&pplayer->safe_timer); - + /* ---- DONE HANDLING TUX! --- */ /* Handle invincibility timer: */ - if (timer_check(&pplayer->invincible_timer)) + if (current_music == HERRING_MUSIC && !timer_check(&pplayer->invincible_timer)) { - if (current_music == HERRING_MUSIC) + /* + no, we are no more invincible + or we were not in invincible mode + but are we in hurry ? + */ + + + if (timer_get_left(&time_left) < TIME_WARNING) { - if (current_level.time_left <= TIME_WARNING) - { - /* stop the herring_song, prepare to play the correct - * fast level_song ! - */ - current_music = HURRYUP_MUSIC; - } - else - { - current_music = LEVEL_MUSIC; - } - /* stop the old music if it's being played */ - if (playing_music()) - halt_music(); + /* yes, we are in hurry + stop the herring_song, prepare to play the correct + fast level_song ! + */ + current_music = HURRYUP_MUSIC; } + else + { + current_music = LEVEL_MUSIC; + } + + /* stop the old music if it's being played */ + if (playing_music()) + halt_music(); } /* Handle skidding: */ timer_check(&pplayer->skidding_timer); - + /* End of level? */ if (pplayer->base.x>= endpos && endpos != 0) @@ -479,632 +484,620 @@ void player_action(player_type* pplayer) } -void player_input(player_type *pplayer) +void player_handle_horizontal_input(player_type *pplayer, int dir) { - /* Handle key and joystick state: */ - - - if (pplayer->input.right == DOWN && pplayer->input.left == UP) - { - if (pplayer->jumping == NO) - { - if (pplayer->base.xm < -SKID_XM && !timer_started(&pplayer->skidding_timer) && - pplayer->dir == LEFT) - { - timer_start(&pplayer->skidding_timer, SKID_TIME); - - play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER); - - } - pplayer->dir = RIGHT; - } - - if (pplayer->base.xm < 0 && !isice(pplayer->base.x, pplayer->base.y + 32) && - !timer_started(&pplayer->skidding_timer)) - { - pplayer->base.xm = 0; - } - - if (!pplayer->duck) - { - if (pplayer->dir == RIGHT) - { - /* Facing the direction we're jumping? Go full-speed: */ - - if (pplayer->input.fire == UP) - { - pplayer->base.xm = pplayer->base.xm + WALK_SPEED; - - if (pplayer->base.xm > MAX_WALK_XM) - pplayer->base.xm = MAX_WALK_XM; - } - else if ( pplayer->input.fire == DOWN) - { - pplayer->base.xm = pplayer->base.xm + RUN_SPEED; - - if (pplayer->base.xm > MAX_RUN_XM) - pplayer->base.xm = MAX_RUN_XM; - } - } - else - { - /* Not facing the direction we're jumping? - Go half-speed: */ - - pplayer->base.xm = pplayer->base.xm + WALK_SPEED / 2; - - if (pplayer->base.xm > MAX_WALK_XM / 2) - pplayer->base.xm = MAX_WALK_XM / 2; - } - } - } - else if (pplayer->input.left == DOWN && pplayer->input.right == UP) - { - if (pplayer->jumping == NO) - { - if (pplayer->base.xm > SKID_XM && !timer_started(&pplayer->skidding_timer) && - pplayer->dir == RIGHT) - { - timer_start(&pplayer->skidding_timer,SKID_TIME); - play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER); - } - pplayer->dir = LEFT; - } - - if (pplayer->base.xm > 0 && !isice(pplayer->base.x, pplayer->base.y + 32) && - !timer_started(&pplayer->skidding_timer)) - { - pplayer->base.xm = 0; - } - - if (!pplayer->duck) - { - if (pplayer->dir == LEFT) - { - /* Facing the direction we're jumping? Go full-speed: */ - - if (pplayer->input.fire == UP) - { - pplayer->base.xm = pplayer->base.xm - WALK_SPEED; - - if (pplayer->base.xm < -MAX_WALK_XM) - pplayer->base.xm = -MAX_WALK_XM; - } - else if (pplayer->input.fire == DOWN) - { - pplayer->base.xm = pplayer->base.xm - RUN_SPEED; - - if (pplayer->base.xm < -MAX_RUN_XM) - pplayer->base.xm = -MAX_RUN_XM; - } - } - else - { - /* Not facing the direction we're jumping? - Go half-speed: */ - - pplayer->base.xm = pplayer->base.xm - WALK_SPEED / 2; - - if (pplayer->base.xm < -MAX_WALK_XM / 2) - pplayer->base.xm = -MAX_WALK_XM / 2; - } - } - } - - /* Jump/jumping? */ - - if ( pplayer->input.up == DOWN) + if (pplayer->jumping == NO) { - if(!timer_started(&pplayer->jump_timer)) - { - timer_start(&pplayer->jump_timer,MAX_JUMP_TIME); - - - /* Taking off? */ - - if (!issolid(pplayer->base.x, pplayer->base.y + 32) || - pplayer->base.ym != 0) - { - /* If they're not on the ground, or are currently moving - vertically, don't jump! */ - - pplayer->jumping = NO; - timer_stop(&pplayer->jump_timer); - } - else - { - /* Make sure we're not standing back up into a solid! */ - - if (pplayer->size == SMALL || pplayer->duck == NO || - !issolid(pplayer->base.x, pplayer->base.y)) - { - pplayer->jumping = YES; - - if (pplayer->size == SMALL) - play_sound(sounds[SND_JUMP], SOUND_CENTER_SPEAKER); - else - play_sound(sounds[SND_BIGJUMP], SOUND_CENTER_SPEAKER); - } - } - } - - /* Keep jumping for a while: */ - - if (timer_check(&pplayer->jump_timer)) + if ((dir ? (pplayer->base.xm < -SKID_XM) : (pplayer->base.xm > SKID_XM)) && !timer_started(&pplayer->skidding_timer) && + pplayer->dir == !dir) { - pplayer->base.ym = pplayer->base.ym - JUMP_SPEED; - } - } - else - timer_stop(&pplayer->jump_timer); - - - /* Shoot! */ - - if (pplayer->input.fire == DOWN && pplayer->input.old_fire == UP && pplayer->got_coffee) - { - add_bullet(pplayer->base.x, pplayer->base.y, pplayer->base.xm, pplayer->dir); - } - - - /* Duck! */ + timer_start(&pplayer->skidding_timer, SKID_TIME); - if (pplayer->input.down == DOWN) - { - if (pplayer->size == BIG) - pplayer->duck = YES; - } - else - { - if (pplayer->size == BIG && pplayer->duck == YES) - { - /* Make sure we're not standing back up into a solid! */ + play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER); - if (!issolid(pplayer->base.x, pplayer->base.y - 32)) - pplayer->duck = NO; } - else - pplayer->duck = NO; + pplayer->dir = dir; } - /* (Tux): */ - - if (pplayer->input.right == UP && pplayer->input.left == UP) + if ((dir ? (pplayer->base.xm < 0) : (pplayer->base.xm > 0)) && !isice(pplayer->base.x, pplayer->base.y + 32) && + !timer_started(&pplayer->skidding_timer)) { - pplayer->frame_main = 1; - pplayer->frame = 1; - } - else - { - if ((pplayer->input.fire == DOWN && (frame % 2) == 0) || - (frame % 4) == 0) - pplayer->frame_main = (pplayer->frame_main + 1) % 4; - - pplayer->frame = pplayer->frame_main; - - if (pplayer->frame == 3) - pplayer->frame = 1; + pplayer->base.xm = 0; } -} - -void player_grabdistros(player_type *pplayer) -{ - /* Grab distros: */ - if (!pplayer->dying) + if (!pplayer->duck) { - trygrabdistro(pplayer->base.x, pplayer->base.y, NO_BOUNCE); - trygrabdistro(pplayer->base.x+ 31, pplayer->base.y, NO_BOUNCE); - - if (pplayer->size == BIG && !pplayer->duck) + if (pplayer->dir == dir) { - trygrabdistro(pplayer->base.x, pplayer->base.y - 32, NO_BOUNCE); - trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32, NO_BOUNCE); - } - } - - - /* Enough distros for a One-up? */ + /* Facing the direction we're jumping? Go full-speed: */ - if (distros >= DISTROS_LIFEUP) - { - distros = distros - DISTROS_LIFEUP; - if(pplayer->lives < MAX_LIVES) - pplayer->lives++; - /*We want to hear the sound even, if MAX_LIVES is reached*/ - play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER); - } -} - -void player_draw(player_type* pplayer) -{ - - if (!timer_started(&pplayer->safe_timer) || (frame % 2) == 0) - { - if (pplayer->size == SMALL) - { - if (timer_started(&pplayer->invincible_timer)) + if (pplayer->input.fire == UP) { - /* Draw cape: */ + pplayer->base.xm = pplayer->base.xm + ( dir ? WALK_SPEED : -WALK_SPEED) * frame_ratio; - if (pplayer->dir == RIGHT) - { - texture_draw(&cape_right[frame % 2], - pplayer->base.x- scroll_x, pplayer->base.y, - NO_UPDATE); - } - else + if(dir) { - texture_draw(&cape_left[frame % 2], - pplayer->base.x- scroll_x, pplayer->base.y, - NO_UPDATE); - } - } - - - if (!pplayer->got_coffee) - { - if (pplayer->dir == RIGHT) - { - texture_draw(&tux_right[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE); - } - else - { - texture_draw(&tux_left[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE); - } - } - else - { - /* Tux got coffee! */ - - if (pplayer->dir == RIGHT) - { - texture_draw(&firetux_right[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE); + if (pplayer->base.xm > MAX_WALK_XM) + pplayer->base.xm = MAX_WALK_XM; } else { - texture_draw(&firetux_left[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE); + if (pplayer->base.xm < -MAX_WALK_XM) + pplayer->base.xm = -MAX_WALK_XM; } } - } - else - { - if (timer_started(&pplayer->invincible_timer)) + else if ( pplayer->input.fire == DOWN) { - /* Draw cape: */ + pplayer->base.xm = pplayer->base.xm + ( dir ? RUN_SPEED : -RUN_SPEED) * frame_ratio; - if (pplayer->dir == RIGHT) + if(dir) { - texture_draw(&bigcape_right[frame % 2], - pplayer->base.x- scroll_x - 8 - 16, pplayer->base.y - 32, - NO_UPDATE); - } - else - { - texture_draw(&bigcape_left[frame % 2], - pplayer->base.x-scroll_x - 8, pplayer->base.y - 32, - NO_UPDATE); - } - } - - if (!pplayer->got_coffee) - { - if (!pplayer->duck) - { - if (!timer_started(&pplayer->skidding_timer)) - { - if (!pplayer->jumping || pplayer->base.ym > 0) - { - if (pplayer->dir == RIGHT) - { - texture_draw(&bigtux_right[pplayer->frame], - pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, - NO_UPDATE); - } - else - { - texture_draw(&bigtux_left[pplayer->frame], - pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, - NO_UPDATE); - } - } - else - { - if (pplayer->dir == RIGHT) - { - texture_draw(&bigtux_right_jump, - pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, - NO_UPDATE); - } - else - { - texture_draw(&bigtux_left_jump, - pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, - NO_UPDATE); - } - } - } - else - { - if (pplayer->dir == RIGHT) - { - texture_draw(&skidtux_right, - pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, - NO_UPDATE); - } - else - { - texture_draw(&skidtux_left, - pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, - NO_UPDATE); - } - } + if (pplayer->base.xm > MAX_RUN_XM) + pplayer->base.xm = MAX_RUN_XM; } else { - if (pplayer->dir == RIGHT) - { - texture_draw(&ducktux_right, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16, - NO_UPDATE); - } - else - { - texture_draw(&ducktux_left, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16, - NO_UPDATE); - } + if (pplayer->base.xm < -MAX_RUN_XM) + pplayer->base.xm = -MAX_RUN_XM; } } else { - /* Tux has coffee! */ - - if (!pplayer->duck) - { - if (!timer_started(&pplayer->skidding_timer)) - { - if (!pplayer->jumping || pplayer->base.ym > 0) - { - if (pplayer->dir == RIGHT) - { - texture_draw(&bigfiretux_right[pplayer->frame], - pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, - NO_UPDATE); - } - else - { - texture_draw(&bigfiretux_left[pplayer->frame], - pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, - NO_UPDATE); - } - } - else - { - if (pplayer->dir == RIGHT) - { - texture_draw(&bigfiretux_right_jump, - pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, - NO_UPDATE); - } - else - { - texture_draw(&bigfiretux_left_jump, - pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, - NO_UPDATE); - } - } - } - else - { - if (pplayer->dir == RIGHT) - { - texture_draw(&skidfiretux_right, - pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, - NO_UPDATE); - } - else - { - texture_draw(&skidfiretux_left, - pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, - NO_UPDATE); - } - } - } - else - { - if (pplayer->dir == RIGHT) - { - texture_draw(&duckfiretux_right, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16, - NO_UPDATE); - } - else - { - texture_draw(&duckfiretux_left, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16, - NO_UPDATE); - } - } - } - } - } - -} - -void player_collision(player_type* pplayer, void* p_c_object, int c_object) -{ - bad_guy_type* pbad_c = NULL; - - switch (c_object) - { - case CO_BADGUY: - pbad_c = p_c_object; - /* Hurt the player if he just touched it: */ - - if (!pbad_c->dying && !pplayer->dying && - !timer_started(&pplayer->safe_timer) && - pbad_c->mode != HELD) - { - if (pbad_c->mode == FLAT && pplayer->input.fire != DOWN) - { - /* Kick: */ - - pbad_c->mode = KICK; - play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER); - - if (pplayer->base.x<= pbad_c->base.x) - { - pbad_c->dir = RIGHT; - pbad_c->base.x = pbad_c->base.x + 16; - } - else - { - pbad_c->dir = LEFT; - pbad_c->base.x = pbad_c->base.x - 16; - } - - timer_start(&pbad_c->timer,5000); - } - else if (pbad_c->mode == FLAT && pplayer->input.fire == DOWN) - { - pbad_c->mode = HELD; - pbad_c->base.y-=8; - } - else if (pbad_c->mode == KICK) - { - if (pplayer->base.y < pbad_c->base.y - 16 && - timer_started(&pbad_c->timer)) - { - /* Step on (stop being kicked) */ + /* Not facing the direction we're jumping? + Go half-speed: */ - pbad_c->mode = FLAT; - play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER); - timer_start(&pbad_c->timer, 10000); - } - else - { - /* Hurt if you get hit by kicked laptop: */ + pplayer->base.xm = pplayer->base.xm + ( dir ? (WALK_SPEED / 2) : -(WALK_SPEED / 2)) * frame_ratio; - if (timer_started(&pbad_c->timer)) - { - if (!timer_started(&pplayer->invincible_timer)) - { - player_kill(pplayer,SHRINK); - } - else - { - pbad_c->dying = FALLING; - pbad_c->base.ym = -8; - play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER); - } - } - } - } - else - { - if (!timer_started(&pplayer->invincible_timer )) + if(dir) { - player_kill(pplayer,SHRINK); + if (pplayer->base.xm > MAX_WALK_XM / 2) + pplayer->base.xm = MAX_WALK_XM / 2; } else { - pbad_c->dying = FALLING; - pbad_c->base.ym = -8; - play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER); + if (pplayer->base.xm < -MAX_WALK_XM / 2) + pplayer->base.xm = -MAX_WALK_XM / 2; } } } - score_multiplier++; - break; - } - -} - -/* Kill Player! */ - -void player_kill(player_type* pplayer, int mode) -{ - pplayer->base.ym = -5; - - play_sound(sounds[SND_HURT], SOUND_CENTER_SPEAKER); - - if (pplayer->dir == RIGHT) - pplayer->base.xm = -8; - else if (tux.dir == LEFT) - pplayer->base.xm = 8; - - if (mode == SHRINK && pplayer->size == BIG) - { - if (pplayer->got_coffee) - pplayer->got_coffee = NO; - - pplayer->size = SMALL; - timer_start(&pplayer->safe_timer,TUX_SAFE_TIME); - } - else - { - pplayer->dying = 1; } } -void player_dying(player_type *pplayer) +void player_handle_vertical_input(player_type *pplayer) { - pplayer->base.ym = pplayer->base.ym + GRAVITY; - - /* He died :^( */ - - --pplayer->lives; - player_remove_powerups(pplayer); - pplayer->dying = NO; - - player_level_begin(pplayer); - -} - -/* Remove Tux's power ups */ -void player_remove_powerups(player_type* pplayer) -{ - pplayer->got_coffee = NO; - pplayer->size = SMALL; -} - -void player_keep_in_bounds(player_type* pplayer) -{ - /* Keep tux in bounds: */ - if (pplayer->base.x< 0) - pplayer->base.x= 0; - else if(pplayer->base.x< scroll_x) - pplayer->base.x= scroll_x; - else if (pplayer->base.x< 160 + scroll_x && scroll_x > 0 && debug_mode == YES) - { - scroll_x = pplayer->base.x- 160; - /*pplayer->base.x+= 160;*/ - - if(scroll_x < 0) - scroll_x = 0; - - } - else if (pplayer->base.x> screen->w / 2 + scroll_x && scroll_x < ((current_level.width * 32) - screen->w)) - { - /* Scroll the screen in past center: */ - - scroll_x = pplayer->base.x- screen->w / 2; - /*pplayer->base.x= 320 + scroll_x;*/ - - if (scroll_x > ((current_level.width * 32) - screen->w)) - scroll_x = ((current_level.width * 32) - screen->w); - } - else if (pplayer->base.x> 608 + scroll_x) - { - /* ... unless there's no more to scroll! */ - - /*pplayer->base.x= 608 + scroll_x;*/ - } - - /* Keep in-bounds, vertically: */ - - if (pplayer->base.y < 0) - pplayer->base.y = 0; - else if (pplayer->base.y > screen->h) - { - player_kill(&tux,KILL); - } -} + if(!timer_started(&pplayer->jump_timer)) + { + timer_start(&pplayer->jump_timer,MAX_JUMP_TIME); + + + /* Taking off? */ + + if (!issolid(pplayer->base.x, pplayer->base.y + 32) || + pplayer->base.ym != 0) + { + /* If they're not on the ground, or are currently moving + vertically, don't jump! */ + + pplayer->jumping = NO; + timer_stop(&pplayer->jump_timer); + } + else + { + /* Make sure we're not standing back up into a solid! */ + + if (pplayer->size == SMALL || pplayer->duck == NO || + !issolid(pplayer->base.x, pplayer->base.y)) + { + pplayer->jumping = YES; + + if (pplayer->size == SMALL) + play_sound(sounds[SND_JUMP], SOUND_CENTER_SPEAKER); + else + play_sound(sounds[SND_BIGJUMP], SOUND_CENTER_SPEAKER); + } + } + } + + /* Keep jumping for a while: */ + + if (timer_check(&pplayer->jump_timer)) + { + pplayer->base.ym = pplayer->base.ym - JUMP_SPEED * frame_ratio; + if (pplayer->base.ym < -YM_FOR_JUMP) + pplayer->base.ym = -YM_FOR_JUMP; + } + } + + void player_input(player_type *pplayer) + { + /* Handle key and joystick state: */ + + + if (pplayer->input.right == DOWN && pplayer->input.left == UP) + { + player_handle_horizontal_input(pplayer,RIGHT); + } + else if (pplayer->input.left == DOWN && pplayer->input.right == UP) + { + player_handle_horizontal_input(pplayer,LEFT); + } + + /* Jump/jumping? */ + + if ( pplayer->input.up == DOWN) + { + player_handle_vertical_input(pplayer); + } + else + timer_stop(&pplayer->jump_timer); + + /* Shoot! */ + + if (pplayer->input.fire == DOWN && pplayer->input.old_fire == UP && pplayer->got_coffee) + { + add_bullet(pplayer->base.x, pplayer->base.y, pplayer->base.xm, pplayer->dir); + } + + + /* Duck! */ + + if (pplayer->input.down == DOWN) + { + if (pplayer->size == BIG) + pplayer->duck = YES; + } + else + { + if (pplayer->size == BIG && pplayer->duck == YES) + { + /* Make sure we're not standing back up into a solid! */ + + if (!issolid(pplayer->base.x, pplayer->base.y - 32)) + pplayer->duck = NO; + } + else + pplayer->duck = NO; + } + + /* (Tux): */ + + if (pplayer->input.right == UP && pplayer->input.left == UP) + { + pplayer->frame_main = 1; + pplayer->frame = 1; + } + else + { + if ((pplayer->input.fire == DOWN && (frame % 2) == 0) || + (frame % 4) == 0) + pplayer->frame_main = (pplayer->frame_main + 1) % 4; + + pplayer->frame = pplayer->frame_main; + + if (pplayer->frame == 3) + pplayer->frame = 1; + } + + } + + void player_grabdistros(player_type *pplayer) + { + /* Grab distros: */ + if (!pplayer->dying) + { + trygrabdistro(pplayer->base.x, pplayer->base.y, NO_BOUNCE); + trygrabdistro(pplayer->base.x+ 31, pplayer->base.y, NO_BOUNCE); + + if (pplayer->size == BIG && !pplayer->duck) + { + trygrabdistro(pplayer->base.x, pplayer->base.y - 32, NO_BOUNCE); + trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32, NO_BOUNCE); + } + } + + + /* Enough distros for a One-up? */ + + if (distros >= DISTROS_LIFEUP) + { + distros = distros - DISTROS_LIFEUP; + if(pplayer->lives < MAX_LIVES) + pplayer->lives++; + /*We want to hear the sound even, if MAX_LIVES is reached*/ + play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER); + } + } + + void player_draw(player_type* pplayer) + { + + if (!timer_started(&pplayer->safe_timer) || (frame % 2) == 0) + { + if (pplayer->size == SMALL) + { + if (timer_started(&pplayer->invincible_timer)) + { + /* Draw cape: */ + + if (pplayer->dir == RIGHT) + { + texture_draw(&cape_right[frame % 2], + pplayer->base.x- scroll_x, pplayer->base.y, + NO_UPDATE); + } + else + { + texture_draw(&cape_left[frame % 2], + pplayer->base.x- scroll_x, pplayer->base.y, + NO_UPDATE); + } + } + + + if (!pplayer->got_coffee) + { + if (pplayer->dir == RIGHT) + { + texture_draw(&tux_right[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE); + } + else + { + texture_draw(&tux_left[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE); + } + } + else + { + /* Tux got coffee! */ + + if (pplayer->dir == RIGHT) + { + texture_draw(&firetux_right[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE); + } + else + { + texture_draw(&firetux_left[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE); + } + } + } + else + { + if (timer_started(&pplayer->invincible_timer)) + { + /* Draw cape: */ + + if (pplayer->dir == RIGHT) + { + texture_draw(&bigcape_right[frame % 2], + pplayer->base.x- scroll_x - 8 - 16, pplayer->base.y - 32, + NO_UPDATE); + } + else + { + texture_draw(&bigcape_left[frame % 2], + pplayer->base.x-scroll_x - 8, pplayer->base.y - 32, + NO_UPDATE); + } + } + + if (!pplayer->got_coffee) + { + if (!pplayer->duck) + { + if (!timer_started(&pplayer->skidding_timer)) + { + if (!pplayer->jumping || pplayer->base.ym > 0) + { + if (pplayer->dir == RIGHT) + { + texture_draw(&bigtux_right[pplayer->frame], + pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, + NO_UPDATE); + } + else + { + texture_draw(&bigtux_left[pplayer->frame], + pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, + NO_UPDATE); + } + } + else + { + if (pplayer->dir == RIGHT) + { + texture_draw(&bigtux_right_jump, + pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, + NO_UPDATE); + } + else + { + texture_draw(&bigtux_left_jump, + pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, + NO_UPDATE); + } + } + } + else + { + if (pplayer->dir == RIGHT) + { + texture_draw(&skidtux_right, + pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, + NO_UPDATE); + } + else + { + texture_draw(&skidtux_left, + pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, + NO_UPDATE); + } + } + } + else + { + if (pplayer->dir == RIGHT) + { + texture_draw(&ducktux_right, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16, + NO_UPDATE); + } + else + { + texture_draw(&ducktux_left, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16, + NO_UPDATE); + } + } + } + else + { + /* Tux has coffee! */ + + if (!pplayer->duck) + { + if (!timer_started(&pplayer->skidding_timer)) + { + if (!pplayer->jumping || pplayer->base.ym > 0) + { + if (pplayer->dir == RIGHT) + { + texture_draw(&bigfiretux_right[pplayer->frame], + pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, + NO_UPDATE); + } + else + { + texture_draw(&bigfiretux_left[pplayer->frame], + pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, + NO_UPDATE); + } + } + else + { + if (pplayer->dir == RIGHT) + { + texture_draw(&bigfiretux_right_jump, + pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, + NO_UPDATE); + } + else + { + texture_draw(&bigfiretux_left_jump, + pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, + NO_UPDATE); + } + } + } + else + { + if (pplayer->dir == RIGHT) + { + texture_draw(&skidfiretux_right, + pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, + NO_UPDATE); + } + else + { + texture_draw(&skidfiretux_left, + pplayer->base.x- scroll_x - 8, pplayer->base.y - 32, + NO_UPDATE); + } + } + } + else + { + if (pplayer->dir == RIGHT) + { + texture_draw(&duckfiretux_right, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16, + NO_UPDATE); + } + else + { + texture_draw(&duckfiretux_left, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16, + NO_UPDATE); + } + } + } + } + } + + } + + void player_collision(player_type* pplayer, void* p_c_object, int c_object) + { + bad_guy_type* pbad_c = NULL; + + switch (c_object) + { + case CO_BADGUY: + pbad_c = p_c_object; + /* Hurt the player if he just touched it: */ + + if (!pbad_c->dying && !pplayer->dying && + !timer_started(&pplayer->safe_timer) && + pbad_c->mode != HELD) + { + if (pbad_c->mode == FLAT && pplayer->input.fire != DOWN) + { + /* Kick: */ + + pbad_c->mode = KICK; + play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER); + + if (pplayer->base.x<= pbad_c->base.x) + { + pbad_c->dir = RIGHT; + pbad_c->base.x = pbad_c->base.x + 16; + } + else + { + pbad_c->dir = LEFT; + pbad_c->base.x = pbad_c->base.x - 16; + } + + timer_start(&pbad_c->timer,5000); + } + else if (pbad_c->mode == FLAT && pplayer->input.fire == DOWN) + { + pbad_c->mode = HELD; + pbad_c->base.y-=8; + } + else if (pbad_c->mode == KICK) + { + if (pplayer->base.y < pbad_c->base.y - 16 && + timer_started(&pbad_c->timer)) + { + /* Step on (stop being kicked) */ + + pbad_c->mode = FLAT; + play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER); + timer_start(&pbad_c->timer, 10000); + } + else + { + /* Hurt if you get hit by kicked laptop: */ + + if (timer_started(&pbad_c->timer)) + { + if (!timer_started(&pplayer->invincible_timer)) + { + player_kill(pplayer,SHRINK); + } + else + { + pbad_c->dying = FALLING; + pbad_c->base.ym = -8; + play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER); + } + } + } + } + else + { + if (!timer_started(&pplayer->invincible_timer )) + { + player_kill(pplayer,SHRINK); + } + else + { + pbad_c->dying = FALLING; + pbad_c->base.ym = -8; + play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER); + } + } + } + score_multiplier++; + break; + } + + } + + /* Kill Player! */ + + void player_kill(player_type* pplayer, int mode) + { + pplayer->base.ym = -5; + + play_sound(sounds[SND_HURT], SOUND_CENTER_SPEAKER); + + if (pplayer->dir == RIGHT) + pplayer->base.xm = -8; + else if (pplayer->dir == LEFT) + pplayer->base.xm = 8; + + if (mode == SHRINK && pplayer->size == BIG) + { + if (pplayer->got_coffee) + pplayer->got_coffee = NO; + + pplayer->size = SMALL; + + timer_start(&pplayer->safe_timer,TUX_SAFE_TIME); + } + else + { + pplayer->dying = 1; + } + } + + void player_dying(player_type *pplayer) + { + pplayer->base.ym = pplayer->base.ym + GRAVITY; + + /* He died :^( */ + + --pplayer->lives; + player_remove_powerups(pplayer); + pplayer->dying = NO; + + player_level_begin(pplayer); + + } + + /* Remove Tux's power ups */ + void player_remove_powerups(player_type* pplayer) + { + pplayer->got_coffee = NO; + pplayer->size = SMALL; + } + + void player_keep_in_bounds(player_type* pplayer) + { + /* Keep tux in bounds: */ + if (pplayer->base.x< 0) + pplayer->base.x= 0; + else if(pplayer->base.x< scroll_x) + pplayer->base.x= scroll_x; + else if (pplayer->base.x< 160 + scroll_x && scroll_x > 0 && debug_mode == YES) + { + scroll_x = pplayer->base.x- 160; + /*pplayer->base.x+= 160;*/ + + if(scroll_x < 0) + scroll_x = 0; + + } + else if (pplayer->base.x> screen->w / 2 + scroll_x && scroll_x < ((current_level.width * 32) - screen->w)) + { + /* Scroll the screen in past center: */ + + scroll_x = pplayer->base.x- screen->w / 2; + /*pplayer->base.x= 320 + scroll_x;*/ + + if (scroll_x > ((current_level.width * 32) - screen->w)) + scroll_x = ((current_level.width * 32) - screen->w); + } + else if (pplayer->base.x> 608 + scroll_x) + { + /* ... unless there's no more to scroll! */ + + /*pplayer->base.x= 608 + scroll_x;*/ + } + + /* Keep in-bounds, vertically: */ + + if (pplayer->base.y < 0) + pplayer->base.y = 0; + else if (pplayer->base.y > screen->h) + { + player_kill(&tux,KILL); + } + } diff --git a/src/player.h b/src/player.h index b9ee3aef2..1b3dc5549 100644 --- a/src/player.h +++ b/src/player.h @@ -19,6 +19,7 @@ #include "timer.h" #include "texture.h" #include "collision.h" +#include "sound.h" /* Times: */ diff --git a/src/scene.h b/src/scene.h index 0242e01cc..4304007e7 100644 --- a/src/scene.h +++ b/src/scene.h @@ -22,7 +22,7 @@ #include "level.h" #define FRAME_RATE 10 // 100 Frames per second (10ms) -int score, highscore, distros, level, next_level, game_pause, +int score, distros, level, next_level, game_pause, done, quit, score_multiplier, endpos, counting_distros, distro_counter; timer_type super_bkgd_timer; float scroll_x; @@ -45,6 +45,10 @@ player_type tux; SDL_Rect src, dest; texture_type img_box_full, img_box_empty, img_mints, img_coffee, img_super_bkgd, img_red_glow; st_level current_level; +unsigned int last_update_time; +unsigned int update_time; +timer_type time_left; +double frame_ratio; void add_score(int x, int y, int s); void set_defaults(void); diff --git a/src/screen.c b/src/screen.c index c01afc74d..b5bd3f893 100644 --- a/src/screen.c +++ b/src/screen.c @@ -66,7 +66,7 @@ void fillrect(float x, float y, float w, float h, float r, float g, float b) if(use_gl) { glBegin(GL_QUADS); - glColor3ub(r/256, g/256, b/256); + glColor3ub(r, g, b); glVertex2i(x, y); glVertex2i(x+w, y); glVertex2i(x+w, y+h); @@ -143,154 +143,6 @@ if(!use_gl) SDL_UpdateRect(scr, x, y, w, h); } -void drawtext(char * text, int x, int y, SDL_Surface * surf, int update, int shadowsize) -{ - /* i - helps to keep tracking of the all string length - j - helps to keep track of the length of the current line */ - int i, j, len; - char c; - SDL_Rect src, dest; - - len = strlen(text); - - /* For each letter in the string... */ - - for (i = 0; i < len; ++i) - { - /* Set source rectangle: */ - - c = text[i]; - - if (c >= 'A' && c <= 'Z') - { - /* Capital letter - first row: */ - - src.x = (c - 'A') * 16; - src.y = 0; - } - else if (c >= 'a' && c <= 'z') - { - /* Lowercase letter - first row: */ - - src.x = (c - 'a') * 16; - src.y = 16; - } - else if (c >= '!' && c <= '9') - { - /* Punctuation (except '?') or number - third row: */ - - src.x = (c - '!') * 16; - src.y = 32; - } - else if (c == '?') - { - /* Question mark - third row, last character: */ - - src.x = 400; - src.y = 24; - } - else if (c == '\n') /* support for multi-lines */ - { - j = i + 1; - y += 18; - continue; - } - else - src.x = -1; - - src.w = 16; - src.h = 16; - - - /* Draw character: */ - - if (src.x != -1) - { - /* Set destination rectangle for shadow: */ - - dest.x = x + (i * 16) + shadowsize; - dest.y = y + shadowsize; - dest.w = src.w; - dest.h = src.h; - - - /* Shadow: */ - - SDL_BlitSurface(letters_black, &src, screen, &dest); - - - /* Set destination rectangle for text: */ - - dest.x = x + (i * 16); - dest.y = y; - dest.w = src.w; - dest.h = src.h; - - - /* Shadow: */ - - SDL_BlitSurface(surf, &src, screen, &dest); - - -/* FIXME: Text doesn't work in OpenGL mode, below is experimental code */ -/* - - dest.x = 0; - dest.y = 0; - dest.w = src.w; - - dest.h = src.h; - - temp = SDL_CreateRGBSurface(SDL_SWSURFACE, dest.w, dest.h, 32, -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); -#else - 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); -#endif - SDL_BlitSurface(letters_black, &src, temp, NULL); - texture_type xyz; - texture_from_sdl_surface(&xyz,temp,IGNORE_ALPHA); - texture_draw(&xyz,x + (i * 16) + shadowsize,y + shadowsize, update); - texture_free(&xyz); - / * Set destination rectangle for text: * / - - dest.x = x + (i * 16); - dest.y = y; - dest.w = src.w; - dest.h = src.h; - - / * Text: * / - - SDL_BlitSurface(surf, &src, temp, NULL); - texture_from_sdl_surface(&xyz,temp,IGNORE_ALPHA); - SDL_FreeSurface(temp); - texture_draw(&xyz,x + (i * 16) + shadowsize,y + shadowsize, update); - texture_free(&xyz);*/ - } - } - - - /* Update */ - - if (update == UPDATE) - { - dest.w = len * 16 + 1; - - if (dest.w > screen->w) - dest.w = screen->w; - - update_rect(screen, x, y, dest.w, 17); - } - -} - - -/* --- DRAW HORIZONTALLY-CENTERED TEXT: --- */ - -void drawcenteredtext(char * text, int y, SDL_Surface * surf, int update, int shadowsize) -{ - drawtext(text, screen->w / 2 - (strlen(text) * 8), y, surf, update, shadowsize); -} /* --- ERASE TEXT: --- */ diff --git a/src/screen.h b/src/screen.h index 0cd53ec24..78f633650 100644 --- a/src/screen.h +++ b/src/screen.h @@ -7,9 +7,12 @@ bill@newbreedsoftware.com http://www.newbreedsoftware.com/supertux/ - April 11, 2000 - April 21, 2000 + April 11, 2000 - February 1, 2004 */ +#ifndef SUPERTUX_SCREEN_H +#define SUPERTUX_SCREEN_H + #include #ifndef NOOPENGL #include @@ -33,13 +36,8 @@ void fillrect(float x, float y, float w, float h, float r, float g, float b); void updatescreen(void); void flipscreen(void); SDL_Surface * load_image(char * file, int use_alpha); -/* -void drawimage(SDL_Surface * surf, float x, float y, int update); -void drawpart(SDL_Surface * surf, float x, float y, float w, float h, 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); void update_rect(SDL_Surface *scr, Sint32 x, Sint32 y, Sint32 w, Sint32 h); +#endif /*SUPERTUX_SCREEN_H*/ diff --git a/src/setup.c b/src/setup.c index 23cebe51c..d7b67f6cb 100644 --- a/src/setup.c +++ b/src/setup.c @@ -7,7 +7,7 @@ bill@newbreedsoftware.com http://www.newbreedsoftware.com/supertux/ - April 11, 2000 - January 1st, 2004 + April 11, 2000 - February 1st, 2004 */ #include @@ -96,25 +96,16 @@ void st_general_setup(void) srand(SDL_GetTicks()); /* Load global images: */ - - letters_black = load_image(DATA_PREFIX "/images/status/letters-black.png", - USE_ALPHA); - - letters_gold = load_image(DATA_PREFIX "/images/status/letters-gold.png", - USE_ALPHA);/* - if (tux_x < 0) - tux_x = 0;*/ - - letters_blue = load_image(DATA_PREFIX "/images/status/letters-blue.png", - USE_ALPHA); - - letters_red = load_image(DATA_PREFIX "/images/status/letters-red.png", - USE_ALPHA); - - + + text_load(&black_text,DATA_PREFIX "/images/status/letters-black.png"); + text_load(&gold_text,DATA_PREFIX "/images/status/letters-gold.png"); + text_load(&blue_text,DATA_PREFIX "/images/status/letters-blue.png"); + text_load(&red_text,DATA_PREFIX "/images/status/letters-red.png"); + /* Set icon image: */ seticon(); + SDL_EnableUNICODE(1); } @@ -189,7 +180,7 @@ void st_video_setup_gl(void) SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - + if (use_fullscreen == YES) { screen = SDL_SetVideoMode(640, 480, 32, SDL_FULLSCREEN | SDL_OPENGL ) ; /* | SDL_HWSURFACE); */ @@ -216,18 +207,8 @@ void st_video_setup_gl(void) exit(1); } } - - /* Initialisierung von OpenGL * / - glViewport(0, 0, screen->w, screen->h); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0, screen->w, screen->h, 0, -1.0, 1.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -*/ - /* + + /* * Set up OpenGL for 2D rendering. */ glDisable(GL_DEPTH_TEST); @@ -241,7 +222,7 @@ void st_video_setup_gl(void) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, 0.0f, 0.0f); - + #endif } @@ -346,7 +327,7 @@ void st_audio_setup(void) if (audio_device == YES) { - if (open_audio(44100, AUDIO_S16, 2, 512) < 0) + if (open_audio(44100, AUDIO_S16, 2, 2048) < 0) { /* only print out message if sound or music was not disabled at command-line diff --git a/src/special.c b/src/special.c index 1242841a1..e3993798c 100644 --- a/src/special.c +++ b/src/special.c @@ -4,7 +4,7 @@ // Description: // // -// Author: Tobias Glaesser , (C) 2004 +// Author: Tobias Glaesser & Bill Kendrick, (C) 2004 // // Copyright: See COPYING file that comes with this distribution // @@ -29,7 +29,6 @@ void bullet_init(bullet_type* pbullet, float x, float y, float xm, int dir) { pbullet->base.width = 4; pbullet->base.height = 4; - pbullet->base.updated = SDL_GetTicks(); pbullet->base.alive = YES; if (dir == RIGHT) @@ -49,9 +48,6 @@ void bullet_init(bullet_type* pbullet, float x, float y, float xm, int dir) void bullet_action(bullet_type* pbullet) { - - double frame_ratio = get_frame_ratio(&pbullet->base); - if (pbullet->base.alive) { pbullet->base.x = pbullet->base.x + pbullet->base.xm * frame_ratio; @@ -112,12 +108,10 @@ void upgrade_init(upgrade_type *pupgrade, float x, float y, int kind) pupgrade->base.xm = 2; pupgrade->base.ym = -2; pupgrade->base.height = 0; - pupgrade->base.updated = SDL_GetTicks(); } void upgrade_action(upgrade_type *pupgrade) { - double frame_ratio = get_frame_ratio(&pupgrade->base); if (pupgrade->base.alive) { @@ -125,7 +119,9 @@ void upgrade_action(upgrade_type *pupgrade) { /* Rise up! */ - pupgrade->base.height++; + pupgrade->base.height = pupgrade->base.height + 0.7 * frame_ratio; + if(pupgrade->base.height > 32) + pupgrade->base.height = 32; } else { @@ -148,7 +144,7 @@ void upgrade_action(upgrade_type *pupgrade) } else if (pupgrade->kind == UPGRADE_HERRING) { - pupgrade->base.ym = -24; + pupgrade->base.ym = -8; } pupgrade->base.y = (int)(pupgrade->base.y / 32) * 32; @@ -253,7 +249,7 @@ void upgrade_collision(upgrade_type* pupgrade, void* p_c_object, int c_object) else if (pupgrade->kind == UPGRADE_HERRING) { play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER); - timer_start(&tux.invincible_timer,TUX_INVINCIBLE_TIME); + timer_start(&pplayer->invincible_timer,TUX_INVINCIBLE_TIME); timer_start(&super_bkgd_timer, 250); /* play the herring song ^^ */ if (current_music != HURRYUP_MUSIC) diff --git a/src/special.h b/src/special.h index 2c9661e89..dfd9b1da9 100644 --- a/src/special.h +++ b/src/special.h @@ -21,6 +21,7 @@ #include "type.h" #include "texture.h" #include "collision.h" +#include "player.h" typedef struct upgrade_type { diff --git a/src/texture.c b/src/texture.c index 19a9f7484..a3b093076 100644 --- a/src/texture.c +++ b/src/texture.c @@ -1,7 +1,7 @@ // // C Implementation: texture // -// Description: +// Description: // // // Author: Tobias Glaesser , (C) 2004 @@ -20,115 +20,163 @@ void texture_setup(void) { #ifdef NOOPENGL -texture_load = texture_load_sdl; -texture_free = texture_free_sdl; -texture_draw = texture_draw_sdl; -texture_draw_bg = texture_draw_bg_sdl; -texture_draw_part = texture_draw_part_sdl; + texture_load = texture_load_sdl; + texture_load_part = texture_load_part_sdl; + texture_free = texture_free_sdl; + texture_draw = texture_draw_sdl; + texture_draw_bg = texture_draw_bg_sdl; + texture_draw_part = texture_draw_part_sdl; #else -if(use_gl) -{ -texture_load = texture_load_gl; -texture_free = texture_free_gl; -texture_draw = texture_draw_gl; -texture_draw_bg = texture_draw_bg_gl; -texture_draw_part = texture_draw_part_gl; -} -else -{ -texture_load = texture_load_sdl; -texture_free = texture_free_sdl; -texture_draw = texture_draw_sdl; -texture_draw_bg = texture_draw_bg_sdl; -texture_draw_part = texture_draw_part_sdl; -} + + if(use_gl) + { + texture_load = texture_load_gl; + texture_load_part = texture_load_part_gl; + texture_free = texture_free_gl; + texture_draw = texture_draw_gl; + texture_draw_bg = texture_draw_bg_gl; + texture_draw_part = texture_draw_part_gl; + } + else + { + texture_load = texture_load_sdl; + texture_load_part = texture_load_part_sdl; + texture_free = texture_free_sdl; + texture_draw = texture_draw_sdl; + texture_draw_bg = texture_draw_bg_sdl; + texture_draw_part = texture_draw_part_sdl; + } #endif } #ifndef NOOPENGL void texture_load_gl(texture_type* ptexture, char * file, int use_alpha) { -texture_load_sdl(ptexture,file,use_alpha); -texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture); + texture_load_sdl(ptexture,file,use_alpha); + texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture); } -void texture_draw_gl(texture_type* ptexture, float x, float y, int update) +void texture_load_part_gl(texture_type* ptexture, char * file, int x, int y, int w, int h, int use_alpha) { - glColor4ub(255, 255, 255,255); - glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - glEnable (GL_BLEND); - glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture); - - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2f(x, y); - glTexCoord2f((float)ptexture->w, 0); - glVertex2f((float)ptexture->w+x, y); - glTexCoord2f((float)ptexture->w, (float)ptexture->h); - glVertex2f((float)ptexture->w+x, (float)ptexture->h+y); - glTexCoord2f(0, (float)ptexture->h); - glVertex2f(x, (float)ptexture->h+y); - glEnd(); + texture_load_part_sdl(ptexture,file,x,y,w,h,use_alpha); + texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture); } -void texture_draw_bg_gl(texture_type* ptexture, int update) +void texture_draw_gl(texture_type* ptexture, float x, float y, int update) { - //glColor3ub(255, 255, 255); - glEnable(GL_TEXTURE_RECTANGLE_NV); - glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); glVertex2f(0, 0); - glTexCoord2f((float)ptexture->w, 0); glVertex2f(screen->w, 0); - glTexCoord2f((float)ptexture->w, (float)ptexture->h); glVertex2f(screen->w, screen->h); - glTexCoord2f(0, (float)ptexture->h); glVertex2f(0, screen->h); - glEnd(); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glColor4ub(255, 255, 255,255); + + glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture); + + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2f(x, y); + glTexCoord2f((float)ptexture->w, 0); + glVertex2f((float)ptexture->w+x, y); + glTexCoord2f((float)ptexture->w, (float)ptexture->h); + glVertex2f((float)ptexture->w+x, (float)ptexture->h+y); + glTexCoord2f(0, (float)ptexture->h); + glVertex2f(x, (float)ptexture->h+y); + glEnd(); + + glDisable(GL_BLEND); +} + +void texture_draw_bg_gl(texture_type* ptexture, int update) +{ + glColor3ub(255, 255, 255); + + glEnable(GL_TEXTURE_RECTANGLE_NV); + glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture); + + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2f(0, 0); + glTexCoord2f((float)ptexture->w, 0); + glVertex2f(screen->w, 0); + glTexCoord2f((float)ptexture->w, (float)ptexture->h); + glVertex2f(screen->w, screen->h); + glTexCoord2f(0, (float)ptexture->h); + glVertex2f(0, screen->h); + glEnd(); } -void texture_draw_part_gl(texture_type* ptexture, float x, float y, float w, float h, int update) +void texture_draw_part_gl(texture_type* ptexture,float sx, float sy, float x, float y, float w, float h, int update) { - glColor3ub(255, 255, 255); - - glEnable(GL_TEXTURE_RECTANGLE_NV); - glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture); - - glBegin(GL_QUADS); - glTexCoord2f(x, y); - glVertex2f(x, y); - glTexCoord2f(x+w, y); - glVertex2f(w+x, y); - glTexCoord2f(x+w, y+h); - glVertex2f(w+x, h+y); - glTexCoord2f(x, y+h); - glVertex2f(x, h+y); - glEnd(); + + glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glColor4ub(255, 255, 255,255); + + glEnable(GL_TEXTURE_RECTANGLE_NV); + + + glBegin(GL_QUADS); + glTexCoord2f(x, y); + glVertex2f(x, y); + glTexCoord2f(x+w, y); + glVertex2f(w+x, y); + glTexCoord2f(x+w, y+h); + glVertex2f(w+x, h+y); + glTexCoord2f(x, y+h); + glVertex2f(x, h+y); + glEnd(); + + glDisable(GL_BLEND); + } void texture_create_gl(SDL_Surface * surf, GLint * tex) { -SDL_Surface *conv; -conv = SDL_CreateRGBSurface(SDL_SWSURFACE , surf->w, surf->h, 32, + Uint32 saved_flags; + Uint8 saved_alpha; + + SDL_Surface *conv; + conv = SDL_CreateRGBSurface(surf->flags, surf->w, surf->h, surf->format->BitsPerPixel, #if SDL_BYTEORDER == SDL_BIG_ENDIAN - 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); + 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); #else - 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); + + 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); #endif - SDL_BlitSurface(surf, 0, conv, 0); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - + + /* Save the alpha blending attributes */ + saved_flags = surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); + saved_alpha = surf->format->alpha; + if ( (saved_flags & SDL_SRCALPHA) + == SDL_SRCALPHA ) + { + SDL_SetAlpha(surf, 0, 0); + } + + SDL_BlitSurface(surf, 0, conv, 0); + + /* Restore the alpha blending attributes */ + if ( (saved_flags & SDL_SRCALPHA) + == SDL_SRCALPHA ) + { + SDL_SetAlpha(surf, saved_flags, saved_alpha); + } + + glGenTextures(1, &*tex); - glBindTexture(GL_TEXTURE_RECTANGLE_NV , *tex); - glEnable(GL_TEXTURE_RECTANGLE_NV); - glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel); - glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 3, conv->w, conv->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels); - //glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 0, 0, 0, 0, conv->w, conv->h); - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - SDL_FreeSurface(conv); + glBindTexture(GL_TEXTURE_RECTANGLE_NV , *tex); + glEnable(GL_TEXTURE_RECTANGLE_NV); + glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel); + glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB10_A2, conv->w, conv->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + SDL_FreeSurface(conv); } void texture_free_gl(texture_type* ptexture) @@ -162,15 +210,65 @@ void texture_load_sdl(texture_type* ptexture, char * file, int use_alpha) } -void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface* sdl_surf, int use_alpha) +void texture_load_part_sdl(texture_type* ptexture, char * file, int x, int y, int w, int h, int use_alpha) { - /* SDL_Surface * temp; + SDL_Rect src; + SDL_Surface * temp; + SDL_Surface * conv; temp = IMG_Load(file); if (temp == NULL) - st_abort("Can't load", file);*/ + st_abort("Can't load", file); + + /* Set source rectangle for conv: */ + + src.x = x; + src.y = y; + src.w = w; + src.h = h; + + conv = SDL_CreateRGBSurface(temp->flags, w, h, temp->format->BitsPerPixel, + temp->format->Rmask, + temp->format->Gmask, + temp->format->Bmask, + temp->format->Amask); + + /* #if SDL_BYTEORDER == SDL_BIG_ENDIAN + 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); + #else + + 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); + #endif*/ + + SDL_SetAlpha(temp,0,0); + + SDL_BlitSurface(temp, &src, conv, NULL); + ptexture->sdl_surface = SDL_DisplayFormatAlpha(conv); + + if (ptexture->sdl_surface == NULL) + st_abort("Can't covert to display format", file); + + if (use_alpha == IGNORE_ALPHA) + SDL_SetAlpha(ptexture->sdl_surface, 0, 0); + + SDL_FreeSurface(temp); + SDL_FreeSurface(conv); + + ptexture->w = ptexture->sdl_surface->w; + ptexture->h = ptexture->sdl_surface->h; +} + +void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface* sdl_surf, int use_alpha) +{ + + /* SDL_Surface * temp; + + temp = IMG_Load(file); + + if (temp == NULL) + st_abort("Can't load", file);*/ ptexture->sdl_surface = SDL_DisplayFormatAlpha(sdl_surf); @@ -183,64 +281,65 @@ void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface* sdl_surf, int ptexture->w = ptexture->sdl_surface->w; ptexture->h = ptexture->sdl_surface->h; - #ifndef NOOPENGL +#ifndef NOOPENGL + if(use_gl) { texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture); } - #endif +#endif } void texture_draw_sdl(texture_type* ptexture, float x, float y, int update) { - SDL_Rect dest; + SDL_Rect dest; - dest.x = x; - dest.y = y; - dest.w = ptexture->w; - dest.h = ptexture->h; + dest.x = x; + dest.y = y; + dest.w = ptexture->w; + dest.h = ptexture->h; - SDL_BlitSurface(ptexture->sdl_surface, NULL, screen, &dest); + SDL_BlitSurface(ptexture->sdl_surface, NULL, screen, &dest); - if (update == UPDATE) - SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h); + if (update == UPDATE) + SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h); } void texture_draw_bg_sdl(texture_type* ptexture, int update) { SDL_Rect dest; - + dest.x = 0; dest.y = 0; dest.w = screen->w; dest.h = screen->h; - + SDL_BlitSurface(ptexture->sdl_surface, NULL, screen, &dest); - + if (update == UPDATE) SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h); } -void texture_draw_part_sdl(texture_type* ptexture, float x, float y, float w, float h, int update) +void texture_draw_part_sdl(texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, int update) { - SDL_Rect src, dest; + SDL_Rect src, dest; - src.x = x; - src.y = y; - src.w = w; - src.h = h; + src.x = sx; + src.y = sy; + src.w = w; + src.h = h; - dest.x = x; - dest.y = y; - dest.w = w; - dest.h = h; + dest.x = x; + dest.y = y; + dest.w = w; + dest.h = h; - SDL_BlitSurface(ptexture->sdl_surface, &src, screen, &dest); + SDL_BlitSurface(ptexture->sdl_surface, &src, screen, &dest); - if (update == UPDATE) - update_rect(screen, dest.x, dest.y, dest.w, dest.h); + if (update == UPDATE) + update_rect(screen, dest.x, dest.y, dest.w, dest.h); } void texture_free_sdl(texture_type* ptexture) diff --git a/src/texture.h b/src/texture.h index b85eb5cbc..0448d0e5b 100644 --- a/src/texture.h +++ b/src/texture.h @@ -30,22 +30,25 @@ texture_type; void texture_setup(void); void (*texture_load) (texture_type* ptexture, char * file, int use_alpha); +void (*texture_load_part) (texture_type* ptexture, char * file, int x, int y, int w, int h, int use_alpha); void (*texture_free) (texture_type* ptexture); void (*texture_draw) (texture_type* ptexture, float x, float y, int update); void (*texture_draw_bg) (texture_type* ptexture, int update); -void (*texture_draw_part) (texture_type* ptexture, float x, float y, float w, float h, int update); +void (*texture_draw_part) (texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, int update); void texture_load_sdl(texture_type* ptexture, char * file, int use_alpha); +void texture_load_part_sdl(texture_type* ptexture, char * file, int x, int y, int w, int h, int use_alpha); void texture_free_sdl(texture_type* ptexture); void texture_draw_sdl(texture_type* ptexture, float x, float y, int update); void texture_draw_bg_sdl(texture_type* ptexture, int update); -void texture_draw_part_sdl(texture_type* ptexture, float x, float y, float w, float h, int update); +void texture_draw_part_sdl(texture_type* ptexture,float sx, float sy, float x, float y, float w, float h, int update); void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface * sdl_surf, int use_alpha); #ifndef NOOPENGL void texture_load_gl(texture_type* ptexture, char * file, int use_alpha); +void texture_load_part_gl(texture_type* ptexture, char * file, int x, int y, int w, int h, int use_alpha); void texture_free_gl(texture_type* ptexture); void texture_draw_gl(texture_type* ptexture, float x, float y, int update); void texture_draw_bg_gl(texture_type* ptexture, int update); -void texture_draw_part_gl(texture_type* ptexture, float x, float y, float w, float h, int update); +void texture_draw_part_gl(texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, int update); void texture_create_gl(SDL_Surface * surf, GLint * tex); #endif diff --git a/src/timer.c b/src/timer.c index 22b43d53a..41b60d1df 100644 --- a/src/timer.c +++ b/src/timer.c @@ -14,6 +14,31 @@ #include "defines.h" #include "timer.h" +unsigned int st_get_ticks(void) +{ +if(st_pause_count != 0) +return SDL_GetTicks() - st_pause_ticks - SDL_GetTicks() + st_pause_count; +else +return SDL_GetTicks() - st_pause_ticks; +} + +void st_pause_ticks_init(void) +{ +st_pause_ticks = 0; +st_pause_count = 0; +} + +void st_pause_ticks_start(void) +{ +st_pause_count = SDL_GetTicks(); +} + +void st_pause_ticks_stop(void) +{ +st_pause_ticks += SDL_GetTicks() - st_pause_count; +st_pause_count = 0; +} + void timer_init(timer_type* ptimer) { ptimer->period = 0; @@ -22,7 +47,7 @@ void timer_init(timer_type* ptimer) void timer_start(timer_type* ptimer, unsigned int period) { - ptimer->time = SDL_GetTicks(); + ptimer->time = st_get_ticks(); ptimer->period = period; } @@ -33,7 +58,7 @@ void timer_stop(timer_type* ptimer) int timer_check(timer_type* ptimer) { - if(ptimer->time != 0 && ptimer->time + ptimer->period > SDL_GetTicks()) + if((ptimer->time != 0) && (ptimer->time + ptimer->period > st_get_ticks())) return YES; else { @@ -52,10 +77,10 @@ int timer_started(timer_type* ptimer) int timer_get_left(timer_type* ptimer) { - return (ptimer->period - (SDL_GetTicks() - ptimer->time)); + return (ptimer->period - (st_get_ticks() - ptimer->time)); } int timer_get_gone(timer_type* ptimer) { - return (SDL_GetTicks() - ptimer->time); + return (st_get_ticks() - ptimer->time); } diff --git a/src/timer.h b/src/timer.h index 8a0cf4042..e99aa1dad 100644 --- a/src/timer.h +++ b/src/timer.h @@ -21,11 +21,33 @@ typedef struct timer_type } timer_type; +unsigned int st_pause_ticks; +unsigned int st_pause_count; + +unsigned int st_get_ticks(void); +void st_pause_ticks_init(void); +void st_pause_ticks_start(void); +void st_pause_ticks_stop(void); void timer_init(timer_type* ptimer); void timer_start(timer_type* ptimer, unsigned int period); void timer_stop(timer_type* ptimer); +/*====================================================================== + int timer_check(timer_type* ptimer); + + param : pointer to a timer which needs to be checked + return: NO = the timer is not started + or it is over + YES = otherwise +======================================================================*/ int timer_check(timer_type* ptimer); int timer_started(timer_type* ptimer); +/*====================================================================== + int timer_get_left(timer_type* ptimer); + + param : pointer to a timer that you want to get the time left + return: the time left (in millisecond) + note : the returned value can be negative +======================================================================*/ int timer_get_left(timer_type* ptimer); int timer_get_gone(timer_type* ptimer); diff --git a/src/title.c b/src/title.c index a2c464bd8..39a99b906 100644 --- a/src/title.c +++ b/src/title.c @@ -41,7 +41,7 @@ int title(void) texture_type title, anim1, anim2; SDL_Event event; SDLKey key; - int done, quit, frame, pict, last_highscore; + int done, quit, frame, pict; char str[80]; game_started = 0; @@ -74,9 +74,11 @@ 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, 1); + load_hs(); + sprintf(str, "High score: %d", hs_score); + text_drawf(&gold_text, str, 0, -40, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE); + sprintf(str, "by %s", hs_name); + text_drawf(&gold_text, str, 0, -20, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE); while (!done && !quit) { @@ -100,7 +102,7 @@ int title(void) key = event.key.keysym.sym; /* Check for menu events */ - menu_event(key); + menu_event(&event.key.keysym); if (key == SDLK_ESCAPE) { @@ -135,8 +137,11 @@ int title(void) texture_draw_bg(&title, NO_UPDATE); /* Draw the high score: */ - sprintf(str, "High score: %d", last_highscore); - drawcenteredtext(str, 460, letters_red, NO_UPDATE, 1); + sprintf(str, "High score: %d", hs_score); + text_drawf(&gold_text, str, 0, -40, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE); + sprintf(str, "by %s", hs_name); + text_drawf(&gold_text, str, 0, -20, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE); + } /* Don't draw menu, if quit is true */ @@ -151,12 +156,12 @@ int title(void) pict = (frame / 5) % 3; if (pict == 0) - texture_draw_part(&title, 560, 270, 80, 75, NO_UPDATE); + texture_draw_part(&title, 560, 270, 560, 270, 80, 75, NO_UPDATE); else if (pict == 1) texture_draw(&anim1, 560, 270, NO_UPDATE); else if (pict == 2) texture_draw(&anim2, 560, 270, NO_UPDATE); - + flipscreen(); /* Pause: */ diff --git a/src/type.c b/src/type.c index 1d230c21a..d6f9347b8 100644 --- a/src/type.c +++ b/src/type.c @@ -18,10 +18,4 @@ #include "type.h" #include "scene.h" -double get_frame_ratio(base_type* pbase) -{ - unsigned int cur_time = SDL_GetTicks(); - double frame_ratio = ((double)(cur_time-pbase->updated))/((double)FRAME_RATE); - pbase->updated = cur_time; - return (frame_ratio == 0 ? 1 : frame_ratio); -} + diff --git a/src/type.h b/src/type.h index 9038afe01..f2d472bf3 100644 --- a/src/type.h +++ b/src/type.h @@ -26,11 +26,10 @@ typedef struct base_type float ym; float width; float height; - int updated; } base_type; -double get_frame_ratio(base_type* pbase); +//double get_frame_ratio(base_type* pbase); #endif /*SUPERTUX_TYPE_H*/ diff --git a/src/world.c b/src/world.c index 3b44d02d4..e664e147b 100644 --- a/src/world.c +++ b/src/world.c @@ -59,13 +59,10 @@ void broken_brick_init(broken_brick_type* pbroken_brick, float x, float y, float pbroken_brick->base.xm = xm; pbroken_brick->base.ym = ym; timer_start(&pbroken_brick->timer,200); - pbroken_brick->base.updated = SDL_GetTicks(); } void broken_brick_action(broken_brick_type* pbroken_brick) { - double frame_ratio = get_frame_ratio(&pbroken_brick->base); - if (pbroken_brick->base.alive) { pbroken_brick->base.x = pbroken_brick->base.x + pbroken_brick->base.xm * frame_ratio; @@ -102,14 +99,11 @@ void bouncy_brick_init(bouncy_brick_type* pbouncy_brick, float x, float y) pbouncy_brick->offset = 0; pbouncy_brick->offset_m = -BOUNCY_BRICK_SPEED; pbouncy_brick->shape = shape(x, y); - pbouncy_brick->base.updated = SDL_GetTicks(); } void bouncy_brick_action(bouncy_brick_type* pbouncy_brick) { - - double frame_ratio = get_frame_ratio(&pbouncy_brick->base); - + if (pbouncy_brick->base.alive) { @@ -141,10 +135,8 @@ void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick) dest.w = 32; dest.h = 32; - SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, - current_level.bkgd_red, - current_level.bkgd_green, - current_level.bkgd_blue)); + fillrect(pbouncy_brick->base.x - scroll_x,pbouncy_brick->base.y,32,32,current_level.bkgd_red,current_level.bkgd_green, + current_level.bkgd_blue); drawshape(pbouncy_brick->base.x - scroll_x, pbouncy_brick->base.y + pbouncy_brick->offset, @@ -160,14 +152,10 @@ void floating_score_init(floating_score_type* pfloating_score, float x, float y, pfloating_score->base.y = y - 16; timer_start(&pfloating_score->timer,1000); pfloating_score->value = s; - pfloating_score->base.updated = SDL_GetTicks(); - } void floating_score_action(floating_score_type* pfloating_score) { -double frame_ratio = get_frame_ratio(&pfloating_score->base); - if (pfloating_score->base.alive) { pfloating_score->base.y = pfloating_score->base.y - 2 * frame_ratio; @@ -183,10 +171,7 @@ void floating_score_draw(floating_score_type* pfloating_score) { char str[10]; sprintf(str, "%d", pfloating_score->value); - drawtext(str, - pfloating_score->base.x + 16 - strlen(str) * 8, - pfloating_score->base.y, - letters_gold, NO_UPDATE, 1); + text_draw(&gold_text, str, pfloating_score->base.x + 16 - strlen(str) * 8, pfloating_score->base.y, 1, NO_UPDATE); } } -- 2.11.0