4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "platform.hpp"
26 #include "video/drawing_context.hpp"
27 #include "resources.hpp"
30 #include "path_walker.hpp"
31 #include "sprite/sprite.hpp"
32 #include "lisp/lisp.hpp"
33 #include "object_factory.hpp"
34 #include "scripting/platform.hpp"
35 #include "scripting/squirrel_util.hpp"
37 Platform::Platform(const lisp::Lisp& reader)
38 : MovingSprite(reader, Vector(0,0), LAYER_OBJECTS, COLGROUP_STATIC), speed(Vector(0,0))
41 reader.get("name", name);
42 reader.get("running", running);
43 const lisp::Lisp* pathLisp = reader.get_lisp("path");
45 throw std::runtime_error("No path specified for platform");
46 path.reset(new Path());
47 path->read(*pathLisp);
48 walker.reset(new PathWalker(path.get(), running));
49 bbox.set_pos(path->get_base());
52 Platform::Platform(const Platform& other)
53 : MovingSprite(other), ScriptInterface(other), speed(other.speed)
56 path.reset(new Path(*other.path));
57 walker.reset(new PathWalker(*other.walker));
58 walker->path = &*path;
62 Platform::collision(GameObject& , const CollisionHit& )
68 Platform::update(float elapsed_time)
70 movement = walker->advance(elapsed_time) - get_pos();
71 speed = movement / elapsed_time;
75 Platform::goto_node(int node_no)
77 walker->goto_node(node_no);
81 Platform::start_moving()
83 walker->start_moving();
87 Platform::stop_moving()
89 walker->stop_moving();
93 Platform::expose(HSQUIRRELVM vm, SQInteger table_idx)
95 if (name.empty()) return;
96 Scripting::Platform* interface = new Scripting::Platform(this);
97 expose_object(vm, table_idx, interface, name, true);
101 Platform::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
103 if (name.empty()) return;
104 Scripting::unexpose_object(vm, table_idx, name);
107 IMPLEMENT_FACTORY(Platform, "platform");