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;
47 const struct level *l;
51 if (!set_level_exists(curr_set(), i))
61 fore = l->is_bonus ? gui_grn : gui_wht;
62 back = l->is_completed ? fore : gui_yel;
65 fore = back = gui_gry;
67 jd = gui_label(id, l->repr, GUI_SML, GUI_ALL, back, fore);
72 static void start_over_level(int i)
74 const struct level *l = get_level(i);
75 if (!l->is_locked || config_cheat())
77 gui_set_image(shot_id, l->shot);
79 set_most_coins(&l->score.most_coins, -1);
81 if (curr_mode() == MODE_PRACTICE)
83 set_best_times(&l->score.best_times, -1, 0);
85 gui_set_label(status_id,
86 _("Play this bonus level in practice mode"));
88 gui_set_label(status_id,
89 _("Play this level in practice mode"));
93 set_best_times(&l->score.unlock_goal, -1, 1);
95 gui_set_label(status_id,
96 _("Play this bonus level in normal mode"));
98 gui_set_label(status_id, _("Play this level in normal mode"));
102 gui_set_label(status_id, l->file);
106 else if (l->is_bonus)
107 gui_set_label(status_id,
108 _("Play in challenge mode to unlock extra bonus levels"));
110 gui_set_label(status_id,
111 _("Finish previous levels to unlock this level"));
114 static void start_over(int id)
127 case START_CHALLENGE:
128 gui_set_image(shot_id, set_shot(curr_set()));
129 set_most_coins(set_coin_score(curr_set()), -1);
130 set_best_times(set_time_score(curr_set()), -1, 0);
131 gui_set_label(status_id, _("Challenge all levels from the first one"));
135 gui_set_label(status_id, _("Collect coins and unlock next level"));
139 gui_set_label(status_id, _("Train yourself without time nor coin"));
147 /*---------------------------------------------------------------------------*/
149 static int start_action(int i)
151 int mode = curr_mode();
153 audio_play(AUD_MENU, 1.0f);
158 return goto_state(&st_set);
160 mode_set(MODE_NORMAL);
161 return goto_state(&st_start);
163 mode_set(MODE_PRACTICE);
164 return goto_state(&st_start);
167 if (i == START_CHALLENGE)
169 /* On cheat, start challenge mode where you want */
172 mode_set(MODE_CHALLENGE);
173 return goto_state(&st_start);
176 mode = MODE_CHALLENGE;
181 const struct level *l = get_level(i);
183 if (!l->is_locked || config_cheat())
185 if (level_play(l, mode))
187 return goto_state(&st_level);
199 static int start_enter(void)
201 int w = config_get_d(CONFIG_WIDTH);
202 int h = config_get_d(CONFIG_HEIGHT);
208 /* Deactivate cheat */
210 if (m == MODE_CHALLENGE && !config_cheat())
212 mode_set(MODE_NORMAL);
216 if ((id = gui_vstack(0)))
218 if ((jd = gui_hstack(id)))
221 gui_label(jd, set_name(curr_set()), GUI_SML, GUI_ALL,
224 gui_start(jd, _("Back"), GUI_SML, START_BACK, 0);
228 if ((jd = gui_harray(id)))
230 shot_id = gui_image(jd, set_shot(curr_set()), 7 * w / 16, 7 * h / 16);
232 if ((kd = gui_varray(jd)))
234 if ((ld = gui_harray(kd)))
236 gui_state(ld, _("Practice"), GUI_SML, START_PRACTICE,
238 gui_state(ld, _("Normal"), GUI_SML, START_NORMAL,
241 for (i = 0; i < 5; i++)
242 if ((ld = gui_harray(kd)))
243 for (j = 4; j >= 0; j--)
244 gui_level(ld, i * 5 + j);
246 gui_state(kd, _("Challenge"), GUI_SML, START_CHALLENGE,
247 m == MODE_CHALLENGE);
252 if ((jd = gui_harray(id)))
254 gui_most_coins(jd, 0);
255 gui_best_times(jd, 0);
259 status_id = gui_label(id, _("Choose a level to play"), GUI_SML, GUI_ALL,
262 gui_layout(id, 0, 0);
264 set_most_coins(NULL, -1);
265 set_best_times(NULL, -1, m != MODE_PRACTICE);
268 audio_music_fade_to(0.5f, "bgm/inter.ogg");
273 static void start_point(int id, int x, int y, int dx, int dy)
275 start_over(gui_point(id, x, y));
278 static void start_stick(int id, int a, int v)
280 int x = (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a)) ? v : 0;
281 int y = (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a)) ? v : 0;
283 start_over(gui_stick(id, x, y));
286 static int start_keybd(int c, int d)
288 if (d && c == SDLK_c && config_cheat())
291 return goto_state(&st_start);
294 if (d && c == SDLK_F12)
298 /* Iterate over all levels, taking a screenshot of each. */
300 for (i = 0; i < MAXLVL; i++)
301 if (set_level_exists(curr_set(), i))
308 static int start_buttn(int b, int d)
312 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
313 return start_action(gui_token(gui_click()));
314 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
315 return start_action(START_BACK);
320 /*---------------------------------------------------------------------------*/
322 struct state st_start = {