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.
22 #include "st_shared.h"
30 /*---------------------------------------------------------------------------*/
33 #define START_PRACTICE -2
34 #define START_NORMAL -3
35 #define START_CHALLENGE -4
40 /*---------------------------------------------------------------------------*/
42 /* Create a level selector button based upon its existence and status. */
44 static void gui_level(int id, int i)
46 const GLfloat *fore, *back;
48 const struct set *s = curr_set();
49 const struct level *l;
53 if (!set_level_exists(s, i))
63 fore = l->is_bonus ? gui_grn : gui_wht;
64 back = l->is_completed ? fore : gui_yel;
67 fore = back = gui_gry;
69 jd = gui_label(id, l->repr, GUI_SML, GUI_ALL, back, fore);
74 static void start_over_level(int i)
76 const struct level *l = get_level(i);
77 if (!l->is_locked || config_cheat())
79 gui_set_image(shot_id, l->shot);
81 set_most_coins(&l->score.most_coins, -1);
83 if (curr_mode() == MODE_PRACTICE)
85 set_best_times(&l->score.best_times, -1, 0);
87 gui_set_label(status_id,
88 _("Play this bonus level in practice mode"));
90 gui_set_label(status_id,
91 _("Play this level in practice mode"));
95 set_best_times(&l->score.unlock_goal, -1, 1);
97 gui_set_label(status_id,
98 _("Play this bonus level in normal mode"));
100 gui_set_label(status_id, _("Play this level in normal mode"));
104 gui_set_label(status_id, l->file);
108 else if (l->is_bonus)
109 gui_set_label(status_id,
110 _("Play in challenge mode to unlock extra bonus levels"));
112 gui_set_label(status_id,
113 _("Finish previous levels to unlock this level"));
116 static void start_over(int id)
129 case START_CHALLENGE:
130 gui_set_image(shot_id, curr_set()->shot);
131 set_most_coins(&curr_set()->coin_score, -1);
132 set_best_times(&curr_set()->time_score, -1, 0);
133 gui_set_label(status_id, _("Challenge all levels from the first one"));
137 gui_set_label(status_id, _("Collect coins and unlock next level"));
141 gui_set_label(status_id, _("Train yourself without time nor coin"));
149 /*---------------------------------------------------------------------------*/
151 static int start_action(int i)
153 int mode = curr_mode();
155 audio_play(AUD_MENU, 1.0f);
160 return goto_state(&st_set);
162 mode_set(MODE_NORMAL);
163 return goto_state(&st_start);
165 mode_set(MODE_PRACTICE);
166 return goto_state(&st_start);
169 if (i == START_CHALLENGE)
171 /* On cheat, start challenge mode where you want */
174 mode_set(MODE_CHALLENGE);
175 return goto_state(&st_start);
178 mode = MODE_CHALLENGE;
183 const struct level *l = get_level(i);
185 if (!l->is_locked || config_cheat())
187 if (level_play(l, mode))
189 return goto_state(&st_level);
201 static int start_enter(void)
203 int w = config_get_d(CONFIG_WIDTH);
204 int h = config_get_d(CONFIG_HEIGHT);
210 /* Deactivate cheat */
212 if (m == MODE_CHALLENGE && !config_cheat())
214 mode_set(MODE_NORMAL);
218 if ((id = gui_vstack(0)))
220 if ((jd = gui_hstack(id)))
223 gui_label(jd, _(curr_set()->name), GUI_SML, GUI_ALL,
226 gui_start(jd, _("Back"), GUI_SML, START_BACK, 0);
230 if ((jd = gui_harray(id)))
232 shot_id = gui_image(jd, curr_set()->shot, 7 * w / 16, 7 * h / 16);
234 if ((kd = gui_varray(jd)))
236 if ((ld = gui_harray(kd)))
238 gui_state(ld, _("Practice"), GUI_SML, START_PRACTICE,
240 gui_state(ld, _("Normal"), GUI_SML, START_NORMAL,
243 for (i = 0; i < 5; i++)
244 if ((ld = gui_harray(kd)))
245 for (j = 4; j >= 0; j--)
246 gui_level(ld, i * 5 + j);
248 gui_state(kd, _("Challenge"), GUI_SML, START_CHALLENGE,
249 m == MODE_CHALLENGE);
254 if ((jd = gui_harray(id)))
256 gui_most_coins(jd, 0);
257 gui_best_times(jd, 0);
261 status_id = gui_label(id, _("Choose a level to play"), GUI_SML, GUI_ALL,
264 gui_layout(id, 0, 0);
266 set_most_coins(NULL, -1);
267 set_best_times(NULL, -1, m != MODE_PRACTICE);
270 audio_music_fade_to(0.5f, "bgm/inter.ogg");
275 static void start_point(int id, int x, int y, int dx, int dy)
277 start_over(gui_point(id, x, y));
280 static void start_stick(int id, int a, int v)
282 int x = (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a)) ? v : 0;
283 int y = (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a)) ? v : 0;
285 start_over(gui_stick(id, x, y));
288 static int start_keybd(int c, int d)
290 if (d && c == SDLK_c && config_cheat())
293 return goto_state(&st_start);
296 if (d && c == SDLK_F12)
300 /* Iterate over all levels, taking a screenshot of each. */
302 for (i = 0; i < MAXLVL; i++)
303 if (set_level_exists(curr_set(), i))
310 static int start_buttn(int b, int d)
314 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
315 return start_action(gui_token(gui_click()));
316 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
317 return start_action(START_BACK);
322 /*---------------------------------------------------------------------------*/
324 struct state st_start = {