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 int title_enter(void)
117 /* Build the title GUI. */
119 if ((id = gui_vstack(0)))
121 gui_label(id, "Neverball", GUI_LRG, GUI_ALL, 0, 0);
125 if ((jd = gui_harray(id)))
129 if ((kd = gui_varray(jd)))
132 play_id = gui_start(kd, sgettext("menu^Cheat"),
133 GUI_MED, TITLE_PLAY, 1);
135 play_id = gui_start(kd, sgettext("menu^Play"),
136 GUI_MED, TITLE_PLAY, 1);
138 gui_state(kd, sgettext("menu^Replay"), GUI_MED, TITLE_DEMO, 0);
139 gui_state(kd, sgettext("menu^Help"), GUI_MED, TITLE_HELP, 0);
140 gui_state(kd, sgettext("menu^Options"), GUI_MED, TITLE_CONF, 0);
141 gui_state(kd, sgettext("menu^Exit"), GUI_MED, TITLE_EXIT, 0);
146 gui_layout(id, 0, 0);
149 /* Start the title screen music. */
151 audio_music_fade_to(0.5f, "bgm/title.ogg");
153 /* Initialize the title level for display. */
155 game_init("map-medium/title.sol", 0, 1);
160 SDL_EnableUNICODE(1);
165 static void title_leave(int id)
167 SDL_EnableUNICODE(0);
172 static void title_timer(int id, float dt)
174 static const char *demo = NULL;
180 case 0: /* Mode 0: Pan across title level. */
182 if (real_time <= 20.0f)
183 game_set_fly(fcosf(V_PI * real_time / 20.0f));
192 case 1: /* Mode 1: Fade out. Load demo level. */
194 if (real_time > 1.0f)
196 if ((demo = demo_pick()))
198 demo_replay_init(demo, NULL, NULL, NULL, NULL, NULL);
212 case 2: /* Mode 2: Run demo. */
214 if (!demo_replay_step(dt))
223 case 3: /* Mode 3: Fade out. Load title level. */
225 if (real_time > 1.0f)
227 game_init("map-medium/title.sol", 0, 1);
239 static int title_keybd(int c, int d)
241 if (d && (c & 0xFF80) == 0 && c > ' ')
242 return title_action(c);
246 static int title_buttn(int b, int d)
250 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
251 return title_action(gui_token(gui_click()));
252 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
258 /*---------------------------------------------------------------------------*/
260 struct state st_title = {