April 11, 2000 - March 15, 2004
*/
+#include <iostream>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
fps_timer.init(true);
frame_timer.init(true);
+ delete world;
+
if (st_gl_mode == ST_GL_LOAD_LEVEL_FILE)
{
world = new World(subset);
}
void
+GameSession::on_escape_press()
+{
+ if(!game_pause)
+ {
+ if(st_gl_mode == ST_GL_TEST)
+ {
+ exit_status = LEVEL_ABORT;
+ }
+ else if (!Menu::current())
+ {
+ Menu::set_current(game_menu);
+ st_pause_ticks_stop();
+ }
+ else
+ {
+ Menu::set_current(NULL);
+ st_pause_ticks_start();
+ }
+ }
+}
+
+void
GameSession::process_events()
{
Player& tux = *world->get_tux();
while (SDL_PollEvent(&event))
{
/* Check for menu-events, if the menu is shown */
- current_menu->event(event);
+ if (Menu::current())
+ Menu::current()->event(event);
switch(event.type)
{
switch(key)
{
case SDLK_ESCAPE: /* Escape: Open/Close the menu: */
- if(!game_pause)
- {
- if(st_gl_mode == ST_GL_TEST)
- {
- exit_status = LEVEL_ABORT;
- }
- else if(!show_menu)
- {
- Menu::set_current(game_menu);
- show_menu = 0;
- st_pause_ticks_stop();
- }
- else
- {
- Menu::set_current(game_menu);
- show_menu = 1;
- st_pause_ticks_start();
- }
- }
+ on_escape_press();
break;
default:
break;
switch(key)
{
case SDLK_p:
- if(!show_menu)
+ if(!Menu::current())
{
if(game_pause)
{
tux.input.up = DOWN;
else if (event.jbutton.button == JOY_B)
tux.input.fire = DOWN;
+ else if (event.jbutton.button == JOY_START)
+ on_escape_press();
break;
case SDL_JOYBUTTONUP:
if (event.jbutton.button == JOY_A)
tux.input.up = UP;
else if (event.jbutton.button == JOY_B)
tux.input.fire = UP;
-
break;
default:
// Check End conditions
if (tux->is_dead())
{
-
+ player_status.lives -= 1;
+
if (player_status.lives < 0)
{ // No more lives!?
if(st_gl_mode != ST_GL_TEST)
if(st_gl_mode != ST_GL_TEST)
{
- if (player_status.score > hs_score)
- save_hs(player_status.score);
+ // FIXME: highscore soving doesn't make sense in its
+ // current form
+ //if (player_status.score > hs_score)
+ //save_hs(player_status.score);
}
exit_status = GAME_OVER;
if (exit_status == NONE)
{
- Player* tux = world->get_tux();
-
// Update Tux and the World
- tux->action(frame_ratio);
world->action(frame_ratio);
}
}
blue_text->drawf("PAUSE - Press 'P' To Play", 0, 230, A_HMIDDLE, A_TOP, 1);
}
- if(show_menu)
+ if(Menu::current())
{
- menu_process_current();
+ Menu::current()->action();
+ Menu::current()->draw();
mouse_cursor->draw();
}
draw();
+ float overlap = 0.0f;
while (exit_status == NONE)
{
/* Calculate the movement-factor */
double frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE);
- if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */
- frame_ratio = 1.5 + (frame_ratio - 1.5) * 0.85;
if(!frame_timer.check())
{
process_events();
- if(show_menu)
+ if(Menu::current())
{
- if(current_menu == game_menu)
+ if(Menu::current() == game_menu)
{
switch (game_menu->check())
{
case 2:
st_pause_ticks_stop();
break;
- case 3:
- // FIXME:
- //update_load_save_game_menu(save_game_menu);
- break;
- case 4:
- update_load_save_game_menu(load_game_menu);
- break;
- case 7:
+ case 5:
st_pause_ticks_stop();
exit_status = LEVEL_ABORT;
break;
}
}
- else if(current_menu == options_menu)
+ else if(Menu::current() == options_menu)
{
process_options_menu();
}
- else if(current_menu == load_game_menu )
+ else if(Menu::current() == load_game_menu )
{
process_load_game_menu();
}
}
// Handle actions:
- if(!game_pause && !show_menu)
+ if(!game_pause && !Menu::current())
{
- action(frame_ratio);
+ frame_ratio *= game_speed;
+ frame_ratio += overlap;
+ while (frame_ratio > 0)
+ {
+ action(1.0f);
+ frame_ratio -= 1.0f;
+ }
+ overlap = frame_ratio;
+
if (exit_status != NONE)
return exit_status;
}
draw();
/* Time stops in pause mode */
- if(game_pause || show_menu )
+ if(game_pause || Menu::current())
{
continue;
}