First tries at making platform scriptable
authorChristoph Sommer <mail@christoph-sommer.de>
Thu, 25 May 2006 13:51:47 +0000 (13:51 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Thu, 25 May 2006 13:51:47 +0000 (13:51 +0000)
SVN-Revision: 3582

src/object/path_walker.cpp
src/object/path_walker.hpp
src/object/platform.cpp
src/object/platform.hpp
src/scripting/wrapper.interface.hpp

index 07c2b5a..abb42bc 100644 (file)
@@ -24,7 +24,7 @@
 #include "path_walker.hpp"
 
 PathWalker::PathWalker(const Path* path)
-  : path(path), current_node_nr(0), next_node_nr(0), node_time(0),
+  : path(path), current_node_nr(0), next_node_nr(0), stop_at_node_nr(-1), node_time(0),
     walking_speed(1.0)
 {
   last_pos = path->nodes[0].position;
@@ -39,6 +39,8 @@ PathWalker::~PathWalker()
 Vector
 PathWalker::advance(float elapsed_time)
 {
+  if (static_cast<int>(current_node_nr) == stop_at_node_nr) return Vector(0,0);
+
   assert(elapsed_time >= 0);
 
   elapsed_time *= fabsf(walking_speed);
@@ -74,6 +76,25 @@ PathWalker::advance(float elapsed_time)
   return result;
 }
 
+void 
+PathWalker::goto_node(int node_no)
+{
+  stop_at_node_nr = node_no;
+}
+
+void 
+PathWalker::start_moving()
+{
+  stop_at_node_nr = -1;
+}
+
+void 
+PathWalker::stop_moving()
+{
+  stop_at_node_nr = next_node_nr;
+}
+
+
 void
 PathWalker::advance_node()
 {
index 9f237ef..3766497 100644 (file)
@@ -41,6 +41,15 @@ public:
    */
   virtual Vector advance(float elapsed_time);
 
+  /** advance until at given node, then stop */
+  void goto_node(int node_no);
+
+  /** start advancing automatically */
+  void start_moving();
+
+  /** stop advancing automatically */
+  void stop_moving();
+
   const Path* path;
 
 private:
@@ -50,6 +59,11 @@ private:
   size_t current_node_nr;
   size_t next_node_nr;
 
+  /**
+   * stop advancing automatically when this node is reached
+   */
+  int stop_at_node_nr;
+
   Vector last_pos;
 
   /**
index 6f405c8..fa9e315 100644 (file)
@@ -31,6 +31,8 @@
 #include "sprite/sprite.hpp"
 #include "lisp/lisp.hpp"
 #include "object_factory.hpp"
+#include "scripting/platform.hpp"
+#include "scripting/squirrel_util.hpp"
 
 Platform::Platform(const lisp::Lisp& reader)
        : MovingSprite(reader, Vector(0,0), LAYER_OBJECTS, COLGROUP_STATIC), speed(Vector(0,0))
@@ -47,7 +49,7 @@ Platform::Platform(const lisp::Lisp& reader)
 }
 
 Platform::Platform(const Platform& other)
-       : MovingSprite(other), speed(other.speed)
+       : MovingSprite(other), ScriptInterface(other), speed(other.speed)
 {
   path.reset(new Path(*other.path));
   walker.reset(new PathWalker(*other.walker));
@@ -82,4 +84,35 @@ Platform::update(float elapsed_time)
   speed = movement / elapsed_time;
 }
 
+void
+Platform::goto_node(int node_no)
+{
+  walker->goto_node(node_no);
+}
+
+void
+Platform::start_moving()
+{
+  walker->start_moving();
+}
+
+void
+Platform::stop_moving()
+{
+  walker->stop_moving();
+}
+
+void
+Platform::expose(HSQUIRRELVM vm, SQInteger table_idx)
+{
+  Scripting::Platform* interface = new Scripting::Platform(this);
+  expose_object(vm, table_idx, interface, "Platform", true);
+}
+
+void
+Platform::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
+{
+  Scripting::unexpose_object(vm, table_idx, "Platform");
+}
+
 IMPLEMENT_FACTORY(Platform, "platform");
index 8e981e5..3f1785b 100644 (file)
 #include "object/moving_sprite.hpp"
 #include "object/path.hpp"
 #include "object/path_walker.hpp"
+#include "script_interface.hpp"
 
 /**
  * This class is the base class for platforms that tux can stand on
  */
-class Platform : public MovingSprite
+class Platform : public MovingSprite, public ScriptInterface
 {
 public:
   Platform(const lisp::Lisp& reader);
@@ -42,6 +43,18 @@ public:
     return speed;
   }
 
+  /** Move platform until at given node, then stop */
+  void goto_node(int node_no);
+
+  /** Start moving platform */
+  void start_moving();
+
+  /** Stop platform at next node */
+  void stop_moving();
+
+  virtual void expose(HSQUIRRELVM vm, SQInteger table_idx);
+  virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx);
+
 private:
   std::auto_ptr<Path> path;
   std::auto_ptr<PathWalker> walker;
index 8b91593..6f8eae8 100644 (file)
@@ -8,3 +8,5 @@
 #include "player.hpp"
 #include "floating_image.hpp"
 #include "anchor_points.hpp"
+#include "platform.hpp"
+