2 * Copyright (C) 2003 Robert Kooima
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
28 /*---------------------------------------------------------------------------*/
40 static float replay_time;
41 static float global_time;
43 /*---------------------------------------------------------------------------*/
45 static int demo_action(int i)
47 audio_play(AUD_MENU, 1.0f);
52 return goto_state(&st_title);
56 return goto_state(&st_demo);
61 return goto_state(&st_demo);
65 if (level_replay(demo_name(i)))
66 return goto_state(&st_demo_play);
71 static void demo_replay(int id, int i)
73 int w = config_get_d(CONFIG_WIDTH);
74 int h = config_get_d(CONFIG_HEIGHT);
77 if ((jd = gui_vstack(id)))
81 gui_image(jd, demo_shot(i), w / 6, h / 6);
82 gui_state(jd, demo_name(i), GUI_SML, i, 0);
95 static void demo_status(int i)
101 case MODE_CHALLENGE: ms = _("Challenge"); break;
102 case MODE_NORMAL: ms = _("Normal"); break;
103 case MODE_PRACTICE: ms = _("Practice"); break;
106 gui_set_label(name_id, demo_name(i));
107 gui_set_label(date_id, demo_str_date(i));
108 gui_set_label(player_id, demo_player(i));
109 gui_set_label(mode_id, ms);
110 gui_set_count(coin_id, demo_coins(i));
111 gui_set_clock(time_id, demo_clock(i));
114 static int demo_enter(void)
121 if ((id = gui_vstack(0)))
125 gui_label(id, _("No Replay"), GUI_MED, GUI_ALL, 0,0);
127 gui_multi(id, _("You can save replay of you games.\\Currently, there is no replay saved."), GUI_SML, GUI_ALL, gui_wht, gui_wht);
129 gui_start(id, _("Back"), GUI_SML, DEMO_BACK, 0);
133 if ((jd = gui_hstack(id)))
136 ld = gui_label(jd, _("Select Replay"), GUI_SML, GUI_ALL, 0,0);
141 if (first + DEMO_STEP < total)
142 gui_state(jd, _("Next"), GUI_SML, DEMO_NEXT, 0);
145 gui_state(jd, _("Prev"), GUI_SML, DEMO_PREV, 0);
147 gui_start(jd, _("Back"), GUI_SML, DEMO_BACK, 0);
149 if ((jd = gui_varray(id)))
150 for (i = first; i < first + DEMO_STEP ; i += DEMO_LINE)
151 if ((kd = gui_harray(jd)))
153 for (j = i + DEMO_LINE - 1; j >= i; j--)
160 if ((jd = gui_hstack(id)))
162 if((kd = gui_vstack(jd)))
164 if ((ld = gui_harray(kd)))
166 coin_id = gui_count(ld, 100, GUI_SML, GUI_RGT);
167 gui_label(ld, _("Coins"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
168 time_id = gui_clock(ld, 35000, GUI_SML, GUI_RGT);
169 gui_label(ld, _("Time"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
170 name_id = gui_label(ld, demo_name(0), GUI_SML, GUI_RGT, 0, 0);
172 if ((ld = gui_harray(kd)))
174 mode_id = gui_label(ld, "..............", GUI_SML, GUI_RGT, 0, 0);
175 gui_label(ld, _("Mode"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
176 player_id = gui_label(ld, demo_player(0), GUI_SML, GUI_RGT, 0, 0);
178 date_id = gui_label(kd, demo_str_date(0), GUI_SML, GUI_RGT, 0, 0);
180 if((kd = gui_vstack(jd)))
182 gui_label(kd, _("Name"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
183 gui_label(kd, _("Player"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
184 gui_label(kd, _("Date"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
190 gui_layout(id, 0, 0);
193 audio_music_fade_to(0.5f, "bgm/inter.ogg");
198 static void demo_leave(int id)
203 static void demo_paint(int id, float st)
210 static void demo_timer(int id, float dt)
216 static void demo_point(int id, int x, int y, int dx, int dy)
218 int jd = gui_point(id, x, y);
219 int i = gui_token(jd);
225 static void demo_stick(int id, int a, int v)
227 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
228 gui_pulse(gui_stick(id, v, 0), 1.2f);
229 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
230 gui_pulse(gui_stick(id, 0, v), 1.2f);
233 static int demo_click(int b, int d)
235 if (b <= 0 && d == 1)
236 return demo_action(gui_token(gui_click()));
240 static int demo_buttn(int b, int d)
244 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
245 return demo_click(0, 1);
246 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
247 return demo_action(DEMO_BACK);
252 /*---------------------------------------------------------------------------*/
254 static int demo_play_enter(void)
258 if ((id = gui_label(0, _("Replay"), GUI_LRG, GUI_ALL, gui_blu, gui_grn)))
260 gui_layout(id, 0, 0);
272 static void demo_play_leave(int id)
277 static void demo_play_paint(int id, float st)
282 if (time_state() < 1.f)
286 static void demo_play_timer(int id, float dt)
297 /* Spin or skip depending on how fast the demo wants to run. */
299 while (replay_time < global_time)
300 if (demo_replay_step(&t))
306 goto_state(&st_demo_end);
311 static int demo_play_buttn(int b, int d)
315 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
316 return goto_state(&st_demo_end);
321 /*---------------------------------------------------------------------------*/
326 static int demo_end_action(int i)
328 audio_play(AUD_MENU, 1.0f);
331 return goto_state(&st_demo_del);
336 return goto_state(&st_demo);
340 static int demo_end_enter(void)
344 if ((id = gui_vstack(0)))
346 kd = gui_label(id, _("Replay Ends"), GUI_MED, GUI_ALL, gui_gry, gui_red);
348 if ((jd = gui_harray(id)))
350 gui_state(jd, _("Delete"), GUI_SML, DEMO_DEL, 0);
351 gui_start(jd, _("Keep"), GUI_SML, DEMO_KEEP, 1);
355 gui_layout(id, 0, 0);
357 audio_music_fade_out(2.0f);
362 static void demo_end_leave(int id)
367 static void demo_end_paint(int id, float st)
373 static void demo_end_timer(int id, float dt)
375 float g[3] = { 0.0f, -9.8f, 0.0f };
377 if (time_state() < 2.f)
384 static void demo_end_point(int id, int x, int y, int dx, int dy)
386 gui_pulse(gui_point(id, x, y), 1.2f);
389 static void demo_end_stick(int id, int a, int v)
391 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
392 gui_pulse(gui_stick(id, v, 0), 1.2f);
393 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
394 gui_pulse(gui_stick(id, 0, v), 1.2f);
397 static int demo_end_click(int b, int d)
400 return demo_end_action(gui_token(gui_click()));
404 static int demo_end_buttn(int b, int d)
408 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
409 return demo_end_action(gui_token(gui_click()));
410 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
411 return demo_end_action(DEMO_KEEP);
416 /*---------------------------------------------------------------------------*/
418 static int demo_del_action(int i)
420 audio_play(AUD_MENU, 1.0f);
422 demo_replay_stop(i == DEMO_DEL);
423 return goto_state(&st_demo);
426 static int demo_del_enter(void)
430 if ((id = gui_vstack(0)))
432 kd = gui_label(id, _("Delete Replay?"), GUI_MED, GUI_ALL, gui_red, gui_red);
434 if ((jd = gui_harray(id)))
436 gui_state(jd, _("Yes"), GUI_SML, DEMO_DEL, 0);
437 gui_start(jd, _("No"), GUI_SML, DEMO_KEEP, 1);
441 gui_layout(id, 0, 0);
443 audio_music_fade_out(2.0f);
448 static void demo_del_leave(int id)
453 static void demo_del_paint(int id, float st)
459 static void demo_del_timer(int id, float dt)
465 static void demo_del_point(int id, int x, int y, int dx, int dy)
467 gui_pulse(gui_point(id, x, y), 1.2f);
470 static void demo_del_stick(int id, int a, int v)
472 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
473 gui_pulse(gui_stick(id, v, 0), 1.2f);
474 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
475 gui_pulse(gui_stick(id, 0, v), 1.2f);
478 static int demo_del_click(int b, int d)
481 return demo_del_action(gui_token(gui_click()));
485 static int demo_del_buttn(int b, int d)
489 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
490 return demo_del_action(gui_token(gui_click()));
491 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
492 return demo_del_action(DEMO_KEEP);
497 /*---------------------------------------------------------------------------*/
499 struct state st_demo = {
512 struct state st_demo_play = {
525 struct state st_demo_end = {
538 struct state st_demo_del = {