first version of floating image
authorMatthias Braun <matze@braunis.de>
Thu, 9 Feb 2006 00:54:38 +0000 (00:54 +0000)
committerMatthias Braun <matze@braunis.de>
Thu, 9 Feb 2006 00:54:38 +0000 (00:54 +0000)
SVN-Revision: 3050

12 files changed:
data/images/objects/logo/logo.sprite [new file with mode: 0644]
data/levels/test/default.nut
data/levels/test/script.stl
data/levels/test/yeti.stl
data/levels/world2/level2.stl
data/script/default.nut
src/math/rect.hpp
src/resources.hpp
src/scripting/wrapper.cpp
src/scripting/wrapper.hpp
src/scripting/wrapper.interface.hpp
src/video/surface.hpp

diff --git a/data/images/objects/logo/logo.sprite b/data/images/objects/logo/logo.sprite
new file mode 100644 (file)
index 0000000..815e301
--- /dev/null
@@ -0,0 +1,6 @@
+(supertux-sprite
+  (action
+    (name "default")
+    (images "../../engine/menu/logo.png")
+  )
+)
index 95cc3ca..6c72200 100644 (file)
@@ -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
index 8a275bf..581a841 100644 (file)
          (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\");
index ef8f432..836d65b 100644 (file)
@@ -5,7 +5,7 @@
   (author "Team")
   (sector
     (name  "main")
-    (music  "bossattack.ogg")
+    (music  "music/bossattack.ogg")
     (gravity 10.000000)
     (tilemap
       (layer  "background")
index a7103be..f830736 100644 (file)
 
        (background
          (image "images/background/forest1.jpg")
-         (speed 1.000000)
+         (speed 0.7)
        )
        (init-script "level2_init();")
        (secretarea (x 673.0)
index 2fded5b..95b4f13 100644 (file)
@@ -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);
index 03728ea..f7179a9 100644 (file)
@@ -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; }
 
index 0263959..1771aa5 100644 (file)
@@ -19,8 +19,6 @@
 #ifndef SUPERTUX_RESOURCES_H
 #define SUPERTUX_RESOURCES_H
 
-#include <string>
-
 class SpriteManager;
 class Menu;
 class Font;
index 2dd0c8f..746110c 100644 (file)
@@ -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<Scripting::FloatingImage*> (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);
 }
 
index 7f69ea8..d0b969a 100644 (file)
@@ -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);
 
 }
 
index b47c755..68a98a1 100644 (file)
@@ -7,3 +7,6 @@
 #include "text.hpp"
 #include "functions.hpp"
 #include "player.hpp"
+#include "floating_image.hpp"
+#include "anchor_points.hpp"
+
index a5ba955..bafe85c 100644 (file)
@@ -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