// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <config.h>
+#include "game_session.hpp"
+
#include <fstream>
#include <sstream>
#include <assert.h>
#include <SDL.h>
-#include "game_session.hpp"
+#include "file_system.hpp"
+#include "gameconfig.hpp"
+#include "gettext.hpp"
+#include "level.hpp"
+#include "levelintro.hpp"
#include "log.hpp"
-#include "console.hpp"
-#include "worldmap/worldmap.hpp"
+#include "main.hpp"
#include "mainloop.hpp"
-#include "audio/sound_manager.hpp"
-#include "gui/menu.hpp"
-#include "sector.hpp"
-#include "level.hpp"
-#include "tile.hpp"
#include "player_status.hpp"
-#include "object/particlesystem.hpp"
-#include "object/background.hpp"
-#include "object/gradient.hpp"
-#include "object/tilemap.hpp"
-#include "object/camera.hpp"
-#include "object/player.hpp"
-#include "object/level_time.hpp"
-#include "lisp/lisp.hpp"
-#include "lisp/parser.hpp"
-#include "resources.hpp"
+#include "options_menu.hpp"
+#include "random_generator.hpp"
+#include "sector.hpp"
#include "statistics.hpp"
#include "timer.hpp"
-#include "options_menu.hpp"
-#include "textscroller.hpp"
+#include "audio/sound_manager.hpp"
#include "control/codecontroller.hpp"
#include "control/joystickkeyboardcontroller.hpp"
-#include "main.hpp"
-#include "file_system.hpp"
-#include "gameconfig.hpp"
-#include "gettext.hpp"
-#include "console.hpp"
-#include "flip_level_transformer.hpp"
-#include "trigger/secretarea_trigger.hpp"
-#include "trigger/sequence_trigger.hpp"
-#include "random_generator.hpp"
-#include "scripting/squirrel_util.hpp"
-#include "object/endsequence_walkright.hpp"
-#include "object/endsequence_walkleft.hpp"
+#include "gui/menu.hpp"
+#include "object/camera.hpp"
#include "object/endsequence_fireworks.hpp"
-#include "direction.hpp"
-#include "scripting/time_scheduler.hpp"
-
-// the engine will be run with a logical framerate of 64fps.
-// We chose 64fps here because it is a power of 2, so 1/64 gives an "even"
-// binary fraction...
-static const float LOGICAL_FPS = 64.0;
+#include "object/endsequence_walkleft.hpp"
+#include "object/endsequence_walkright.hpp"
+#include "object/level_time.hpp"
+#include "object/player.hpp"
+#include "scripting/squirrel_util.hpp"
+#include "worldmap/worldmap.hpp"
enum GameMenuIDs {
MNID_CONTINUE,
end_sequence(0),
levelfile(levelfile_), best_level_statistics(statistics),
capture_demo_stream(0), playback_demo_stream(0), demo_controller(0),
- play_time(0), edit_mode(false)
+ play_time(0), edit_mode(false), levelintro_shown(false)
{
current_ = this;
currentsector = NULL;
level->load(levelfile);
level->stats.total_coins = level->get_total_coins();
level->stats.total_badguys = level->get_total_badguys();
- level->stats.total_secrets = level->get_total_count<SecretAreaTrigger>();
+ level->stats.total_secrets = level->get_total_secrets();
level->stats.reset();
if(reset_sector != "") {
currentsector->activate("main");
}
- //levelintro();
-
sound_manager->stop_music();
currentsector->play_music(LEVEL_MUSIC);
}
void
-GameSession::levelintro()
-{
- sound_manager->stop_music();
-
- DrawingContext context;
- for(Sector::GameObjects::iterator i = currentsector->gameobjects.begin();
- i != currentsector->gameobjects.end(); ++i) {
- Background* background = dynamic_cast<Background*> (*i);
- if(background) {
- background->draw(context);
- }
- Gradient* gradient = dynamic_cast<Gradient*> (*i);
- if(gradient) {
- gradient->draw(context);
- }
- }
-
-// context.draw_text(gold_text, level->get_name(), Vector(SCREEN_WIDTH/2, 160),
-// ALIGN_CENTER, LAYER_FOREGROUND1);
- context.draw_center_text(gold_text, level->get_name(), Vector(0, 160),
- LAYER_FOREGROUND1);
-
- std::stringstream ss_coins;
- ss_coins << _("Coins") << ": " << player_status->coins;
- context.draw_text(white_text, ss_coins.str(), Vector(SCREEN_WIDTH/2, 210),
- ALIGN_CENTER, LAYER_FOREGROUND1);
-
- if((level->get_author().size()) && (level->get_author() != "SuperTux Team"))
- context.draw_text(white_small_text,
- std::string(_("contributed by ")) + level->get_author(),
- Vector(SCREEN_WIDTH/2, 350), ALIGN_CENTER, LAYER_FOREGROUND1);
-
- if(best_level_statistics != NULL)
- best_level_statistics->draw_message_info(context, _("Best Level Statistics"));
-
- wait_for_event(1.0, 3.0);
-}
-
-void
GameSession::on_escape_press()
{
if(currentsector->player->is_dying() || end_sequence)
void
GameSession::toggle_pause()
{
+ // pause
if(!game_pause) {
speed_before_pause = main_loop->get_speed();
main_loop->set_speed(0);
Menu::set_current(game_menu.get());
game_menu->set_active_item(MNID_CONTINUE);
game_pause = true;
- } else {
- main_loop->set_speed(speed_before_pause);
- Menu::set_current(NULL);
- game_pause = false;
}
+
+ // unpause is done in update() after the menu is processed
}
void
GameSession::process_events()
{
// end of pause mode?
+ // XXX this looks like a fail-safe to unpause the game if there's no menu
+ // XXX having it enabled causes some unexpected problems
+ // XXX hopefully disabling it won't...
+ /*
if(!Menu::current() && game_pause) {
game_pause = false;
}
+ */
// playback a demo?
if(playback_demo_stream != 0) {
{
context.draw_filled_rect(
Vector(0,0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT),
- Color(.2f, .2f, .2f, .5f), LAYER_FOREGROUND1);
+ Color(0.0f, 0.0f, 0.0f, .25f), LAYER_FOREGROUND1);
}
void
current_ = this;
if(currentsector != Sector::current()) {
- currentsector->activate(currentsector->player->get_pos());
+ currentsector->activate(currentsector->player->get_pos());
}
currentsector->play_music(LEVEL_MUSIC);
SDL_Event event;
while(SDL_PollEvent(&event))
{}
+
+ if (!levelintro_shown) {
+ levelintro_shown = true;
+ main_loop->push_screen(new LevelIntro(level.get(), best_level_statistics));
+ }
}
void
process_events();
process_menu();
+ // Unpause the game if the menu has been closed
+ if (game_pause && !Menu::current()) {
+ main_loop->set_speed(speed_before_pause);
+ game_pause = false;
+ }
+
check_end_conditions();
// respawning in new sector?
sector->activate(newspawnpoint);
sector->play_music(LEVEL_MUSIC);
currentsector = sector;
+ //Keep persistent across sectors
+ if(edit_mode)
+ currentsector->get_players()[0]->set_edit_mode(edit_mode);
newsector = "";
newspawnpoint = "";
}
// abort if a sequence is already playing
if (end_sequence)
- return;
+ return;
if (sequencename == "endsequence") {
if (currentsector->get_players()[0]->physic.get_velocity_x() < 0) {
// Stop all clocks.
for(std::vector<GameObject*>::iterator i = currentsector->gameobjects.begin();
- i != currentsector->gameobjects.end(); ++i)
+ i != currentsector->gameobjects.end(); ++i)
{
GameObject* obj = *i;