/* extern variables */
extern char* soundfilenames[NUM_SOUNDS];
+st_level current_level;
/* Local variables: */
char level_subset[100];
char str[60];
float fps_fps;
+int st_gl_mode;
+unsigned int last_update_time;
+unsigned int update_time;
+int pause_menu_frame;
/* Local function prototypes: */
void levelintro(void);
void initgame(void);
-void loadlevelsong(void);
-void unloadlevelsong(void);
void loadshared(void);
void unloadshared(void);
void drawstatus(void);
clearscreen(0, 0, 0);
sprintf(str, "LEVEL %d", level);
- text_drawf(&red_text, str, 0, 200, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
+ text_drawf(&blue_text, str, 0, 200, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
sprintf(str, "%s", current_level.name);
text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
sprintf(str, "TUX x %d", tux.lives);
- text_drawf(&blue_text, str, 0, 256, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
+ text_drawf(&white_text, str, 0, 256, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
flipscreen();
case SDLK_ESCAPE: /* Escape: Open/Close the menu: */
if(!game_pause)
{
- if(show_menu)
- {
- show_menu = 0;
- st_pause_ticks_stop();
- }
+ if(st_gl_mode == ST_GL_TEST)
+ quit = 1;
+ else if(show_menu)
+ {
+ show_menu = 0;
+ st_pause_ticks_stop();
+ }
else
- {
- show_menu = 1;
- st_pause_ticks_start();
- }
+ {
+ show_menu = 1;
+ st_pause_ticks_start();
+ }
}
break;
default:
if(!show_menu)
{
if(game_pause)
- {
- game_pause = 0;
- st_pause_ticks_stop();
- }
+ {
+ game_pause = 0;
+ st_pause_ticks_stop();
+ }
else
- {
- game_pause = 1;
- st_pause_ticks_start();
- }
+ {
+ game_pause = 1;
+ st_pause_ticks_start();
+ }
}
break;
case SDLK_TAB:
break;
case SDLK_l:
if(debug_mode == YES)
- --tux.lives;
+ --tux.lives;
break;
case SDLK_s:
if(debug_mode == YES)
- score += 1000;
+ score += 1000;
break;
default:
break;
{
/* Tux either died, or reached the end of a level! */
-
if (playing_music())
halt_music();
/* End of a level! */
level++;
next_level = 0;
- drawresultscreen();
+ if(st_gl_mode == ST_GL_PLAY)
+ drawresultscreen();
player_level_begin(&tux);
}
else
{
-
player_dying(&tux);
/* No more lives!? */
if (tux.lives < 0)
{
- drawendscreen();
+ if(st_gl_mode == ST_GL_PLAY)
+ drawendscreen();
- if (score > hs_score)
- save_hs(score);
- unloadlevelgfx();
- unloadlevelsong();
+ if(st_gl_mode == ST_GL_PLAY)
+ {
+ if (score > hs_score)
+ save_hs(score);
+ }
+ level_free_gfx();
+ level_free(¤t_level);
+ level_free_song();
unloadshared();
arrays_free();
return(0);
player_level_begin(&tux);
set_defaults();
- loadlevel(¤t_level,"default",level);
+ level_free(¤t_level);
+ if(level_load(¤t_level,level_subset,level) != 0)
+ exit(1);
arrays_free();
arrays_init();
activate_bad_guys();
- unloadlevelgfx();
- loadlevelgfx(¤t_level);
- unloadlevelsong();
- loadlevelsong();
- levelintro();
+ level_free_gfx();
+ level_load_gfx(¤t_level);
+ level_free_song();
+ level_load_song(¤t_level);
+ if(st_gl_mode == ST_GL_PLAY)
+ levelintro();
start_timers();
}
/* Draw the real background */
if(current_level.bkgd_image[0] != '\0')
{
- s = scroll_x / 30;
+ s = (int)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);
}
if(game_pause)
- text_drawf(&red_text, "PAUSE", 0, 230, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
+ {
+ x = screen->h / 20;
+ for(i = 0; i < x; ++i)
+ {
+ fillrect(i % 2 ? (pause_menu_frame * i)%screen->w : -((pause_menu_frame * i)%screen->w) ,(i*20+pause_menu_frame)%screen->h,screen->w,10,20,20,20, rand() % 20 + 1);
+ }
+ fillrect(0,0,screen->w,screen->h,rand() % 50, rand() % 50, rand() % 50, 128);
+ text_drawf(&blue_text, "PAUSE - Press 'P' To Play", 0, 230, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
+ }
if(show_menu)
- done = drawmenu();
+ menu_process_current();
/* (Update it all!) */
/* --- GAME LOOP! --- */
-int gameloop(void)
+int gameloop(char * subset, int levelnb, int mode)
{
-
- /*Uint32 last_time, now_time*/
- int fps_cnt, jump;
+ int fps_cnt, jump, done;
timer_type fps_timer, frame_timer;
+ level = levelnb;
+ st_gl_mode = mode;
+ strcpy(level_subset,subset);
+
/* Clear screen: */
clearscreen(0, 0, 0);
/* Init the game: */
arrays_init();
- initmenu();
- menumenu = MENU_GAME;
+ menu_reset();
+ menu_set_current(&game_menu);
+
initgame();
loadshared();
set_defaults();
- loadlevel(¤t_level,"default",level);
- loadlevelgfx(¤t_level);
+ if(level_load(¤t_level,level_subset,level) != 0)
+ exit(1);
+ level_load_gfx(¤t_level);
activate_bad_guys();
- loadlevelsong();
- load_hs();
+ level_load_song(¤t_level);
+ if(st_gl_mode == ST_GL_PLAY)
+ load_hs();
player_init(&tux);
- levelintro();
+ if(st_gl_mode == ST_GL_PLAY)
+ levelintro();
+
start_timers();
/* --- MAIN GAME LOOP!!! --- */
game_draw();
do
{
- 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();
-
+ jump = NO;
+
/* Calculate the movement-factor */
frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE);
tux.input.old_fire = tux.input.fire;
- printf("%lf\n",frame_ratio);
-
+ /*printf("%lf\n",frame_ratio);*/
+
game_event();
+ if(show_menu)
+ {
+ if(current_menu == &game_menu)
+ {
+ switch (menu_check(&game_menu))
+ {
+ case 0:
+ st_pause_ticks_stop();
+ break;
+ case 1:
+ savegame();
+ break;
+ case 2:
+ loadgame(NULL);
+ break;
+ case 4:
+ done = 1;
+ break;
+ }
+ }
+ else if(current_menu == &options_menu)
+ {
+ process_options_menu();
+ }
+ }
+
/* Handle actions: */
}
}
else
- SDL_Delay(50);
-
- if(tux.input.down == DOWN)
- SDL_Delay(30);
-
+ {
+ ++pause_menu_frame;
+ 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).*/
+ the FPS aren't affected).*/
/*if( ! fps_fps < 50.0 )
game_draw();
else
continue;
}
+ /* Set the time the last update and the time of the current update */
+ last_update_time = update_time;
+ update_time = st_get_ticks();
+
+
/* 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+. */
+ 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);
+ //if((update_time - last_update_time) < 10)
+ // SDL_Delay((11 - (update_time - last_update_time))/2);
/* Calculate frames per second */
if(show_fps)
{
- ++fps_cnt;
+ ++fps_cnt;
fps_fps = (1000.0 / (float)timer_get_gone(&fps_timer)) * (float)fps_cnt;
if(!timer_check(&fps_timer))
if (playing_music())
halt_music();
- unloadlevelgfx();
- unloadlevelsong();
+ level_free_gfx();
+ level_free(¤t_level);
+ level_free_song();
unloadshared();
arrays_free();
void initgame(void)
{
- level = 1;
score = 0;
distros = 0;
}
-/* Free music data for this level: */
-
-void unloadlevelsong(void)
-{
- free_music(level_song);
- free_music(level_song_fast);
-}
-
-/* Load music: */
-
-void loadlevelsong(void)
-{
-
- char * song_path;
- char * song_subtitle;
-
- song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) +
- strlen(current_level.song_title) + 8));
- sprintf(song_path, "%s/music/%s", DATA_PREFIX, current_level.song_title);
- level_song = load_song(song_path);
- free(song_path);
-
-
- song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) +
- strlen(current_level.song_title) + 8 + 5));
- song_subtitle = strdup(current_level.song_title);
- strcpy(strstr(song_subtitle, "."), "\0");
- sprintf(song_path, "%s/music/%s-fast%s", DATA_PREFIX, song_subtitle, strstr(current_level.song_title, "."));
- level_song_fast = load_song(song_path);
- free(song_subtitle);
- free(song_path);
-}
-
/* Load graphics/sounds shared between all levels: */
void loadshared(void)
/* Mark this as the end position of the level! */
- endpos = x;
+ endpos = (int)x;
}
else if (c == '\\')
{
/* Is is ground? */
+
+int issolid(float x, float y)
+{
+ if (isbrick(x, y) ||
+ isice(x, y) ||
+ (shape(x, y) == '[') ||
+ (shape(x, y) == '=') ||
+ (shape(x, y) == ']') ||
+ (shape(x, y) == 'A') ||
+ (shape(x, y) == 'B') ||
+ (shape(x, y) == '!') ||
+ (shape(x, y) == 'a'))
+ {
+ return YES;
+ }
+
+ return NO;
+}
+
+/*
int issolid(float x, float y)
{
if (isbrick(x, y) ||
}
return NO;
-}
+}*/
/* Is it a brick? */
{
if (shape(x, y) == 'A')
{
+
+ DEBUG_MSG("Here I am");
+
/* Box with a distro! */
add_bouncy_distro(((x + 1) / 32) * 32,
int i;
sprintf(str, "%d", score);
- text_draw(&blue_text, "SCORE", 0, 0, 1, NO_UPDATE);
+ text_draw(&white_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(st_gl_mode == ST_GL_PLAY)
+ {
+ sprintf(str, "%d", hs_score);
+ text_draw(&white_text, "HIGH", 0, 20, 1, NO_UPDATE);
+ text_draw(&gold_text, str, 96, 20, 1, NO_UPDATE);
+ }
+ else if(st_gl_mode == ST_GL_TEST)
+ {
+ text_draw(&white_text,"Press ESC To Return",0,20,1, NO_UPDATE);
+ }
+
if (timer_get_left(&time_left) > TIME_WARNING || (frame % 10) < 5)
{
sprintf(str, "%d", timer_get_left(&time_left) / 1000 );
- text_draw(&blue_text, "TIME", 224, 0, 1, NO_UPDATE);
- text_draw(&gold_text, str, 304, 0, 1, NO_UPDATE);
+ text_draw(&white_text, "TIME", 224, 0, 1, NO_UPDATE);
+ text_draw(&gold_text, str, 304, 0, 1, NO_UPDATE);
}
sprintf(str, "%d", distros);
- text_draw(&blue_text, "DISTROS", screen->h, 0, 1, NO_UPDATE);
+ text_draw(&white_text, "DISTROS", screen->h, 0, 1, NO_UPDATE);
text_draw(&gold_text, str, 608, 0, 1, NO_UPDATE);
- text_draw(&blue_text, "LIVES", screen->h, 20, 1, NO_UPDATE);
+ text_draw(&white_text, "LIVES", screen->h, 20, 1, NO_UPDATE);
if(show_fps)
{
- sprintf(str, "%f", fps_fps);
- text_draw(&blue_text, "FPS", screen->h, 40, 1, NO_UPDATE);
- text_draw(&blue_text, str, screen->h + 60, 40, 1, NO_UPDATE);
+ sprintf(str, "%2.1f", fps_fps);
+ text_draw(&white_text, "FPS", screen->h, 40, 1, NO_UPDATE);
+ text_draw(&gold_text, str, screen->h + 60, 40, 1, NO_UPDATE);
}
for(i=0; i < tux.lives; ++i)
clearscreen(0, 0, 0);
- text_drawf(&red_text, "Result:", 0, 200, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
+ text_drawf(&blue_text, "Result:", 0, 200, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
sprintf(str, "SCORE: %d", score);
text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
{
player_level_begin(&tux);
set_defaults();
- loadlevel(¤t_level,"default",level);
+ level_free(¤t_level);
+ if(level_load(¤t_level,level_subset,level) != 0)
+ exit(1);
arrays_free();
arrays_init();
activate_bad_guys();
- unloadlevelgfx();
- loadlevelgfx(¤t_level);
- unloadlevelsong();
- loadlevelsong();
+ level_free_gfx();
+ level_load_gfx(¤t_level);
+ level_free_song();
+ level_load_song(¤t_level);
levelintro();
start_timers();