X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fplatform.cpp;h=d6dde0a7c983c15032cb53688fafbc71428c3769;hb=5f1c84ed5ce0ab5450f92082a9aaaa9ca0effc39;hp=b0b2a3b1c1bce0c23d44d778b89598f36cc6388e;hpb=07ddaed2a657e4d2a3d038fed223fc5827159caf;p=supertux.git diff --git a/src/object/platform.cpp b/src/object/platform.cpp index b0b2a3b1c..d6dde0a7c 100644 --- a/src/object/platform.cpp +++ b/src/object/platform.cpp @@ -28,34 +28,35 @@ #include "player.hpp" #include "path.hpp" #include "path_walker.hpp" -#include "sprite/sprite_manager.hpp" +#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), name(""), speed(Vector(0,0)) { - std::string sprite_name; - reader.get("sprite", sprite_name); - if(sprite_name == "") - throw std::runtime_error("No sprite specified in platform object"); - sprite.reset(sprite_manager->create(sprite_name)); - + bool running = true; + reader.get("name", name); + reader.get("running", running); const lisp::Lisp* pathLisp = reader.get_lisp("path"); if(pathLisp == NULL) throw std::runtime_error("No path specified for platform"); path.reset(new Path()); path->read(*pathLisp); - walker.reset(new PathWalker(path.get())); - - bbox.p1 = path->get_base(); - bbox.set_size(sprite->get_width(), sprite->get_height()); - - set_group(COLGROUP_STATIC); + walker.reset(new PathWalker(path.get(), running)); + bbox.set_pos(path->get_base()); + flags |= FLAG_SOLID; } -Platform::~Platform() +Platform::Platform(const Platform& other) + : MovingSprite(other), ScriptInterface(other), name(other.name), speed(other.speed) { + path.reset(new Path(*other.path)); + walker.reset(new PathWalker(*other.walker)); + walker->path = &*path; } //TODO: Squish Tux when standing between platform and solid tile/object @@ -87,9 +88,36 @@ Platform::update(float elapsed_time) } void -Platform::draw(DrawingContext& context) +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) +{ + if (name == "") return; + Scripting::Platform* interface = new Scripting::Platform(this); + expose_object(vm, table_idx, interface, name, true); +} + +void +Platform::unexpose(HSQUIRRELVM vm, SQInteger table_idx) { - sprite->draw(context, get_pos(), LAYER_OBJECTS); + if (name == "") return; + Scripting::unexpose_object(vm, table_idx, name); } IMPLEMENT_FACTORY(Platform, "platform");