/* --- GAME LOOP! --- */
-int gameloop(const char * subset, int levelnb, int mode)
+GameSession::GameSession(const char * subset, int levelnb, int mode)
{
- int fps_cnt, jump, done;
- timer_type fps_timer, frame_timer;
timer_init(&fps_timer, true);
timer_init(&frame_timer, true);
if(st_gl_mode == ST_GL_LOAD_GAME)
loadgame(levelnb);
+}
- /* --- MAIN GAME LOOP!!! --- */
+int
+GameSession::run()
+{
+ int fps_cnt;
+ bool jump;
+ bool done;
+ /* --- MAIN GAME LOOP!!! --- */
jump = false;
- done = 0;
+ done = false;
quit = 0;
global_frame_counter = 0;
game_pause = 0;
fps_cnt = 0;
/* Clear screen: */
-
clearscreen(0, 0, 0);
updatescreen();
/* Play music: */
play_current_music();
-
while (SDL_PollEvent(&event))
{}
break;
case 7:
st_pause_ticks_stop();
- done = 1;
+ done = true;
break;
}
}
extern int game_started;
-/* Function prototypes: */
-class Tile;
+class GameSession
+{
+ private:
+ timer_type fps_timer, frame_timer;
+ public:
+ GameSession(const char * subset, int levelnb, int mode);
+ int run();
+};
void activate_bad_guys(Level* plevel);
-int gameloop(const char * subset, int levelnb, int mode);
void savegame(int slot);
void loadgame(int slot);
std::string slotinfo(int slot);
void le_testlevel()
{
le_current_level->save("test", le_level);
- gameloop("test",le_level, ST_GL_TEST);
+
+ GameSession session("test",le_level, ST_GL_TEST);
+ session.run();
+
Menu::set_current(leveleditor_menu);
arrays_free();
le_current_level->load_gfx();
if (tmp.length() == strlen("Slot X - Free"))
{ // Slot is free, so start a new game
- gameloop("default", 1, ST_GL_PLAY);
+ GameSession session("default", 1, ST_GL_PLAY);
+ session.run();
+
show_menu = true;
Menu::set_current(main_menu);
}
{ // Slot contains a level, so load it
if (game_started)
{
- gameloop("default",slot - 1,ST_GL_LOAD_GAME);
+ GameSession session("default",slot - 1,ST_GL_LOAD_GAME);
+ session.run();
+
show_menu = true;
Menu::set_current(main_menu);
}
}
else if (level_startup_file)
{
- gameloop(level_startup_file, 1, ST_GL_LOAD_LEVEL_FILE);
+ GameSession session(level_startup_file, 1, ST_GL_LOAD_LEVEL_FILE);
+ session.run();
}
else
{
{
std::cout << "Enter the current level: " << i->name << std::endl;;
halt_music();
- gameloop(const_cast<char*>((datadir + "levels/default/" + i->name).c_str()),
- 1, ST_GL_LOAD_LEVEL_FILE);
+ GameSession session(const_cast<char*>((datadir + "levels/default/" + i->name).c_str()),
+ 1, ST_GL_LOAD_LEVEL_FILE);
+ session.run();
play_music(song, 1);
return;
}