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.
21 #include "st_shared.h"
30 /*---------------------------------------------------------------------------*/
32 static float real_time = 0.0f;
33 static float demo_time = 0.0f;
36 static int play_id = 0;
44 static int title_action(int i)
46 static const char keyphrase[] = "CHEAT";
47 static char queue[sizeof (keyphrase)] = "";
49 size_t queue_len = strlen(queue);
53 audio_play(AUD_MENU, 1.0f);
58 config_get_s(CONFIG_PLAYER, player, MAXNAM);
60 if (strlen(player) == 0)
61 return goto_name(&st_set, &st_title);
63 return goto_state(&st_set);
67 case TITLE_HELP: return goto_state(&st_help); break;
68 case TITLE_DEMO: return goto_state(&st_demo); break;
69 case TITLE_CONF: return goto_state(&st_conf); break;
70 case TITLE_EXIT: return 0; break;
74 /* Let the queue fill up. */
76 if (queue_len < sizeof (queue) - 1)
78 queue[queue_len] = (char) i;
79 queue[queue_len + 1] = '\0';
82 /* Advance the queue before adding the new element. */
88 for (k = 1; k < queue_len; k++)
89 queue[k - 1] = queue[k];
91 queue[queue_len - 1] = (char) i;
94 if (strcmp(queue, keyphrase) == 0)
97 gui_set_label(play_id, sgettext("menu^Cheat"));
98 gui_pulse(play_id, 1.2f);
100 else if (config_cheat())
103 gui_set_label(play_id, sgettext("menu^Play"));
104 gui_pulse(play_id, 1.2f);
112 static struct level title_level;
114 static int title_enter(void)
118 /* Build the title GUI. */
120 if ((id = gui_vstack(0)))
122 gui_label(id, "Neverball", GUI_LRG, GUI_ALL, 0, 0);
126 if ((jd = gui_harray(id)))
130 if ((kd = gui_varray(jd)))
133 play_id = gui_start(kd, sgettext("menu^Cheat"),
134 GUI_MED, TITLE_PLAY, 1);
136 play_id = gui_start(kd, sgettext("menu^Play"),
137 GUI_MED, TITLE_PLAY, 1);
139 gui_state(kd, sgettext("menu^Replay"), GUI_MED, TITLE_DEMO, 0);
140 gui_state(kd, sgettext("menu^Help"), GUI_MED, TITLE_HELP, 0);
141 gui_state(kd, sgettext("menu^Options"), GUI_MED, TITLE_CONF, 0);
142 gui_state(kd, sgettext("menu^Exit"), GUI_MED, TITLE_EXIT, 0);
147 gui_layout(id, 0, 0);
150 /* Start the title screen music. */
152 audio_music_fade_to(0.5f, "bgm/title.ogg");
154 /* Initialize the title level for display. */
155 level_load("map-medium/title.sol", &title_level);
156 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;
183 case 0: /* Mode 0: Pan across title level. */
185 if (real_time <= 20.0f)
186 game_set_fly(fcosf(V_PI * real_time / 20.0f));
195 case 1: /* Mode 1: Fade out. Load demo level. */
197 if (real_time > 1.0f)
199 if ((demo = demo_pick()))
201 demo_replay_init(demo, NULL);
215 case 2: /* Mode 2: Run demo. */
217 while (demo_time < real_time)
218 if (demo_replay_step(&t))
229 case 3: /* Mode 3: Fade out. Load title level. */
231 if (real_time > 1.0f)
233 game_init(&title_level, 0, 0);
244 static int title_keybd(int c, int d)
246 if (d && (c & 0xFF80) == 0 && c > ' ')
247 return title_action(c);
251 static int title_buttn(int b, int d)
255 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
256 return title_action(gui_token(gui_click()));
257 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
263 /*---------------------------------------------------------------------------*/
265 struct state st_title = {