make igloo the first level
authorMatthias Braun <matze@braunis.de>
Sun, 23 Apr 2006 14:49:35 +0000 (14:49 +0000)
committerMatthias Braun <matze@braunis.de>
Sun, 23 Apr 2006 14:49:35 +0000 (14:49 +0000)
SVN-Revision: 3386

15 files changed:
data/images/objects/invisible/invisible.png [new file with mode: 0644]
data/images/objects/invisible/invisible.sprite [new file with mode: 0644]
data/levels/world1/worldmap.stwm
data/levels/world2/default.nut
data/levels/world2/level2.stl
src/object/block.cpp
src/object/floating_image.cpp
src/object/floating_image.hpp
src/object/scripted_object.cpp
src/player_status.cpp
src/scripting/floating_image.cpp
src/scripting/floating_image.hpp
src/scripting/wrapper.cpp
src/sprite/sprite.cpp
src/sprite/sprite.hpp

diff --git a/data/images/objects/invisible/invisible.png b/data/images/objects/invisible/invisible.png
new file mode 100644 (file)
index 0000000..a587ad9
Binary files /dev/null and b/data/images/objects/invisible/invisible.png differ
diff --git a/data/images/objects/invisible/invisible.sprite b/data/images/objects/invisible/invisible.sprite
new file mode 100644 (file)
index 0000000..a9cce7c
--- /dev/null
@@ -0,0 +1,6 @@
+(supertux-sprite
+  (action
+    (name "default")
+    (images "invisible.png")
+  )
+)
index 7062bce..f01f3e0 100644 (file)
       (x 3)
       (y 28)
     )
+    (level
+      (name "intro.stl")
+      (x 22)
+      (y 4)
+      (sprite "images/objects/invisible/invisible.sprite")
+    )
     (special-tile
       (teleport-to-x 9)
       (teleport-to-y 15)
index 0713e29..091e665 100644 (file)
@@ -1,4 +1,5 @@
 
+
 function get_gold_key()
 {
   add_key(KEY_GOLD);
@@ -20,3 +21,31 @@ function level2_init()
   Effect.four_to_three();
   Tux.activate();
 }
+
+// Initialize keys
+if(! ("world2_keys" in state))
+       state.world2_keys <- {}
+       
+local keys = state.world2_keys;
+if(! ("brass" in keys))
+       keys.brass <- false;
+if(! ("gold" in keys))
+       keys.gold <- false;
+
+local x = 10;
+local y = 10;
+
+key_brass <- FloatingImage("images/objects/keys/key_brass.sprite");
+key_brass.set_anchor_point(ANCHOR_TOPLEFT);
+key_brass.set_pos(x, y);
+key_brass.set_visible(true);
+key_brass.set_action(keys.brass ? "display" : "outline");
+x += 30;
+
+key_gold <- FloatingImage("images/objects/keys/key_gold.sprite");
+key_gold.set_anchor_point(ANCHOR_TOPLEFT);
+key_gold.set_pos(x, y);
+key_gold.set_visible(true);
+key_gold.set_action(keys.gold ? "display" : "outline");
+x += 30;
+
index b830769..9a9f08d 100644 (file)
        )
        (init-script "
           import(\"levels/world2/default.nut\");
-          import(\"scripts/default.nut\");
-          level2_init();
         ")
        (secretarea (x 673.0)
                     (y 1090.0)
index 7f6e9f4..6d0c5f4 100644 (file)
@@ -204,7 +204,7 @@ BonusBlock::hit(Player& )
 void
 BonusBlock::try_open()
 {
-  if(sprite->get_action_name() == "empty") {
+  if(sprite->get_action() == "empty") {
     sound_manager->play("sounds/brick.wav");
     return;
   }
@@ -282,7 +282,7 @@ Brick::Brick(const Vector& pos, int data)
 void
 Brick::hit(Player& )
 {
-  if(sprite->get_action_name() == "empty")
+  if(sprite->get_action() == "empty")
     return;
   
   try_break(true);
@@ -291,7 +291,7 @@ Brick::hit(Player& )
 void
 Brick::try_break(bool playerhit)
 {
-  if(sprite->get_action_name() == "empty")
+  if(sprite->get_action() == "empty")
     return;
   
   sound_manager->play("sounds/brick.wav");
index 4dc8c6a..6041bae 100644 (file)
@@ -46,6 +46,18 @@ FloatingImage::update(float elapsed_time)
 }
 
 void
+FloatingImage::set_action(const std::string& action)
+{
+  sprite->set_action(action);
+}
+
+std::string
+FloatingImage::get_action()
+{
+  return sprite->get_action();
+}
+
+void
 FloatingImage::draw(DrawingContext& context)
 {
   if(!visible)
index 0c827fa..7e7ddc3 100644 (file)
@@ -62,6 +62,9 @@ public:
     return visible;
   }
 
+  void set_action(const std::string& action);
+  std::string get_action();
+
   void update(float elapsed_time);
   void draw(DrawingContext& context);
 
index 07eebb3..47839d2 100644 (file)
@@ -142,7 +142,7 @@ ScriptedObject::set_action(const std::string& animation)
 std::string
 ScriptedObject::get_action()
 {
-  return sprite->get_action_name();
+  return sprite->get_action();
 }
 
 std::string
index 432640c..edd22ce 100644 (file)
@@ -199,7 +199,7 @@ PlayerStatus::draw(DrawingContext& context)
   context.draw_text(white_text, coinstext, Vector(SCREEN_WIDTH - white_text->get_text_width(coinstext) - gold_text->get_text_width(" 99999") - BORDER_X, BORDER_Y), LEFT_ALLIGN, LAYER_FOREGROUND1);
   context.draw_text(gold_text, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), RIGHT_ALLIGN, LAYER_FOREGROUND1);
 
-  draw_keys(context);  
+  //draw_keys(context);  
 
   context.pop_transform();
 }
index db8292e..8b09e64 100644 (file)
@@ -94,4 +94,16 @@ FloatingImage::set_visible(bool visible)
   floating_image->set_visible(visible);
 }
 
+void
+FloatingImage::set_action(const std::string& action)
+{
+  floating_image->set_action(action);
+}
+
+std::string
+FloatingImage::get_action()
+{
+  return floating_image->get_action();
+}
+
 }
index 42dcf36..78f39df 100644 (file)
@@ -46,6 +46,8 @@ public:
   int get_anchor_point();
   void set_visible(bool visible);
   bool get_visible();
+  void set_action(const std::string& action);
+  std::string get_action();
   
 #ifndef SCRIPTING_API
 private:
index d28de47..57d74ed 100644 (file)
@@ -1413,6 +1413,58 @@ static int FloatingImage_get_visible_wrapper(HSQUIRRELVM vm)
   
 }
 
+static int FloatingImage_set_action_wrapper(HSQUIRRELVM vm)
+{
+  Scripting::FloatingImage* _this;
+  if(SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast<SQUserPointer*> (&_this), 0))) {
+    sq_throwerror(vm, _SC("'set_action' called without instance"));
+    return SQ_ERROR;
+  }
+  const char* arg0;
+  if(SQ_FAILED(sq_getstring(vm, 2, &arg0))) {
+    sq_throwerror(vm, _SC("Argument 1 not a string"));
+    return SQ_ERROR;
+  }
+  
+  try {
+    _this->set_action(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 'set_action'"));
+    return SQ_ERROR;
+  }
+  
+}
+
+static int FloatingImage_get_action_wrapper(HSQUIRRELVM vm)
+{
+  Scripting::FloatingImage* _this;
+  if(SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast<SQUserPointer*> (&_this), 0))) {
+    sq_throwerror(vm, _SC("'get_action' called without instance"));
+    return SQ_ERROR;
+  }
+  
+  try {
+    std::string return_value = _this->get_action();
+  
+    sq_pushstring(vm, return_value.c_str(), return_value.size());
+    return 1;
+  
+  } catch(std::exception& e) {
+    sq_throwerror(vm, e.what());
+    return SQ_ERROR;
+  } catch(...) {
+    sq_throwerror(vm, _SC("Unexpected exception while executing function 'get_action'"));
+    return SQ_ERROR;
+  }
+  
+}
+
 static int display_wrapper(HSQUIRRELVM vm)
 {
   return Scripting::display(vm);
@@ -2843,6 +2895,18 @@ void register_supertux_wrapper(HSQUIRRELVM v)
     throw SquirrelError(v, "Couldn't register function 'get_visible'");
   }
 
+  sq_pushstring(v, "set_action", -1);
+  sq_newclosure(v, &FloatingImage_set_action_wrapper, 0);
+  if(SQ_FAILED(sq_createslot(v, -3))) {
+    throw SquirrelError(v, "Couldn't register function 'set_action'");
+  }
+
+  sq_pushstring(v, "get_action", -1);
+  sq_newclosure(v, &FloatingImage_get_action_wrapper, 0);
+  if(SQ_FAILED(sq_createslot(v, -3))) {
+    throw SquirrelError(v, "Couldn't register function 'get_action'");
+  }
+
   if(SQ_FAILED(sq_createslot(v, -3))) {
     throw SquirrelError(v, "Couldn't register class 'FloatingImage'");
   }
index 4d68980..3ab4554 100644 (file)
@@ -100,7 +100,7 @@ Sprite::draw(DrawingContext& context, const Vector& pos, int layer)
   update();
 
   if((int)frame >= get_frames() || (int)frame < 0)
-    log_warning << "frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() << "/" << get_action_name() << std::endl;
+    log_warning << "frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
   else
     context.draw_surface(action->surfaces[(int)frame],
             pos - Vector(action->x_offset, action->y_offset),
index e86a58b..229f634 100644 (file)
@@ -64,7 +64,7 @@ public:
   const std::string& get_name() const
   { return data.name; }
   /** Get current action name */
-  const std::string& get_action_name() const
+  const std::string& get_action() const
   { return action->name; }
 
   int get_width() const;