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 /*---------------------------------------------------------------------------*/
30 #define DEMO_BACK (MAXDEMO+1)
31 #define DEMO_NEXT (MAXDEMO+2)
32 #define DEMO_PREV (MAXDEMO+3)
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);
84 gui_clock(jd, demo_clock(i), GUI_SML, GUI_TOP);
85 gui_count(jd, demo_coins(i), GUI_SML, GUI_BOT);
91 static int demo_enter(void)
98 if ((id = gui_vstack(0)))
100 if ((jd = gui_hstack(id)))
102 if ((kd = gui_vstack(jd)))
105 if (first + DEMO_STEP < total)
106 gui_state(kd, _("Next"), GUI_SML, DEMO_NEXT, 0);
108 gui_state(kd, _("Back"), GUI_SML, DEMO_BACK, 0);
112 ld = gui_label(jd, _("Select Replay"), GUI_MED, GUI_ALL, 0,0);
115 if ((kd = gui_vstack(jd)))
119 gui_start(kd, _("Prev"), GUI_SML, DEMO_PREV, 0);
121 gui_start(kd, _("Back"), GUI_SML, DEMO_BACK, 0);
126 if ((jd = gui_varray(id)))
127 for (i = first; i < first + DEMO_STEP && i < total; i += DEMO_LINE)
128 if ((kd = gui_harray(jd)))
130 for (j = i + DEMO_LINE - 1; j >= i; j--)
137 gui_layout(id, 0, 0);
140 audio_music_fade_to(0.5f, "bgm/inter.ogg");
145 static void demo_leave(int id)
150 static void demo_paint(int id, float st)
157 static void demo_timer(int id, float dt)
163 static void demo_point(int id, int x, int y, int dx, int dy)
165 gui_pulse(gui_point(id, x, y), 1.2f);
168 static void demo_stick(int id, int a, int v)
170 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
171 gui_pulse(gui_stick(id, v, 0), 1.2f);
172 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
173 gui_pulse(gui_stick(id, 0, v), 1.2f);
176 static int demo_click(int b, int d)
178 if (b <= 0 && d == 1)
179 return demo_action(gui_token(gui_click()));
183 static int demo_keybd(int c, int d)
185 if (d && c == SDLK_ESCAPE)
186 goto_state(&st_title);
190 static int demo_buttn(int b, int d)
194 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
195 return demo_click(0, 1);
196 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
197 return goto_state(&st_title);
202 /*---------------------------------------------------------------------------*/
204 static int demo_play_enter(void)
208 if ((id = gui_label(0, _("Replay"), GUI_LRG, GUI_ALL, gui_blu, gui_grn)))
210 gui_layout(id, 0, 0);
222 static void demo_play_leave(int id)
227 static void demo_play_paint(int id, float st)
232 if (time_state() < 1.f)
236 static void demo_play_timer(int id, float dt)
246 /* Spin or skip depending on how fast the demo wants to run. */
248 while (replay_time < global_time)
249 if (demo_replay_step(&t))
256 goto_state(&st_demo_end);
261 static int demo_play_keybd(int c, int d)
263 if (d && c == SDLK_ESCAPE)
264 goto_state(&st_demo_end);
268 static int demo_play_buttn(int b, int d)
272 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
273 return goto_state(&st_demo_end);
278 /*---------------------------------------------------------------------------*/
283 static int demo_end_action(int i)
285 audio_play(AUD_MENU, 1.0f);
288 return goto_state(&st_demo_del);
293 return goto_state(&st_demo);
297 static int demo_end_enter(void)
301 if ((id = gui_vstack(0)))
303 kd = gui_label(id, _("Replay Ends"), GUI_MED, GUI_ALL, gui_gry, gui_red);
305 if ((jd = gui_harray(id)))
307 gui_state(jd, _("Delete"), GUI_SML, DEMO_DEL, 0);
308 gui_start(jd, _("Keep"), GUI_SML, DEMO_KEEP, 1);
312 gui_layout(id, 0, 0);
314 audio_music_fade_out(2.0f);
319 static void demo_end_leave(int id)
324 static void demo_end_paint(int id, float st)
330 static void demo_end_timer(int id, float dt)
336 static int demo_end_keybd(int c, int d)
338 return (d && c == SDLK_ESCAPE) ? demo_end_action(DEMO_KEEP) : 1;
341 static void demo_end_point(int id, int x, int y, int dx, int dy)
343 gui_pulse(gui_point(id, x, y), 1.2f);
346 static void demo_end_stick(int id, int a, int v)
348 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
349 gui_pulse(gui_stick(id, v, 0), 1.2f);
350 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
351 gui_pulse(gui_stick(id, 0, v), 1.2f);
354 static int demo_end_click(int b, int d)
357 return demo_end_action(gui_token(gui_click()));
361 static int demo_end_buttn(int b, int d)
365 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
366 return demo_end_action(gui_token(gui_click()));
367 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
368 return demo_end_action(DEMO_KEEP);
373 /*---------------------------------------------------------------------------*/
375 static int demo_del_action(int i)
377 audio_play(AUD_MENU, 1.0f);
379 demo_replay_stop(i == DEMO_DEL);
380 return goto_state(&st_demo);
383 static int demo_del_enter(void)
387 if ((id = gui_vstack(0)))
389 kd = gui_label(id, _("Delete Replay?"), GUI_MED, GUI_ALL, gui_red, gui_red);
391 if ((jd = gui_harray(id)))
393 gui_state(jd, _("Yes"), GUI_SML, DEMO_DEL, 0);
394 gui_start(jd, _("No"), GUI_SML, DEMO_KEEP, 1);
398 gui_layout(id, 0, 0);
400 audio_music_fade_out(2.0f);
405 static void demo_del_leave(int id)
410 static void demo_del_paint(int id, float st)
416 static void demo_del_timer(int id, float dt)
422 static int demo_del_keybd(int c, int d)
424 return (d && c == SDLK_ESCAPE) ? demo_del_action(DEMO_KEEP) : 1;
427 static void demo_del_point(int id, int x, int y, int dx, int dy)
429 gui_pulse(gui_point(id, x, y), 1.2f);
432 static void demo_del_stick(int id, int a, int v)
434 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
435 gui_pulse(gui_stick(id, v, 0), 1.2f);
436 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
437 gui_pulse(gui_stick(id, 0, v), 1.2f);
440 static int demo_del_click(int b, int d)
443 return demo_del_action(gui_token(gui_click()));
447 static int demo_del_buttn(int b, int d)
451 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
452 return demo_del_action(gui_token(gui_click()));
453 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
454 return demo_del_action(DEMO_KEEP);
459 /*---------------------------------------------------------------------------*/
461 struct state st_demo = {
474 struct state st_demo_play = {
487 struct state st_demo_end = {
500 struct state st_demo_del = {