Split EndSequence into multiple types. Defeating the Yeti now triggers an EndSequence.
authorChristoph Sommer <mail@christoph-sommer.de>
Sun, 28 Jan 2007 20:35:11 +0000 (20:35 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Sun, 28 Jan 2007 20:35:11 +0000 (20:35 +0000)
SVN-Revision: 4719

data/levels/world1/27 - No More Mr Ice Guy.stl
src/game_session.cpp
src/object/endsequence.cpp
src/object/endsequence.hpp
src/object/endsequence_fireworks.cpp [new file with mode: 0644]
src/object/endsequence_fireworks.hpp [new file with mode: 0644]
src/object/endsequence_walkleft.cpp [new file with mode: 0644]
src/object/endsequence_walkleft.hpp [new file with mode: 0644]
src/object/endsequence_walkright.cpp [new file with mode: 0644]
src/object/endsequence_walkright.hpp [new file with mode: 0644]

index daea254..f288171 100644 (file)
@@ -105,14 +105,7 @@ Effect.fade_in(1);
        (yeti
          (x 2)
          (y 177)
-         (dead-script "
-sector.Tux.make_invincible();
-play_sound(\"sounds/yeti_finish.ogg\");
-wait(6);
-Effect.fade_out(5.5);
-wait(5.5);
-Level.finish(true);
-")
+         (dead-script "sector.Tux.trigger_sequence(\"fireworks\");")
         )
        (particles-snow
        )
index c4ee383..2b539ee 100644 (file)
@@ -55,7 +55,6 @@
 #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"
@@ -69,6 +68,9 @@
 #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.
@@ -579,50 +581,60 @@ GameSession::display_info_box(const std::string& text)
 void
 GameSession::start_sequence(const std::string& sequencename)
 {
-  if(sequencename == "endsequence" || sequencename == "fireworks") {
-    if(end_sequence)
-      return;
+  // 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();
+    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;
+       continue;
       if(st->get_sequence_name() == "stoptux")
-        xend = st->get_pos().x;
+       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((xst > xend) ? LEFT : RIGHT);
-
-    sound_manager->play_music("music/leveldone.ogg", false);
-    currentsector->player->invincible_timer.start(7.3f);
-
-    // 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();
+       xst = st->get_pos().y;
     }
 
-    if(sequencename == "fireworks") {
-      currentsector->add_object(new Fireworks());
-    }
-  } else if(sequencename == "stoptux") {
-    if(!end_sequence) {
-      log_warning << "Final target reached without an active end sequence" << std::endl;
-      this->start_sequence("endsequence");
+    if (xst > xend) {
+      end_sequence = new EndSequenceWalkLeft();
+    } else {
+      end_sequence = new EndSequenceWalkRight();
     }
-    if (end_sequence) end_sequence->stop_tux();
-  } else {
-    log_warning << "Unknown sequence '" << sequencename << "'" << std::endl;
+  }
+  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();
   }
 }
 
index 23c530f..2e4cc6a 100644 (file)
@@ -60,7 +60,7 @@ EndSequence::draw(DrawingContext& /*context*/)
 }
 
 void
-EndSequence::start(Direction dir)
+EndSequence::start()
 {
   if (isrunning) return;
   isrunning = true;
@@ -71,8 +71,6 @@ EndSequence::start(Direction dir)
   tux.set_controller(end_sequence_controller);
   tux.set_speedlimit(230); //MAX_WALK_XM
 
-  walk_dir = dir;
-
   starting();
 }
 
@@ -106,25 +104,11 @@ EndSequence::is_done()
 void
 EndSequence::starting()
 {
-  last_x_pos = -1;
-  endsequence_timer.start(7.3f);
 }
 
 void
 EndSequence::running(float /*elapsed_time*/)
 {
-  Player& tux = *Sector::current()->player;
-
-  if (tux_may_walk) {
-    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);
-    }
-  }
-
-  last_x_pos = tux.get_pos().x;
-
-  if (endsequence_timer.check()) isdone = true;
 }
 
 void
index 25e2acd..f7ac647 100644 (file)
@@ -25,7 +25,6 @@
 #include "timer.hpp"
 #include "lisp/lisp.hpp"
 #include "control/codecontroller.hpp"
-#include "direction.hpp"
 
 class EndSequence : public GameObject
 {
@@ -36,7 +35,7 @@ public:
     virtual void update(float elapsed_time);
     virtual void draw(DrawingContext& context);
 
-    void start(Direction dir); /**< play EndSequence */
+    void start(); /**< 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 */
@@ -47,15 +46,11 @@ protected:
     virtual void running(float elapsed_time); /**< called while the EndSequence is running */
     virtual void stopping(); /**< called when EndSequence stops */
 
-    CodeController* end_sequence_controller;
-    float last_x_pos;
-    Timer endsequence_timer;
-
-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 */
+    CodeController* end_sequence_controller;
+
 };
 
 #endif
diff --git a/src/object/endsequence_fireworks.cpp b/src/object/endsequence_fireworks.cpp
new file mode 100644 (file)
index 0000000..8bcd927
--- /dev/null
@@ -0,0 +1,66 @@
+//  $Id$
+//
+//  SuperTux - End Sequence: Tux walks right
+//  Copyright (C) 2007 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
+//
+//  This program is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU General Public License
+//  as published by the Free Software Foundation; either version 2
+//  of the License, or (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#include <config.h>
+#include "endsequence_fireworks.hpp"
+#include "sector.hpp"
+#include "object/player.hpp"
+#include "object/fireworks.hpp"
+
+EndSequenceFireworks::EndSequenceFireworks()
+: EndSequence()
+{
+}
+
+EndSequenceFireworks::~EndSequenceFireworks()
+{
+}
+
+void
+EndSequenceFireworks::draw(DrawingContext& /*context*/)
+{
+}
+
+void
+EndSequenceFireworks::starting()
+{
+  EndSequence::starting();
+  endsequence_timer.start(7.3f);
+  Sector::current()->add_object(new Fireworks());
+}
+
+void
+EndSequenceFireworks::running(float elapsed_time)
+{
+  EndSequence::running(elapsed_time);
+  //Player& tux = *Sector::current()->player;
+
+  if (tux_may_walk) {
+    end_sequence_controller->press(Controller::JUMP);
+  }
+
+  if (endsequence_timer.check()) isdone = true;
+}
+
+void
+EndSequenceFireworks::stopping()
+{
+  EndSequence::stopping();
+}
+
diff --git a/src/object/endsequence_fireworks.hpp b/src/object/endsequence_fireworks.hpp
new file mode 100644 (file)
index 0000000..aaa7b79
--- /dev/null
@@ -0,0 +1,42 @@
+//  $Id$
+//
+//  SuperTux - End Sequence: Tux walks right
+//  Copyright (C) 2007 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
+//
+//  This program is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU General Public License
+//  as published by the Free Software Foundation; either version 2
+//  of the License, or (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#ifndef __ENDSEQUENCE_FIREWORKS_H__
+#define __ENDSEQUENCE_FIREWORKS_H__
+
+#include <memory>
+#include "object/endsequence.hpp"
+#include "timer.hpp"
+
+class EndSequenceFireworks : public EndSequence
+{
+public:
+    EndSequenceFireworks();
+    virtual ~EndSequenceFireworks();
+    virtual void draw(DrawingContext& context);
+
+protected:
+    virtual void starting(); /**< called when EndSequence starts */
+    virtual void running(float elapsed_time); /**< called while the EndSequence is running */
+    virtual void stopping(); /**< called when EndSequence stops */
+
+    Timer endsequence_timer;
+};
+
+#endif
diff --git a/src/object/endsequence_walkleft.cpp b/src/object/endsequence_walkleft.cpp
new file mode 100644 (file)
index 0000000..6a29edf
--- /dev/null
@@ -0,0 +1,70 @@
+//  $Id$
+//
+//  SuperTux - End Sequence: Tux walks right
+//  Copyright (C) 2007 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
+//
+//  This program is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU General Public License
+//  as published by the Free Software Foundation; either version 2
+//  of the License, or (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#include <config.h>
+#include "endsequence_walkleft.hpp"
+#include "sector.hpp"
+#include "object/player.hpp"
+
+EndSequenceWalkLeft::EndSequenceWalkLeft()
+: EndSequence()
+{
+}
+
+EndSequenceWalkLeft::~EndSequenceWalkLeft()
+{
+}
+
+void
+EndSequenceWalkLeft::draw(DrawingContext& /*context*/)
+{
+}
+
+void
+EndSequenceWalkLeft::starting()
+{
+  EndSequence::starting();
+  last_x_pos = -1;
+  endsequence_timer.start(7.3f);
+}
+
+void
+EndSequenceWalkLeft::running(float elapsed_time)
+{
+  EndSequence::running(elapsed_time);
+  Player& tux = *Sector::current()->player;
+
+  if (tux_may_walk) {
+    end_sequence_controller->press(Controller::LEFT);
+    if (int(last_x_pos) == int(tux.get_pos().x)) {
+      end_sequence_controller->press(Controller::JUMP);
+    }
+  }
+
+  last_x_pos = tux.get_pos().x;
+
+  if (endsequence_timer.check()) isdone = true;
+}
+
+void
+EndSequenceWalkLeft::stopping()
+{
+  EndSequence::stopping();
+}
+
diff --git a/src/object/endsequence_walkleft.hpp b/src/object/endsequence_walkleft.hpp
new file mode 100644 (file)
index 0000000..6abac4d
--- /dev/null
@@ -0,0 +1,43 @@
+//  $Id$
+//
+//  SuperTux - End Sequence: Tux walks right
+//  Copyright (C) 2007 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
+//
+//  This program is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU General Public License
+//  as published by the Free Software Foundation; either version 2
+//  of the License, or (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#ifndef __ENDSEQUENCE_WALKLEFT_H__
+#define __ENDSEQUENCE_WALKLEFT_H__
+
+#include <memory>
+#include "object/endsequence.hpp"
+#include "timer.hpp"
+
+class EndSequenceWalkLeft : public EndSequence
+{
+public:
+    EndSequenceWalkLeft();
+    virtual ~EndSequenceWalkLeft();
+    virtual void draw(DrawingContext& context);
+
+protected:
+    virtual void starting(); /**< called when EndSequence starts */
+    virtual void running(float elapsed_time); /**< called while the EndSequence is running */
+    virtual void stopping(); /**< called when EndSequence stops */
+
+    float last_x_pos;
+    Timer endsequence_timer;
+};
+
+#endif
diff --git a/src/object/endsequence_walkright.cpp b/src/object/endsequence_walkright.cpp
new file mode 100644 (file)
index 0000000..823b29f
--- /dev/null
@@ -0,0 +1,70 @@
+//  $Id$
+//
+//  SuperTux - End Sequence: Tux walks right
+//  Copyright (C) 2007 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
+//
+//  This program is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU General Public License
+//  as published by the Free Software Foundation; either version 2
+//  of the License, or (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#include <config.h>
+#include "endsequence_walkright.hpp"
+#include "sector.hpp"
+#include "object/player.hpp"
+
+EndSequenceWalkRight::EndSequenceWalkRight()
+: EndSequence()
+{
+}
+
+EndSequenceWalkRight::~EndSequenceWalkRight()
+{
+}
+
+void
+EndSequenceWalkRight::draw(DrawingContext& /*context*/)
+{
+}
+
+void
+EndSequenceWalkRight::starting()
+{
+  EndSequence::starting();
+  last_x_pos = -1;
+  endsequence_timer.start(7.3f);
+}
+
+void
+EndSequenceWalkRight::running(float elapsed_time)
+{
+  EndSequence::running(elapsed_time);
+  Player& tux = *Sector::current()->player;
+
+  if (tux_may_walk) {
+    end_sequence_controller->press(Controller::RIGHT);
+    if (int(last_x_pos) == int(tux.get_pos().x)) {
+      end_sequence_controller->press(Controller::JUMP);
+    }
+  }
+
+  last_x_pos = tux.get_pos().x;
+
+  if (endsequence_timer.check()) isdone = true;
+}
+
+void
+EndSequenceWalkRight::stopping()
+{
+  EndSequence::stopping();
+}
+
diff --git a/src/object/endsequence_walkright.hpp b/src/object/endsequence_walkright.hpp
new file mode 100644 (file)
index 0000000..aae4a2c
--- /dev/null
@@ -0,0 +1,43 @@
+//  $Id$
+//
+//  SuperTux - End Sequence: Tux walks right
+//  Copyright (C) 2007 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
+//
+//  This program is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU General Public License
+//  as published by the Free Software Foundation; either version 2
+//  of the License, or (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#ifndef __ENDSEQUENCE_WALKRIGHT_H__
+#define __ENDSEQUENCE_WALKRIGHT_H__
+
+#include <memory>
+#include "object/endsequence.hpp"
+#include "timer.hpp"
+
+class EndSequenceWalkRight : public EndSequence
+{
+public:
+    EndSequenceWalkRight();
+    virtual ~EndSequenceWalkRight();
+    virtual void draw(DrawingContext& context);
+
+protected:
+    virtual void starting(); /**< called when EndSequence starts */
+    virtual void running(float elapsed_time); /**< called while the EndSequence is running */
+    virtual void stopping(); /**< called when EndSequence stops */
+
+    float last_x_pos;
+    Timer endsequence_timer;
+};
+
+#endif