From: Ondřej Hošek Date: Sun, 28 Jan 2007 19:31:49 +0000 (+0000) Subject: B91: Tux now guesses direction to walk in during an end sequence. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9bf5386f1d1b84b5290bb015e1ede6d1745d5e61;p=supertux.git B91: Tux now guesses direction to walk in during an end sequence. SVN-Revision: 4715 --- diff --git a/src/game_session.cpp b/src/game_session.cpp index c1ae83c18..38b6f46d3 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -66,8 +66,10 @@ #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 "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" @@ -581,9 +583,20 @@ GameSession::start_sequence(const std::string& sequencename) if(end_sequence) return; + // Determine walking direction for Tux + float xst = 1.f, xend = 2.f; + for(std::vector::iterator i = currentsector->gameobjects.begin(); i != currentsector->gameobjects.end(); i++) { + SequenceTrigger* st = dynamic_cast(*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; + } end_sequence = new EndSequence(); currentsector->add_object(end_sequence); - end_sequence->start(); + end_sequence->start((xst > xend) ? LEFT : RIGHT); sound_manager->play_music("music/leveldone.ogg", false); currentsector->player->invincible_timer.start(7.3f); diff --git a/src/object/endsequence.cpp b/src/object/endsequence.cpp index c9a91d330..23c530fbe 100644 --- a/src/object/endsequence.cpp +++ b/src/object/endsequence.cpp @@ -60,7 +60,7 @@ EndSequence::draw(DrawingContext& /*context*/) } void -EndSequence::start() +EndSequence::start(Direction dir) { if (isrunning) return; isrunning = true; @@ -71,6 +71,8 @@ EndSequence::start() tux.set_controller(end_sequence_controller); tux.set_speedlimit(230); //MAX_WALK_XM + walk_dir = dir; + starting(); } @@ -114,7 +116,7 @@ EndSequence::running(float /*elapsed_time*/) Player& tux = *Sector::current()->player; if (tux_may_walk) { - end_sequence_controller->press(Controller::RIGHT); + end_sequence_controller->press((walk_dir == RIGHT) ? Controller::RIGHT : Controller::LEFT); if (int(last_x_pos) == int(tux.get_pos().x)) { end_sequence_controller->press(Controller::JUMP); } diff --git a/src/object/endsequence.hpp b/src/object/endsequence.hpp index 68cb0e5df..25e2acdf0 100644 --- a/src/object/endsequence.hpp +++ b/src/object/endsequence.hpp @@ -25,6 +25,7 @@ #include "timer.hpp" #include "lisp/lisp.hpp" #include "control/codecontroller.hpp" +#include "direction.hpp" class EndSequence : public GameObject { @@ -35,7 +36,7 @@ public: virtual void update(float elapsed_time); virtual void draw(DrawingContext& context); - void start(); /**< play EndSequence */ + void start(Direction dir); /**< play EndSequence */ void stop_tux(); /**< called when Tux has reached his final position */ void stop(); /**< stop playing EndSequence, mark it as done playing */ bool is_tux_stopped(); /**< returns true if Tux has reached his final position */ @@ -54,7 +55,7 @@ private: bool isrunning; /**< true while EndSequence plays */ bool isdone; /**< true if EndSequence has finished playing */ bool tux_may_walk; /**< true while tux is allowed to walk */ - + Direction walk_dir; /**< direction in which Tux should walk */ }; #endif diff --git a/src/trigger/sequence_trigger.hpp b/src/trigger/sequence_trigger.hpp index 34ec2517b..199323ae7 100644 --- a/src/trigger/sequence_trigger.hpp +++ b/src/trigger/sequence_trigger.hpp @@ -35,6 +35,8 @@ public: void write(lisp::Writer& writer); void event(Player& player, EventType type); + std::string get_sequence_name() const { return sequence_name; } + private: EventType triggerevent; std::string sequence_name;