missingkeys.patch by mathnerd314 to no longer overwrite keys.
[supertux.git] / data / levels / world2 / default.nut
1 function add_key(key)
2 {
3   local keys = state.world2_keys;
4   keys[key] = true;
5   update_keys();
6 }
7
8 function level2_init()
9 {
10   foreach(name in ["air", "earth", "wood", "fire", "water"])
11   {
12     add_key(name);
13   }
14   Tux.deactivate();
15   Effect.sixteen_to_nine(2);
16   Text.set_text(translate("---Insert Cutscene Here---"));
17   Tux.walk(100);
18   Text.fade_in(2);
19   wait(4);
20   Text.fade_out(1);
21   wait(1);
22   Effect.four_to_three();
23   Tux.activate();
24 }
25
26 /***************************************
27  * Handling of the "keys" in the world *
28  ***************************************/
29 if(! ("world2_keys" in state))
30         state.world2_keys <- {}
31         
32 local keys = state.world2_keys;
33 foreach(name in ["air", "earth", "wood", "fire", "water"])
34 {
35   if(! (name in keys))
36     keys[name] <- false;
37 }
38
39 /// this function updates the key images (call this if tux has collected a key)
40 function update_keys()
41 {
42         local keys = state.world2_keys;
43         foreach(name in ["air", "earth", "wood", "fire", "water"])
44         {
45           key[name].set_action(keys[name] ? "display" : "outline");
46         }
47 }
48
49 if(! ("key" in this))
50  key <- {};
51
52 local x = 10;
53 local y = 10;
54
55 foreach(name in ["air", "earth", "wood", "fire", "water"])
56 {
57   if(! (name in key) {
58     key[name] <- FloatingImage("images/objects/keys/key_" + name + ".sprite");
59     key[name].set_anchor_point(ANCHOR_TOP_LEFT);
60     key[name].set_pos(x, y);
61     key[name].set_visible(true);
62   }
63   x += 30;
64 }
65
66 update_keys();