Updated addon repository URL and improved debug output on download
[supertux.git] / data / levels / world1 / intro.nut
1 function initialize()
2 {
3   Tux.add_bonus("grow");
4   RADIO.set_action("quiet");
5   PENNY.set_action("stand-left");
6   NOLOK.set_visible(false);
7   LOGO.set_visible(false);
8   LOGO.enable_gravity(false);
9   SIGN.set_visible(false);
10 }
11
12 function logo_in()
13 {
14   local x = LOGO.get_pos_x();
15   local y = LOGO.get_pos_y();
16   local time = 1.5;
17   LOGO.set_pos(x,-120);
18   LOGO.set_visible(true);
19   LOGO.set_velocity(0,(120+y)/time);
20   LOGO.enable_gravity(false);
21   wait(time);
22   LOGO.set_velocity(0,0);
23   wait(3);
24   LOGO.set_visible(false);
25 }
26
27 function intro_text()
28 {
29   Text.set_text(translate ("Somewhere at the shores\nof Antarctica..."));
30   Text.fade_in(1);
31   wait(1);
32   Text.fade_out(1);
33 }
34
35 function rap_scene()
36 {
37   Tux.deactivate();
38   //begin conversation and Tux rap
39   play_sound("speech/tux_hello.ogg"); // 3.1 seconds
40   Text.set_centered(false);
41   Text.set_text(translate ("Tux: Hello Penny"));
42   Text.fade_in(1);
43   wait(2.5);
44   Text.fade_out(1);
45   wait(1);
46   play_sound("speech/penny_runt_01.ogg"); // 1.2 seconds
47   Text.set_text(translate ("Penny: Hey Tux"));
48   Text.fade_in(0.5);
49   wait(1);
50   Text.fade_out(0.5);
51   wait(0.5);
52   play_sound("speech/tux_murp_01.ogg"); // 1.5 seconds
53   Text.set_text(translate ("Tux: Check out my dance moves."));
54   Text.fade_in(0.5);
55   wait(1);
56   Text.fade_out(0.5);
57   wait(0.5);
58   RADIO.set_action("loud");
59   play_sound("speech/tux_rap.ogg"); // 24.6 seconds
60   local t = ::newthread(shake_bush_thread);
61   t.call(this); // Nolok's waiting...
62   // meanwhile... Tux dances!
63   // TODO: add some more dance moves besides jumps, ducks, & flips
64   // and fill in the parts where he just stands still
65   wait(6); // music intro - 6 seconds
66   Tux.do_duck();
67   Tux.set_dir(false);
68   wait(0.40625); // all times rounded to nearest 1/64 of a second
69   Tux.do_standup();
70   Tux.kick(); // 0.3 seconds
71   wait(0.40625);
72   Tux.set_dir(true);
73   wait(0.203125);
74   Tux.set_dir(false);
75   wait(0.203125);
76   Tux.set_dir(true);
77   wait(0.09375);
78   Tux.do_duck(); // t=7.3
79   wait(0.5);
80   Tux.set_dir(false);
81   wait(0.203125);
82   Tux.set_dir(true);
83   wait(0.203125);
84   Tux.set_dir(false);
85   wait(0.203125);
86   Tux.set_dir(true);
87   wait(0.203125);
88   Tux.set_dir(false);
89   wait(0.203125);
90   Tux.set_dir(true);
91   Tux.do_standup(); // t=8.8
92   wait(0.203125);
93   Tux.set_dir(false);
94   wait(0.203125);
95   Tux.kick();
96   wait(0.40625);
97   Tux.set_dir(true);
98   Tux.do_jump(-300);
99   wait(0.703125);
100   Tux.do_duck(); // t=10.7
101   wait(0.296875);
102   Tux.set_dir(false);
103   wait(0.59375);
104   Tux.set_dir(true);
105   wait(0.703125);
106   Tux.do_standup(); // t=12.3
107   Tux.kick();
108   wait(0.5);
109   Tux.do_duck();
110   wait(0.5);
111   Tux.do_backflip(); // t=13.3
112   wait(79.0/64);
113   Tux.walk(200);
114   wait(38.0/64);
115   Tux.walk(0);
116   wait(184.0/64);
117   Tux.set_dir(false); //t=18.0
118   wait(0.3)
119   Tux.kick();
120   wait(0.40625);
121   Tux.do_duck();
122   Tux.set_dir(true);
123   wait(0.296875);
124   Tux.set_dir(false); // t=19.0
125   wait(0.5);
126   Tux.do_standup();
127   Tux.do_jump(-800);
128   wait(1.5);
129   Tux.kick(); // t=21
130   wait(0.5);
131   Tux.do_duck();
132   wait(0.5);
133   Tux.do_jump(-400);
134   wait(1.0);
135   Tux.do_standup();
136   wait(0.796875);
137   Tux.set_dir(true); //t=23.8 - Tux sees Nolok!
138   Tux.do_jump(-520);
139   wait(151.0/64);
140   // we have to activate Tux to hurt him
141   Tux.activate();
142   Tux.kill(false);
143   Tux.deactivate();
144   wait(1.5);
145   // song is done
146   // darkness
147   NOLOK.set_visible(false);
148   NOLOK.set_solid(false);
149   PENNY.set_visible(false);
150   PENNY.set_solid(false);
151   RADIO.set_visible(false);
152   RADIO.set_solid(false);
153   SIGN.set_visible(true);
154   //wake up, Tux...
155   Effect.fade_in(3);
156   play_sound("speech/tux_upset.ogg"); // 11 seconds
157   Text.set_text(translate ("Tux: Oww... my head..."));
158   Text.fade_in(1);
159   wait(1.9);
160   Tux.activate();
161   Text.fade_out(0.3);
162   wait(0.5);
163   Text.set_text(translate ("Tux: Wait!")); // t=2.4
164   Text.fade_in(0.5);
165   wait(1);
166   Text.fade_out(0.5);
167   wait(0.5);
168   Text.set_text(translate ("Tux: Penny!")); // t=3.9
169   Text.fade_in(0.5);
170   wait(1);
171   Text.fade_out(0.5);
172   wait(0.5);
173   Text.set_text(translate ("Tux: Where are you, Penny?!")); // t=4.4
174   Text.fade_in(0.5);
175   wait(2);
176   Text.fade_out(0.5);
177   wait(0.5);
178   Text.set_text(translate ("Tux: Oh no...")); // t=6.9
179   Text.fade_in(0.5);
180   wait(1);
181   Text.fade_out(0.5);
182   wait(0.5);
183   Text.set_text(translate ("Tux: Don't worry, Penny, I'll rescue you!")); // t=8.4
184   Text.fade_in(0.5);
185   wait(2);
186   Text.fade_out(0.5);
187   wait(0.5);
188 }
189
190 function shake_bush()
191 {
192   //play_sound("sounds/rustle.wav");
193   local bushx = BUSH.get_pos_x();
194   local bushy = BUSH.get_pos_y();
195   for(local i = 0; i < 21; ++i) {
196     BUSH.set_pos(bushx + ( rand() % 6 ) - 3, bushy);
197     wait(0.046875);
198   }
199   wait(0.015625);
200 }
201
202 function shake_bush_thread(table)
203 {
204   table.wait(8);
205   table.shake_bush(); // each bush shake lasts 1 second
206   table.wait(5);
207   table.shake_bush();
208   table.wait(3);
209   table.shake_bush();
210   table.wait(2);
211   table.shake_bush();
212   table.shake_bush(); // total 23 seconds
213   //enter Nolok
214   table.NOLOK.set_velocity(-220, 600);
215   table.NOLOK.set_visible(true);
216   table.Effect.fade_out(1.3);
217 }
218
219 function end_level()
220 {
221   //end intro sequence
222   Effect.fade_out(2);
223   wait(2.1);
224   Level.finish(true);
225 }
226
227 state_idx <- 0;
228 states <- { init=0, start=1, logo_in=2, intro_text=3, rap_scene=4, end_level=5};
229 function trigger_state(state) {
230   local idx = states[state];
231   if(!idx || idx <= state_idx)
232     return;
233   state_idx = idx;
234   switch(state) {
235     case "start":
236       initialize();
237       break;
238     case "logo_in":
239       logo_in();
240       break;
241     case "intro_text":
242       intro_text();
243       break;
244     case "rap_scene":
245       rap_scene();
246       break;
247     case "end_level":
248       end_level();
249       break;
250   }
251 }