#include <ctype.h>
#endif
-#include "app/globals.h"
#include "game_session.h"
#include "video/screen.h"
-#include "app/setup.h"
#include "gui/menu.h"
#include "sector.h"
#include "level.h"
#include "lisp/lisp.h"
#include "lisp/parser.h"
#include "resources.h"
-#include "app/gettext.h"
#include "worldmap.h"
#include "misc.h"
#include "statistics.h"
#include "control/codecontroller.h"
#include "control/joystickkeyboardcontroller.h"
#include "main.h"
+#include "gameconfig.h"
+#include "gettext.h"
// the engine will be run with a lofical framerate of 64fps.
// We choose 64fps here because it is a power of 2, so 1/64 gives an "even"
context.do_drawing();
- SDL_Event event;
- wait_for_event(event,1000,3000,true);
+ wait_for_event(1.0, 3.0);
}
/* Reset Timers */
GameSession::start_timers()
{
time_left.start(level->timelimit);
- Ticks::pause_init();
}
void
} else if (!Menu::current()) {
Menu::set_current(game_menu);
game_menu->set_active_item(MNID_CONTINUE);
- Ticks::pause_start();
game_pause = true;
} else {
- Ticks::pause_stop();
game_pause = false;
}
}
// end of pause mode?
if(!Menu::current() && game_pause) {
game_pause = false;
- Ticks::pause_stop();
}
if (end_sequence != NO_ENDSEQUENCE) {
}
void
-GameSession::action(float elapsed_time)
+GameSession::update(float elapsed_time)
{
// handle controller
if(main_controller->pressed(Controller::PAUSE_MENU))
// advance timers
if(!currentsector->player->growing_timer.started()) {
// Update Tux and the World
- currentsector->action(elapsed_time);
+ currentsector->update(elapsed_time);
}
// respawning in new sector?
{
Menu* menu = Menu::current();
if(menu) {
- menu->action();
+ menu->update();
if(menu == game_menu) {
switch (game_menu->check()) {
if(!game_pause)
global_time += elapsed_time;
- skipdraw = false;
-
// regulate fps
ticks = SDL_GetTicks();
if(ticks > fps_nextframe_ticks) {
- // don't draw all frames when we're getting too slow
- skipdraw = true;
+ if(skipdraw == true) {
+ // already skipped last frame? we have to slow down the game then...
+ skipdraw = false;
+ fps_nextframe_ticks -= (Uint32) (1000.0 / LOGICAL_FPS);
+ } else {
+ // don't draw all frames when we're getting too slow
+ skipdraw = true;
+ }
} else {
+ skipdraw = false;
while(fps_nextframe_ticks > ticks) {
/* just wait */
// If we really have to wait long, then do an imprecise SDL_Delay()
// Update the world
check_end_conditions();
if (end_sequence == ENDSEQUENCE_RUNNING)
- action(elapsed_time/2);
+ update(elapsed_time/2);
else if(end_sequence == NO_ENDSEQUENCE)
- action(elapsed_time);
+ update(elapsed_time);
}
else
{
}
void
+GameSession::finish()
+{
+ exit_status = ES_LEVEL_FINISHED;
+}
+
+void
GameSession::respawn(const std::string& sector, const std::string& spawnpoint)
{
newsector = sector;
context.do_drawing();
- SDL_Event event;
- wait_for_event(event,2000,5000,true);
+ wait_for_event(2.0, 5.0);
}
std::string slotinfo(int slot)
{
int slot = load_game_menu->check();
- if(slot != -1 && load_game_menu->get_item_by_id(slot).kind == MN_ACTION)
- {
- std::stringstream stream;
- stream << slot;
- std::string slotfile = user_dir + "/save/slot" + stream.str() + ".stsg";
+ if(slot == -1)
+ return false;
+
+ if(load_game_menu->get_item_by_id(slot).kind != MN_ACTION)
+ return false;
+
+ std::stringstream stream;
+ stream << slot;
+ std::string slotfile = user_dir + "/save/slot" + stream.str() + ".stsg";
- fadeout(256);
- DrawingContext context;
- context.draw_text(white_text, "Loading...",
- Vector(SCREEN_WIDTH/2, SCREEN_HEIGHT/2), CENTER_ALLIGN, LAYER_FOREGROUND1);
- context.do_drawing();
+ fadeout(256);
+ DrawingContext context;
+ context.draw_text(white_text, "Loading...",
+ Vector(SCREEN_WIDTH/2, SCREEN_HEIGHT/2),
+ CENTER_ALLIGN, LAYER_FOREGROUND1);
+ context.do_drawing();
- WorldMapNS::WorldMap worldmap;
+ WorldMapNS::WorldMap worldmap;
- worldmap.set_map_filename("/levels/world1/worldmap.stwm");
- // Load the game or at least set the savegame_file variable
- worldmap.loadgame(slotfile);
+ worldmap.set_map_filename("/levels/world1/worldmap.stwm");
+ // Load the game or at least set the savegame_file variable
+ worldmap.loadgame(slotfile);
- worldmap.display();
+ worldmap.display();
- Menu::set_current(main_menu);
+ Menu::set_current(main_menu);
- Ticks::pause_stop();
- return true;
- }
- else
- {
- return false;
- }
+ return true;
}