#include "statistics.hpp"
#include "timer.hpp"
#include "options_menu.hpp"
-#include "object/fireworks.hpp"
#include "textscroller.hpp"
#include "control/codecontroller.hpp"
#include "control/joystickkeyboardcontroller.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 "object/endsequence_fireworks.hpp"
+#include "direction.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"
statistics_backdrop.reset(new Surface("images/engine/menu/score-backdrop.png"));
- restart_level(true);
+ restart_level();
game_menu.reset(new Menu());
game_menu->add_label(_("Pause"));
}
void
-GameSession::restart_level(bool fromBeginning)
+GameSession::restart_level()
{
game_pause = false;
end_sequence = 0;
level->stats.total_badguys = level->get_total_badguys();
level->stats.total_secrets = level->get_total_count<SecretAreaTrigger>();
level->stats.reset();
- if (!fromBeginning && (reset_sector != "")) level->stats.declare_invalid();
+ if(reset_sector != "")level->stats.declare_invalid();
- if (fromBeginning) reset_sector="";
if(reset_sector != "") {
currentsector = level->get_sector(reset_sector);
if(!currentsector) {
}
// context.draw_text(gold_text, level->get_name(), Vector(SCREEN_WIDTH/2, 160),
-// CENTER_ALLIGN, LAYER_FOREGROUND1);
+// 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),
- CENTER_ALLIGN, LAYER_FOREGROUND1);
+ 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), CENTER_ALLIGN, LAYER_FOREGROUND1);
+ Vector(SCREEN_WIDTH/2, 350), ALIGN_CENTER, LAYER_FOREGROUND1);
if(best_level_statistics != NULL)
best_level_statistics->draw_message_info(context, _("Best Level Statistics"));
/* End of level? */
if(end_sequence && end_sequence->is_done()) {
finish(true);
- return;
} else if (!end_sequence && tux->is_dead()) {
- if (player_status->coins < 0) {
- // No more coins: restart level from beginning
- player_status->coins = 0;
- restart_level(true);
- } else {
- // Still has coins: restart level from last reset point
- restart_level(false);
- }
-
- return;
+ restart_level();
}
}
{
context.draw_filled_rect(
Vector(0,0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT),
- Color(.2, .2, .2, .5), LAYER_FOREGROUND1);
+ Color(.2f, .2f, .2f, .5f), LAYER_FOREGROUND1);
}
void
void
GameSession::start_sequence(const std::string& sequencename)
{
- if(sequencename == "endsequence" || sequencename == "fireworks") {
- if(end_sequence)
- return;
-
- end_sequence = new EndSequence();
- currentsector->add_object(end_sequence);
- end_sequence->start();
-
- sound_manager->play_music("music/leveldone.ogg", false);
- currentsector->player->invincible_timer.start(7.3);
-
- // Stop all clocks.
- for(std::vector<GameObject*>::iterator i = currentsector->gameobjects.begin();
- i != currentsector->gameobjects.end(); ++i)
- {
- GameObject* obj = *i;
-
- LevelTime* lt = dynamic_cast<LevelTime*> (obj);
- if(lt)
- lt->stop();
- }
-
- if(sequencename == "fireworks") {
- currentsector->add_object(new Fireworks());
- }
- } else if(sequencename == "stoptux") {
- if(!end_sequence) {
+ // handle special "stoptux" sequence
+ if (sequencename == "stoptux") {
+ if (!end_sequence) {
log_warning << "Final target reached without an active end sequence" << std::endl;
this->start_sequence("endsequence");
}
if (end_sequence) end_sequence->stop_tux();
- } else {
- log_warning << "Unknown sequence '" << sequencename << "'" << std::endl;
+ return;
+ }
+
+ // abort if a sequence is already playing
+ if (end_sequence) return;
+
+ if (sequencename == "endsequence") {
+
+ // Determine walking direction for Tux
+ float xst = 1.f, xend = 2.f;
+ for(std::vector<GameObject*>::iterator i = currentsector->gameobjects.begin(); i != currentsector->gameobjects.end(); i++) {
+ SequenceTrigger* st = dynamic_cast<SequenceTrigger*>(*i);
+ if(!st)
+ continue;
+ if(st->get_sequence_name() == "stoptux")
+ xend = st->get_pos().x;
+ else if(st->get_sequence_name() == "endsequence")
+ xst = st->get_pos().y;
+ }
+
+ if (xst > xend) {
+ end_sequence = new EndSequenceWalkLeft();
+ } else {
+ end_sequence = new EndSequenceWalkRight();
+ }
+ }
+ else if (sequencename == "fireworks") end_sequence = new EndSequenceFireworks();
+ else {
+ log_warning << "Unknown sequence '" << sequencename << "'. Ignoring." << std::endl;
+ return;
+ }
+
+ currentsector->add_object(end_sequence);
+ end_sequence->start();
+
+ sound_manager->play_music("music/leveldone.ogg", false);
+ currentsector->player->invincible_timer.start(10000.0f);
+
+ // Stop all clocks.
+ for(std::vector<GameObject*>::iterator i = currentsector->gameobjects.begin();
+ i != currentsector->gameobjects.end(); ++i)
+ {
+ GameObject* obj = *i;
+
+ LevelTime* lt = dynamic_cast<LevelTime*> (obj);
+ if(lt)
+ lt->stop();
}
}