From 6a5c52fa2a14acd773c628dcd9c04221fe6e960f Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 9 Feb 2006 00:54:38 +0000 Subject: [PATCH] first version of floating image SVN-Revision: 3050 --- data/images/objects/logo/logo.sprite | 6 + data/levels/test/default.nut | 8 +- data/levels/test/script.stl | 11 +- data/levels/test/yeti.stl | 2 +- data/levels/world2/level2.stl | 2 +- data/script/default.nut | 2 +- src/math/rect.hpp | 12 ++ src/resources.hpp | 2 - src/scripting/wrapper.cpp | 315 +++++++++++++++++++++++++++++++++++ src/scripting/wrapper.hpp | 1 + src/scripting/wrapper.interface.hpp | 3 + src/video/surface.hpp | 8 +- 12 files changed, 356 insertions(+), 16 deletions(-) create mode 100644 data/images/objects/logo/logo.sprite diff --git a/data/images/objects/logo/logo.sprite b/data/images/objects/logo/logo.sprite new file mode 100644 index 000000000..815e301e5 --- /dev/null +++ b/data/images/objects/logo/logo.sprite @@ -0,0 +1,6 @@ +(supertux-sprite + (action + (name "default") + (images "../../engine/menu/logo.png") + ) +) diff --git a/data/levels/test/default.nut b/data/levels/test/default.nut index 95cc3caeb..6c722002d 100644 --- a/data/levels/test/default.nut +++ b/data/levels/test/default.nut @@ -7,6 +7,7 @@ function intro() RADIO.set_action("quiet"); PENNY.set_action("stand-left"); NOLOK.set_visible(false); + local logo = FloatingImage("images/objects/logo/logo.sprite"); Tux.deactivate(); Tux.set_visible(false); DisplayEffect.sixteen_to_nine(0); @@ -24,10 +25,11 @@ function intro() SUPERTUX.set_velocity(50,0); Camera.scroll_to(3100, 945, 18); wait(10); - Text.set_text("SuperTux\n(Replace this with the title logo)"); - Text.fade_in(2); + logo.set_anchor_point(ANCHOR_TOP); + logo.set_pos(0, 50); + logo.set_visible(true); wait(5); - Text.fade_out(2); + logo.set_visible(false); wait(6); //begin conversation and Tux rap diff --git a/data/levels/test/script.stl b/data/levels/test/script.stl index 8a275bf29..581a84104 100644 --- a/data/levels/test/script.stl +++ b/data/levels/test/script.stl @@ -138,6 +138,11 @@ (solid #f) ) (init-script " + + local logo = FloatingImage(\"images/objects/logo/logo.sprite\"); + + logo.set_visible(true); + Text.set_text(translate(\"The Crazy Nolok Dance\")); Text.fade_in(2); TUX.set_action(\"jump\"); @@ -158,11 +163,11 @@ while(true) { } tuxjumps--; wait(0.5); - if(PENNY.get_animation() == \"stand\") { + if(PENNY.get_action() == \"stand\") { PENNY.set_action(\"throw\"); - } else if(PENNY.get_animation() == \"throw\") { + } else if(PENNY.get_action() == \"throw\") { PENNY.set_action(\"jump\"); - } else if(PENNY.get_animation() == \"jump\") { + } else if(PENNY.get_action() == \"jump\") { PENNY.set_action(\"dead\"); } else { Sound.play(\"sounds/grow.wav\"); diff --git a/data/levels/test/yeti.stl b/data/levels/test/yeti.stl index ef8f4322f..836d65b94 100644 --- a/data/levels/test/yeti.stl +++ b/data/levels/test/yeti.stl @@ -5,7 +5,7 @@ (author "Team") (sector (name "main") - (music "bossattack.ogg") + (music "music/bossattack.ogg") (gravity 10.000000) (tilemap (layer "background") diff --git a/data/levels/world2/level2.stl b/data/levels/world2/level2.stl index a7103be50..f83073680 100644 --- a/data/levels/world2/level2.stl +++ b/data/levels/world2/level2.stl @@ -187,7 +187,7 @@ (background (image "images/background/forest1.jpg") - (speed 1.000000) + (speed 0.7) ) (init-script "level2_init();") (secretarea (x 673.0) diff --git a/data/script/default.nut b/data/script/default.nut index 2fded5ba6..95b4f1340 100644 --- a/data/script/default.nut +++ b/data/script/default.nut @@ -1,7 +1,7 @@ function end_level() { - Sound.play_music("leveldone"); + Sound.play_music("music/leveldone.ogg"); Tux.deactivate(); wait(6); DisplayEffect.fade_out(2); diff --git a/src/math/rect.hpp b/src/math/rect.hpp index 03728ea40..f7179a9e7 100644 --- a/src/math/rect.hpp +++ b/src/math/rect.hpp @@ -26,6 +26,18 @@ public: assert(p1.x <= p2.x && p1.y <= p2.y); } + float get_left() const + { return p1.x; } + + float get_right() const + { return p2.x; } + + float get_top() const + { return p1.y; } + + float get_bottom() const + { return p2.y; } + float get_width() const { return p2.x - p1.x; } diff --git a/src/resources.hpp b/src/resources.hpp index 02639590a..1771aa567 100644 --- a/src/resources.hpp +++ b/src/resources.hpp @@ -19,8 +19,6 @@ #ifndef SUPERTUX_RESOURCES_H #define SUPERTUX_RESOURCES_H -#include - class SpriteManager; class Menu; class Font; diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index 2dd0c8f3c..746110cad 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -534,6 +534,130 @@ static int Player_get_visible_wrapper(HSQUIRRELVM v) return 1; } +static int FloatingImage_release_hook(SQUserPointer ptr, int ) +{ + Scripting::FloatingImage* _this = reinterpret_cast (ptr); + delete _this; + return 0; +} + +static int FloatingImage_constructor_wrapper(HSQUIRRELVM v) +{ + const char* arg0; + sq_getstring(v, 2, &arg0); + + Scripting::FloatingImage* _this = new Scripting::FloatingImage(arg0); + sq_setinstanceup(v, 1, _this); + sq_setreleasehook(v, 1, FloatingImage_release_hook); + + return 0; +} + +static int FloatingImage_set_layer_wrapper(HSQUIRRELVM v) +{ + Scripting::FloatingImage* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + int arg0; + sq_getinteger(v, 2, &arg0); + + _this->set_layer(arg0); + + return 0; +} + +static int FloatingImage_get_layer_wrapper(HSQUIRRELVM v) +{ + Scripting::FloatingImage* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + + int return_value = _this->get_layer(); + + sq_pushinteger(v, return_value); + return 1; +} + +static int FloatingImage_set_pos_wrapper(HSQUIRRELVM v) +{ + Scripting::FloatingImage* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + float arg0; + sq_getfloat(v, 2, &arg0); + float arg1; + sq_getfloat(v, 3, &arg1); + + _this->set_pos(arg0, arg1); + + return 0; +} + +static int FloatingImage_get_pos_x_wrapper(HSQUIRRELVM v) +{ + Scripting::FloatingImage* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + + float return_value = _this->get_pos_x(); + + sq_pushfloat(v, return_value); + return 1; +} + +static int FloatingImage_get_pos_y_wrapper(HSQUIRRELVM v) +{ + Scripting::FloatingImage* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + + float return_value = _this->get_pos_y(); + + sq_pushfloat(v, return_value); + return 1; +} + +static int FloatingImage_set_anchor_point_wrapper(HSQUIRRELVM v) +{ + Scripting::FloatingImage* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + int arg0; + sq_getinteger(v, 2, &arg0); + + _this->set_anchor_point(arg0); + + return 0; +} + +static int FloatingImage_get_anchor_point_wrapper(HSQUIRRELVM v) +{ + Scripting::FloatingImage* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + + int return_value = _this->get_anchor_point(); + + sq_pushinteger(v, return_value); + return 1; +} + +static int FloatingImage_set_visible_wrapper(HSQUIRRELVM v) +{ + Scripting::FloatingImage* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + SQBool arg0; + sq_getbool(v, 2, &arg0); + + _this->set_visible(arg0); + + return 0; +} + +static int FloatingImage_get_visible_wrapper(HSQUIRRELVM v) +{ + Scripting::FloatingImage* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + + bool return_value = _this->get_visible(); + + sq_pushbool(v, return_value); + return 1; +} + static int display_text_file_wrapper(HSQUIRRELVM v) { const char* arg0; @@ -770,6 +894,32 @@ void create_squirrel_instance(HSQUIRRELVM v, Scripting::Player* object, bool set sq_remove(v, -2); // remove root table } +void create_squirrel_instance(HSQUIRRELVM v, Scripting::FloatingImage* object, bool setup_releasehook) +{ + using namespace Wrapper; + + sq_pushroottable(v); + sq_pushstring(v, "FloatingImage", -1); + if(SQ_FAILED(sq_get(v, -2))) { + std::ostringstream msg; + msg << "Couldn't resolved squirrel type 'FloatingImage'"; + 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 'FloatingImage'"; + throw SquirrelError(v, msg.str()); + } + sq_remove(v, -2); // remove object name + + if(setup_releasehook) { + sq_setreleasehook(v, -1, FloatingImage_release_hook); + } + + sq_remove(v, -2); // remove root table +} + void register_supertux_wrapper(HSQUIRRELVM v) { using namespace Wrapper; @@ -815,6 +965,78 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, msg.str()); } + sq_pushstring(v, "ANCHOR_TOP", -1); + sq_pushinteger(v, 16); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'ANCHOR_TOP'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "ANCHOR_BOTTOM", -1); + sq_pushinteger(v, 32); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'ANCHOR_BOTTOM'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "ANCHOR_LEFT", -1); + sq_pushinteger(v, 1); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'ANCHOR_LEFT'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "ANCHOR_RIGHT", -1); + sq_pushinteger(v, 2); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'ANCHOR_RIGHT'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "ANCHOR_MIDDLE", -1); + sq_pushinteger(v, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'ANCHOR_MIDDLE'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "ANCHOR_TOP_LEFT", -1); + sq_pushinteger(v, 17); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'ANCHOR_TOP_LEFT'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "ANCHOR_TOP_RIGHT", -1); + sq_pushinteger(v, 18); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'ANCHOR_TOP_RIGHT'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "ANCHOR_BOTTOM_LEFT", -1); + sq_pushinteger(v, 33); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'ANCHOR_BOTTOM_LEFT'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "ANCHOR_BOTTOM_RIGHT", -1); + sq_pushinteger(v, 34); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'ANCHOR_BOTTOM_RIGHT'"; + throw SquirrelError(v, msg.str()); + } + sq_pushstring(v, "display_text_file", -1); sq_newclosure(v, &display_text_file_wrapper, 0); if(SQ_FAILED(sq_createslot(v, -3))) { @@ -1258,6 +1480,99 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, msg.str()); } + // Register class FloatingImage + sq_pushstring(v, "FloatingImage", -1); + if(sq_newclass(v, SQFalse) < 0) { + std::ostringstream msg; + msg << "Couldn't create new class 'FloatingImage'"; + throw SquirrelError(v, msg.str()); + } + sq_pushstring(v, "constructor", -1); + sq_newclosure(v, &FloatingImage_constructor_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'constructor'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "set_layer", -1); + sq_newclosure(v, &FloatingImage_set_layer_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'set_layer'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "get_layer", -1); + sq_newclosure(v, &FloatingImage_get_layer_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'get_layer'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "set_pos", -1); + sq_newclosure(v, &FloatingImage_set_pos_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'set_pos'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "get_pos_x", -1); + sq_newclosure(v, &FloatingImage_get_pos_x_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'get_pos_x'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "get_pos_y", -1); + sq_newclosure(v, &FloatingImage_get_pos_y_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'get_pos_y'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "set_anchor_point", -1); + sq_newclosure(v, &FloatingImage_set_anchor_point_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'set_anchor_point'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "get_anchor_point", -1); + sq_newclosure(v, &FloatingImage_get_anchor_point_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'get_anchor_point'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "set_visible", -1); + sq_newclosure(v, &FloatingImage_set_visible_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'set_visible'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "get_visible", -1); + sq_newclosure(v, &FloatingImage_get_visible_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'get_visible'"; + throw SquirrelError(v, msg.str()); + } + + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register class'FloatingImage'"; + throw SquirrelError(v, msg.str()); + } + sq_pop(v, 1); } diff --git a/src/scripting/wrapper.hpp b/src/scripting/wrapper.hpp index 7f69ea8e0..d0b969aac 100644 --- a/src/scripting/wrapper.hpp +++ b/src/scripting/wrapper.hpp @@ -21,6 +21,7 @@ void create_squirrel_instance(HSQUIRRELVM v, Scripting::ScriptedObject* object, void create_squirrel_instance(HSQUIRRELVM v, Scripting::Sound* object, bool setup_releasehook = false); void create_squirrel_instance(HSQUIRRELVM v, Scripting::Text* object, bool setup_releasehook = false); void create_squirrel_instance(HSQUIRRELVM v, Scripting::Player* object, bool setup_releasehook = false); +void create_squirrel_instance(HSQUIRRELVM v, Scripting::FloatingImage* object, bool setup_releasehook = false); } diff --git a/src/scripting/wrapper.interface.hpp b/src/scripting/wrapper.interface.hpp index b47c755c7..68a98a10a 100644 --- a/src/scripting/wrapper.interface.hpp +++ b/src/scripting/wrapper.interface.hpp @@ -7,3 +7,6 @@ #include "text.hpp" #include "functions.hpp" #include "player.hpp" +#include "floating_image.hpp" +#include "anchor_points.hpp" + diff --git a/src/video/surface.hpp b/src/video/surface.hpp index a5ba95558..bafe85c56 100644 --- a/src/video/surface.hpp +++ b/src/video/surface.hpp @@ -35,8 +35,9 @@ enum DrawingEffect { }; /** - * Container class that holds a surface, necessary so that we can - * reload Surface implementations on the fly + * A rectangular image. + * The class basically holds a reference to a texture with additional UV + * coordinates that specify a rectangular area on this texture */ class Surface { @@ -66,9 +67,6 @@ public: /** flip the surface horizontally */ void hflip(); - /** Reload the surface, which is necesarry in case of a mode swich */ - void reload(); - const Surface& operator= (const Surface& other); float get_width() const -- 2.11.0