Update Swedish translation.
[supertux.git] / data / levels / world2 / default.nut
index 0713e29..4d720bd 100644 (file)
@@ -1,14 +1,16 @@
-
-function get_gold_key()
+function add_key(key)
 {
-  add_key(KEY_GOLD);
-  end_level();
+  local keys = state.world2_keys;
+  keys[key] = true;
+  update_keys();
 }
 
 function level2_init()
 {
-  add_key(KEY_BRASS);
-  add_key(KEY_IRON);
+  foreach(name in ["air", "earth", "wood", "fire", "water"])
+  {
+    add_key(name);
+  }
   Tux.deactivate();
   Effect.sixteen_to_nine(2);
   Text.set_text(translate("---Insert Cutscene Here---"));
@@ -20,3 +22,45 @@ function level2_init()
   Effect.four_to_three();
   Tux.activate();
 }
+
+/***************************************
+ * Handling of the "keys" in the world *
+ ***************************************/
+if(! ("world2_keys" in state))
+       state.world2_keys <- {}
+       
+local keys = state.world2_keys;
+foreach(name in ["air", "earth", "wood", "fire", "water"])
+{
+  if(! (name in keys))
+    keys[name] <- false;
+}
+
+/// this function updates the key images (call this if tux has collected a key)
+function update_keys()
+{
+       local keys = state.world2_keys;
+       foreach(name in ["air", "earth", "wood", "fire", "water"])
+       {
+         key[name].set_action(keys[name] ? "display" : "outline");
+       }
+}
+
+if(! ("key" in this))
+ key <- {};
+
+local x = 10;
+local y = 10;
+
+foreach(name in ["air", "earth", "wood", "fire", "water"])
+{
+  if(! (name in key) ) {
+    key[name] <- FloatingImage("images/objects/keys/key_" + name + ".sprite");
+    key[name].set_anchor_point(ANCHOR_TOP_LEFT);
+    key[name].set_pos(x, y);
+    key[name].set_visible(true);
+  }
+  x += 30;
+}
+
+update_keys();