From a48ee7c0b3e60c9f21499054446aeaeca6914f46 Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Thu, 25 May 2006 13:51:47 +0000 Subject: [PATCH] First tries at making platform scriptable SVN-Revision: 3582 --- src/object/path_walker.cpp | 23 ++++++++++++++++++++++- src/object/path_walker.hpp | 14 ++++++++++++++ src/object/platform.cpp | 35 ++++++++++++++++++++++++++++++++++- src/object/platform.hpp | 15 ++++++++++++++- src/scripting/wrapper.interface.hpp | 2 ++ 5 files changed, 86 insertions(+), 3 deletions(-) diff --git a/src/object/path_walker.cpp b/src/object/path_walker.cpp index 07c2b5ada..abb42bc1e 100644 --- a/src/object/path_walker.cpp +++ b/src/object/path_walker.cpp @@ -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(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() { diff --git a/src/object/path_walker.hpp b/src/object/path_walker.hpp index 9f237eff6..3766497f2 100644 --- a/src/object/path_walker.hpp +++ b/src/object/path_walker.hpp @@ -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; /** diff --git a/src/object/platform.cpp b/src/object/platform.cpp index 6f405c8f6..fa9e3153b 100644 --- a/src/object/platform.cpp +++ b/src/object/platform.cpp @@ -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"); diff --git a/src/object/platform.hpp b/src/object/platform.hpp index 8e981e5ae..3f1785b8e 100644 --- a/src/object/platform.hpp +++ b/src/object/platform.hpp @@ -24,11 +24,12 @@ #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; std::auto_ptr walker; diff --git a/src/scripting/wrapper.interface.hpp b/src/scripting/wrapper.interface.hpp index 8b9159314..6f8eae83b 100644 --- a/src/scripting/wrapper.interface.hpp +++ b/src/scripting/wrapper.interface.hpp @@ -8,3 +8,5 @@ #include "player.hpp" #include "floating_image.hpp" #include "anchor_points.hpp" +#include "platform.hpp" + -- 2.11.0