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.
23 #include "st_shared.h"
32 /*---------------------------------------------------------------------------*/
34 static float real_time = 0.0f;
37 static int play_id = 0;
45 static int title_action(int i)
47 static const char keyphrase[] = "CHEAT";
48 static char queue[sizeof (keyphrase)] = "";
50 size_t queue_len = strlen(queue);
54 audio_play(AUD_MENU, 1.0f);
59 config_get_s(CONFIG_PLAYER, player, MAXNAM);
61 if (strlen(player) == 0)
62 return goto_name(&st_set, &st_title, 0);
64 return goto_state(&st_set);
68 case TITLE_HELP: return goto_state(&st_help); break;
69 case TITLE_DEMO: return goto_state(&st_demo); break;
70 case TITLE_CONF: return goto_state(&st_conf); break;
71 case TITLE_EXIT: return 0; break;
75 /* Let the queue fill up. */
77 if (queue_len < sizeof (queue) - 1)
79 queue[queue_len] = (char) i;
80 queue[queue_len + 1] = '\0';
83 /* Advance the queue before adding the new element. */
89 for (k = 1; k < queue_len; k++)
90 queue[k - 1] = queue[k];
92 queue[queue_len - 1] = (char) i;
95 if (strcmp(queue, keyphrase) == 0)
98 gui_set_label(play_id, sgettext("menu^Cheat"));
99 gui_pulse(play_id, 1.2f);
101 else if (config_cheat())
104 gui_set_label(play_id, sgettext("menu^Play"));
105 gui_pulse(play_id, 1.2f);
113 static struct level title_level;
115 static int title_enter(void)
119 /* Build the title GUI. */
121 if ((id = gui_vstack(0)))
123 gui_label(id, "Neverball", GUI_LRG, GUI_ALL, 0, 0);
127 if ((jd = gui_harray(id)))
131 if ((kd = gui_varray(jd)))
134 play_id = gui_start(kd, sgettext("menu^Cheat"),
135 GUI_MED, TITLE_PLAY, 1);
137 play_id = gui_start(kd, sgettext("menu^Play"),
138 GUI_MED, TITLE_PLAY, 1);
140 gui_state(kd, sgettext("menu^Replay"), GUI_MED, TITLE_DEMO, 0);
141 gui_state(kd, sgettext("menu^Help"), GUI_MED, TITLE_HELP, 0);
142 gui_state(kd, sgettext("menu^Options"), GUI_MED, TITLE_CONF, 0);
143 gui_state(kd, sgettext("menu^Exit"), GUI_MED, TITLE_EXIT, 0);
148 gui_layout(id, 0, 0);
151 /* Start the title screen music. */
153 audio_music_fade_to(0.5f, "bgm/title.ogg");
155 /* Initialize the title level for display. */
156 level_load("map-medium/title.sol", &title_level);
157 game_init(&title_level, 0, 0);
162 SDL_EnableUNICODE(1);
167 static void title_leave(int id)
169 SDL_EnableUNICODE(0);
174 static void title_timer(int id, float dt)
176 static const char *demo = NULL;
182 case 0: /* Mode 0: Pan across title level. */
184 if (real_time <= 20.0f)
185 game_set_fly(fcosf(V_PI * real_time / 20.0f));
194 case 1: /* Mode 1: Fade out. Load demo level. */
196 if (real_time > 1.0f)
198 if ((demo = demo_pick()))
200 demo_replay_init(demo, NULL);
214 case 2: /* Mode 2: Run demo. */
216 if (!demo_replay_step(dt))
225 case 3: /* Mode 3: Fade out. Load title level. */
227 if (real_time > 1.0f)
229 game_init(&title_level, 0, 0);
240 static int title_keybd(int c, int d)
242 if (d && (c & 0xFF80) == 0 && c > ' ')
243 return title_action(c);
247 static int title_buttn(int b, int d)
251 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
252 return title_action(gui_token(gui_click()));
253 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
259 /*---------------------------------------------------------------------------*/
261 struct state st_title = {