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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 313 314 0 0 0 1708 1708 1708 1708 1708 1708 1708 1708 1708 1708 1708 1708 1708 1708 1708 1708 1708 1708 1708 1708 1708 1708 1708 1708 1708 315 316 1708 1708 1708 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1705 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1705 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1705 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1705 1700 1700 1700 1700 1700 1700 1700 1700 1700 1705 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1705 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1705 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1705 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1705 1700 1700 1700 1700 1700 1700 1700 1705 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1705 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1705 1700 1700 1700 1700 1700 1700 1700 1705 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1705 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700 1700)
+ (path
+ (mode "circular")
+ (node
+ (x 0)
+ (y 0)
+ (time 20)
+ )
+ (node
+ (x 0)
+ (y -1280)
+ )
+ )
)
(camera
(mode "normal")
(x 64)
(y 608)
)
+ (scripttrigger
+ (script "risinglava.goto_node(1);")
+ (button #f)
+ (width 32)
+ (height 236)
+ (x 160)
+ (y 468)
+ )
)
)
#include "object_factory.hpp"
#include "main.hpp"
#include "log.hpp"
+#include "scripting/tilemap.hpp"
+#include "scripting/squirrel_util.hpp"
TileMap::TileMap()
: solid(false), speed(1), width(0), height(0), z_pos(0), x_offset(0), y_offset(0),
speed = 1;
}
+ const lisp::Lisp* pathLisp = reader.get_lisp("path");
+ if (pathLisp) {
+ path.reset(new Path());
+ path->read(*pathLisp);
+ walker.reset(new PathWalker(path.get(), /*running*/false));
+ Vector v = path->get_base();
+ set_x_offset(v.x);
+ set_y_offset(v.y);
+ }
+
reader.get("width", width);
reader.get("height", height);
if(width < 0 || height < 0)
}
}
- // FIXME: testing only
- static int step = 0;
- if (step++ > 10) {
- step = 0;
- if (name == "risinglava") set_y_offset(get_y_offset() - 1);
+ // if we have a path to follow, follow it
+ if (walker.get()) {
+ Vector v = walker->advance(elapsed_time);
+ set_x_offset(v.x);
+ set_y_offset(v.y);
}
}
/** if we don't round here, we'll have a 1 pixel gap on screen sometimes.
* I have no idea why */
- float start_x = ((int)((roundf(context.get_translation().x) - x_offset) / 32)) * 32 + x_offset;
- float start_y = ((int)((roundf(context.get_translation().y) - y_offset) / 32)) * 32 + y_offset;
- float end_x = std::min(start_x + SCREEN_WIDTH + 32, float(width * 32 + x_offset));
- float end_y = std::min(start_y + SCREEN_HEIGHT + 32, float(height * 32 + y_offset));
- int tsx = int((start_x - x_offset) / 32); // tilestartindex x
- int tsy = int((start_y - y_offset) / 32); // tilestartindex y
+ float start_x = ((int)((roundf(context.get_translation().x) - roundf(x_offset)) / 32)) * 32 + roundf(x_offset);
+ float start_y = ((int)((roundf(context.get_translation().y) - roundf(y_offset)) / 32)) * 32 + roundf(y_offset);
+ float end_x = std::min(start_x + SCREEN_WIDTH + 32, float(width * 32 + roundf(x_offset)));
+ float end_y = std::min(start_y + SCREEN_HEIGHT + 32, float(height * 32 + roundf(y_offset)));
+ int tsx = int((start_x - roundf(x_offset)) / 32); // tilestartindex x
+ int tsy = int((start_y - roundf(y_offset)) / 32); // tilestartindex y
Vector pos;
int tx, ty;
}
void
+TileMap::goto_node(int node_no)
+{
+ if (!walker.get()) return;
+ walker->goto_node(node_no);
+}
+
+void
+TileMap::start_moving()
+{
+ if (!walker.get()) return;
+ walker->start_moving();
+}
+
+void
+TileMap::stop_moving()
+{
+ if (!walker.get()) return;
+ walker->stop_moving();
+}
+
+void
+TileMap::expose(HSQUIRRELVM vm, SQInteger table_idx)
+{
+ if (name.empty()) return;
+ if (!walker.get()) return;
+ Scripting::TileMap* interface = new Scripting::TileMap(this);
+ expose_object(vm, table_idx, interface, name, true);
+}
+
+void
+TileMap::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
+{
+ if (name.empty()) return;
+ if (!walker.get()) return;
+ Scripting::unexpose_object(vm, table_idx, name);
+}
+
+void
TileMap::set(int newwidth, int newheight, const std::vector<unsigned int>&newt,
int new_z_pos, bool newsolid)
{
#include "serializable.hpp"
#include "math/vector.hpp"
#include "video/drawing_context.hpp"
+#include "object/path.hpp"
+#include "object/path_walker.hpp"
+#include "script_interface.hpp"
namespace lisp {
class Lisp;
/**
* This class is reponsible for drawing the level tiles
*/
-class TileMap : public GameObject, public Serializable
+class TileMap : public GameObject, public Serializable, public ScriptInterface
{
public:
TileMap();
virtual void update(float elapsed_time);
virtual void draw(DrawingContext& context);
+ /** Move tilemap until at given node, then stop */
+ void goto_node(int node_no);
+
+ /** Start moving tilemap */
+ void start_moving();
+
+ /** Stop tilemap at next node */
+ void stop_moving();
+
+ virtual void expose(HSQUIRRELVM vm, SQInteger table_idx);
+ virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx);
+
void set(int width, int height, const std::vector<unsigned int>& vec,
int z_pos, bool solid);
float alpha; /**< requested tilemap opacity */
float current_alpha; /**< current tilemap opacity */
float remaining_fade_time; /**< seconds until requested tilemap opacity is reached */
+
+ std::auto_ptr<Path> path;
+ std::auto_ptr<PathWalker> walker;
};
#endif /*SUPERTUX_TILEMAP_H*/
}
+static SQInteger TileMap_release_hook(SQUserPointer ptr, SQInteger )
+{
+ Scripting::TileMap* _this = reinterpret_cast<Scripting::TileMap*> (ptr);
+ delete _this;
+ return 0;
+}
+
+static SQInteger TileMap_goto_node_wrapper(HSQUIRRELVM vm)
+{
+ SQUserPointer data;
+ if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0))) {
+ sq_throwerror(vm, _SC("'goto_node' called without instance"));
+ return SQ_ERROR;
+ }
+ Scripting::TileMap* _this = reinterpret_cast<Scripting::TileMap*> (data);
+ SQInteger arg0;
+ if(SQ_FAILED(sq_getinteger(vm, 2, &arg0))) {
+ sq_throwerror(vm, _SC("Argument 1 not an integer"));
+ return SQ_ERROR;
+ }
+
+ try {
+ _this->goto_node(static_cast<int> (arg0));
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'goto_node'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static SQInteger TileMap_start_moving_wrapper(HSQUIRRELVM vm)
+{
+ SQUserPointer data;
+ if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0))) {
+ sq_throwerror(vm, _SC("'start_moving' called without instance"));
+ return SQ_ERROR;
+ }
+ Scripting::TileMap* _this = reinterpret_cast<Scripting::TileMap*> (data);
+
+ try {
+ _this->start_moving();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'start_moving'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static SQInteger TileMap_stop_moving_wrapper(HSQUIRRELVM vm)
+{
+ SQUserPointer data;
+ if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0))) {
+ sq_throwerror(vm, _SC("'stop_moving' called without instance"));
+ return SQ_ERROR;
+ }
+ Scripting::TileMap* _this = reinterpret_cast<Scripting::TileMap*> (data);
+
+ try {
+ _this->stop_moving();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'stop_moving'"));
+ return SQ_ERROR;
+ }
+
+}
+
static SQInteger display_wrapper(HSQUIRRELVM vm)
{
return Scripting::display(vm);
sq_remove(v, -2); // remove root table
}
+void create_squirrel_instance(HSQUIRRELVM v, Scripting::TileMap* object, bool setup_releasehook)
+{
+ using namespace Wrapper;
+
+ sq_pushroottable(v);
+ sq_pushstring(v, "TileMap", -1);
+ if(SQ_FAILED(sq_get(v, -2))) {
+ std::ostringstream msg;
+ msg << "Couldn't resolved squirrel type 'TileMap'";
+ throw SquirrelError(v, msg.str());
+ }
+
+ if(SQ_FAILED(sq_createinstance(v, -1)) || SQ_FAILED(sq_setinstanceup(v, -1, object))) {
+ std::ostringstream msg;
+ msg << "Couldn't setup squirrel instance for object of type 'TileMap'";
+ throw SquirrelError(v, msg.str());
+ }
+ sq_remove(v, -2); // remove object name
+
+ if(setup_releasehook) {
+ sq_setreleasehook(v, -1, TileMap_release_hook);
+ }
+
+ sq_remove(v, -2); // remove root table
+}
+
void register_supertux_wrapper(HSQUIRRELVM v)
{
using namespace Wrapper;
throw SquirrelError(v, "Couldn't register class 'Thunderstorm'");
}
+ // Register class TileMap
+ sq_pushstring(v, "TileMap", -1);
+ if(sq_newclass(v, SQFalse) < 0) {
+ std::ostringstream msg;
+ msg << "Couldn't create new class 'TileMap'";
+ throw SquirrelError(v, msg.str());
+ }
+ sq_pushstring(v, "goto_node", -1);
+ sq_newclosure(v, &TileMap_goto_node_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'goto_node'");
+ }
+
+ sq_pushstring(v, "start_moving", -1);
+ sq_newclosure(v, &TileMap_start_moving_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'start_moving'");
+ }
+
+ sq_pushstring(v, "stop_moving", -1);
+ sq_newclosure(v, &TileMap_stop_moving_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'stop_moving'");
+ }
+
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register class 'TileMap'");
+ }
+
}
} // end of namespace Scripting
void create_squirrel_instance(HSQUIRRELVM v, Scripting::Wind* object, bool setup_releasehook = false);
void create_squirrel_instance(HSQUIRRELVM v, Scripting::AmbientSound* object, bool setup_releasehook = false);
void create_squirrel_instance(HSQUIRRELVM v, Scripting::Thunderstorm* object, bool setup_releasehook = false);
+void create_squirrel_instance(HSQUIRRELVM v, Scripting::TileMap* object, bool setup_releasehook = false);
}
#include "wind.hpp"
#include "ambient_sound.hpp"
#include "thunderstorm.hpp"
+#include "tilemap.hpp"