From b9511e761c02a52392c2291c4877609bfbe15400 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Gl=C3=A4=C3=9Fer?= Date: Mon, 8 Mar 2004 15:17:56 +0000 Subject: [PATCH] fixed game load/save SVN-Revision: 191 --- src/gameloop.c | 68 ++++++++++++++++++++++++++++-------------------------- src/setup.c | 6 ++++- src/timer.c | 73 +++++++++++++++++++++++++++++++++++++++++++--------------- src/timer.h | 2 ++ src/title.c | 17 ++++++++++---- 5 files changed, 109 insertions(+), 57 deletions(-) diff --git a/src/gameloop.c b/src/gameloop.c index 04043f896..446852e39 100644 --- a/src/gameloop.c +++ b/src/gameloop.c @@ -305,18 +305,18 @@ int game_action(void) level++; next_level = 0; if(st_gl_mode != ST_GL_TEST) - { - drawresultscreen(); - } - else - { - level_free_gfx(); + { + drawresultscreen(); + } + else + { + level_free_gfx(); level_free(¤t_level); level_free_song(); unloadshared(); arrays_free(); return(0); - } + } player_level_begin(&tux); } else @@ -350,7 +350,7 @@ int game_action(void) set_defaults(); level_free(¤t_level); if(level_load(¤t_level,level_subset,level) != 0) - exit(1); + return 0; arrays_free(); arrays_init(); activate_bad_guys(); @@ -564,27 +564,23 @@ int gameloop(char * subset, int levelnb, int mode) timer_type fps_timer, frame_timer; timer_init(&fps_timer, YES); timer_init(&frame_timer, YES); - + game_started = YES; st_gl_mode = mode; level = levelnb; strcpy(level_subset,subset); - if(st_gl_mode != ST_GL_LOAD_GAME) - { - /* Init the game: */ - arrays_init(); - set_defaults(); + /* Init the game: */ + arrays_init(); + set_defaults(); - if(level_load(¤t_level,level_subset,level) != 0) - exit(1); - level_load_gfx(¤t_level); - activate_bad_guys(); - level_load_song(¤t_level); + if(level_load(¤t_level,level_subset,level) != 0) + exit(1); + level_load_gfx(¤t_level); + activate_bad_guys(); + level_load_song(¤t_level); - } - player_init(&tux); if(st_gl_mode != ST_GL_TEST) @@ -596,7 +592,7 @@ int gameloop(char * subset, int levelnb, int mode) levelintro(); - timer_init(&time_left,YES); + timer_init(&time_left,YES); start_timers(); if(st_gl_mode == ST_GL_LOAD_GAME) @@ -640,7 +636,7 @@ int gameloop(char * subset, int levelnb, int mode) /* Handle events: */ tux.input.old_fire = tux.input.fire; - + game_event(); if(show_menu) @@ -1742,9 +1738,15 @@ void savegame(int slot) fwrite(&level,sizeof(int),1,fi); fwrite(&score,sizeof(int),1,fi); fwrite(&distros,sizeof(int),1,fi); - fwrite(&tux,sizeof(player_type),1,fi); fwrite(&scroll_x,sizeof(float),1,fi); - fwrite(&time_left,sizeof(float),1,fi); + fwrite(&tux,sizeof(player_type),1,fi); + timer_fwrite(&tux.invincible_timer,fi); + printf("Time inv LEFT: %d\n",timer_get_left(&tux.invincible_timer)); + timer_fwrite(&tux.skidding_timer,fi); + timer_fwrite(&tux.safe_timer,fi); + timer_fwrite(&tux.frame_timer,fi); + timer_fwrite(&time_left,fi); + printf("Time LEFT: %d\n",timer_get_left(&time_left)); ui = st_get_ticks(); fwrite(&ui,sizeof(int),1,fi); } @@ -1789,20 +1791,20 @@ void loadgame(int slot) level_free_song(); level_load_song(¤t_level); levelintro(); - timer_start(&time_left,current_level.time_left*1000); update_time = st_get_ticks(); fread(&score,sizeof(int),1,fi); fread(&distros,sizeof(int),1,fi); - fread(&tux,sizeof(player_type),1,fi); fread(&scroll_x,sizeof(float),1,fi); - fread(&time_left,sizeof(float),1,fi); + fread(&tux,sizeof(player_type),1,fi); + timer_fread(&tux.invincible_timer,fi); + printf("Time inv LEFT: %d - %d\n",timer_get_left(&tux.invincible_timer),tux.invincible_timer.time); + timer_fread(&tux.skidding_timer,fi); + timer_fread(&tux.safe_timer,fi); + timer_fread(&tux.frame_timer,fi); + timer_fread(&time_left,fi); + printf("Time LEFT: %d\n",timer_get_left(&time_left)); fread(&ui,sizeof(int),1,fi); - time_left.time += st_get_ticks() - ui; - tux.invincible_timer.time += st_get_ticks() - ui; - tux.skidding_timer.time += st_get_ticks() - ui; - tux.safe_timer.time += st_get_ticks() - ui; - tux.vphysic.start_time += st_get_ticks() - ui; tux.hphysic.start_time += st_get_ticks() - ui; tux.vphysic.start_time += st_get_ticks() - ui; fclose(fi); diff --git a/src/setup.c b/src/setup.c index 4a68ce4e2..2f7e48c45 100644 --- a/src/setup.c +++ b/src/setup.c @@ -392,7 +392,11 @@ void process_save_load_game_menu(int save) else { if(game_started == NO) - gameloop("whatever",slot,ST_GL_LOAD_GAME); + { + gameloop("default",slot,ST_GL_LOAD_GAME); + show_menu = YES; + menu_set_current(&main_menu); + } else loadgame(slot); } diff --git a/src/timer.c b/src/timer.c index 2e5b45851..25a63a37a 100644 --- a/src/timer.c +++ b/src/timer.c @@ -1,7 +1,7 @@ // // C Implementation: timer // -// Description: +// Description: // // // Author: Tobias Glaesser , (C) 2004 @@ -18,39 +18,39 @@ unsigned int st_pause_ticks, st_pause_count; 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; + 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; + st_pause_ticks = 0; + st_pause_count = 0; } void st_pause_ticks_start(void) { -st_pause_count = SDL_GetTicks(); + st_pause_count = SDL_GetTicks(); } void st_pause_ticks_stop(void) { -st_pause_ticks += SDL_GetTicks() - st_pause_count; -st_pause_count = 0; + st_pause_ticks += SDL_GetTicks() - st_pause_count; + st_pause_count = 0; } void timer_init(timer_type* ptimer, int st_ticks) { ptimer->period = 0; ptimer->time = 0; - + if(st_ticks == YES) - ptimer->get_ticks = st_get_ticks; + ptimer->get_ticks = st_get_ticks; else - ptimer->get_ticks = SDL_GetTicks; - + ptimer->get_ticks = SDL_GetTicks; + } void timer_start(timer_type* ptimer, unsigned int period) @@ -61,10 +61,10 @@ void timer_start(timer_type* ptimer, unsigned int period) void timer_stop(timer_type* ptimer) { -if(ptimer->get_ticks == st_get_ticks) - timer_init(ptimer,YES); -else - timer_init(ptimer,NO); + if(ptimer->get_ticks == st_get_ticks) + timer_init(ptimer,YES); + else + timer_init(ptimer,NO); } int timer_check(timer_type* ptimer) @@ -95,3 +95,40 @@ int timer_get_gone(timer_type* ptimer) { return (ptimer->get_ticks() - ptimer->time); } + +int timer_fwrite(timer_type* ptimer, FILE* fi) +{ + unsigned int diff_ticks; + int tick_mode; + if(ptimer->time != 0) + diff_ticks = ptimer->get_ticks() - ptimer->time; + else + diff_ticks = 0; + + fwrite(&ptimer->period,sizeof(unsigned int),1,fi); + fwrite(&diff_ticks,sizeof(unsigned int),1,fi); + if(ptimer->get_ticks == st_get_ticks) + tick_mode = YES; + else + tick_mode = NO; + fwrite(&tick_mode,sizeof(unsigned int),1,fi); +} + +int timer_fread(timer_type* ptimer, FILE* fi) +{ + unsigned int diff_ticks; + int tick_mode; + fread(&ptimer->period,sizeof(unsigned int),1,fi); + fread(&diff_ticks,sizeof(unsigned int),1,fi); + fread(&tick_mode,sizeof(unsigned int),1,fi); + if(tick_mode == YES) + ptimer->get_ticks = st_get_ticks; + else + ptimer->get_ticks = SDL_GetTicks; + if(diff_ticks != 0) + ptimer->time = ptimer->get_ticks() - diff_ticks; + else + ptimer->time = 0; + +} + diff --git a/src/timer.h b/src/timer.h index 8cd880a8e..f2f18235d 100644 --- a/src/timer.h +++ b/src/timer.h @@ -50,6 +50,8 @@ int timer_started(timer_type* ptimer); ======================================================================*/ int timer_get_left(timer_type* ptimer); int timer_get_gone(timer_type* ptimer); +int timer_fwrite(timer_type* ptimer, FILE* fi); +int timer_fread(timer_type* ptimer, FILE* fi); #endif /*SUPERTUX_TIMER_H*/ diff --git a/src/title.c b/src/title.c index 666c5a90e..362abeb97 100644 --- a/src/title.c +++ b/src/title.c @@ -282,7 +282,7 @@ void display_credits() int done; int scroll, speed; timer_type timer; - int n,d; + int n,d,e; int length; FILE* fi; char temp[1024]; @@ -316,6 +316,7 @@ void display_credits() done = 0; n = d = 0; + e = -20; length = names.num_items; @@ -372,12 +373,18 @@ void display_credits() else if(names.item[i][0] == ' ') text_drawf(&white_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1, NO_UPDATE); else if(names.item[i+1][0] == '-' || names.item[i][0] == '-') - text_drawf(&white_big_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1, NO_UPDATE); + text_drawf(&white_big_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 3+e%7, NO_UPDATE); else - text_drawf(&blue_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1, NO_UPDATE); + text_drawf(&blue_text, names.item[i], 0 + e % 20, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1, NO_UPDATE); } } - + if(e == 20) + { + e = -19; + } + e++; + + texture_draw_part(&bkg_title, 0, 0, 0, 0, 640, 130, NO_UPDATE); flipscreen(); @@ -389,7 +396,7 @@ void display_credits() if(scroll < 0) scroll = 0; - SDL_Delay(20); + SDL_Delay(35); if(timer_get_left(&timer) < 0) { -- 2.11.0