#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"
if(end_sequence)
return;
+ // 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;
+ }
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);
}
void
-EndSequence::start()
+EndSequence::start(Direction dir)
{
if (isrunning) return;
isrunning = true;
tux.set_controller(end_sequence_controller);
tux.set_speedlimit(230); //MAX_WALK_XM
+ walk_dir = dir;
+
starting();
}
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);
}
#include "timer.hpp"
#include "lisp/lisp.hpp"
#include "control/codecontroller.hpp"
+#include "direction.hpp"
class EndSequence : public GameObject
{
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 */
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
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;