B91: Tux now guesses direction to walk in during an end sequence.
authorOndřej Hošek <ondra.hosek@gmail.com>
Sun, 28 Jan 2007 19:31:49 +0000 (19:31 +0000)
committerOndřej Hošek <ondra.hosek@gmail.com>
Sun, 28 Jan 2007 19:31:49 +0000 (19:31 +0000)
SVN-Revision: 4715

src/game_session.cpp
src/object/endsequence.cpp
src/object/endsequence.hpp
src/trigger/sequence_trigger.hpp

index c1ae83c..38b6f46 100644 (file)
 #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<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);
index c9a91d3..23c530f 100644 (file)
@@ -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);
     }
index 68cb0e5..25e2acd 100644 (file)
@@ -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
index 34ec251..199323a 100644 (file)
@@ -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;