#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;
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);
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()
{
*/
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:
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;
/**
#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))
}
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));
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");
#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);
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;
#include "player.hpp"
#include "floating_image.hpp"
#include "anchor_points.hpp"
+#include "platform.hpp"
+