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 /*---------------------------------------------------------------------------*/
32 int goto_end_level(void)
34 switch (curr_lg()->mode)
39 return goto_state(&st_over);
41 return goto_state(&st_start);
46 /*---------------------------------------------------------------------------*/
49 #define START_PRACTICE -2
50 #define START_NORMAL -3
51 #define START_CHALLENGE -4
56 /*---------------------------------------------------------------------------*/
58 /* Create a level selector button based upon its existence and status. */
60 static void gui_level(int id, int i)
62 const GLfloat *fore, *back;
64 const struct set *s = curr_set();
65 const struct level *l;
69 if (!set_level_exists(s, i))
79 fore = l->is_bonus ? gui_grn : gui_wht;
80 back = l->is_completed ? fore : gui_yel;
83 fore = back = gui_gry;
85 jd = gui_label(id, l->repr, GUI_SML, GUI_ALL, back, fore);
90 static void start_over_level(i)
92 const struct level *l = get_level(i);
93 if (!l->is_locked || config_get_d(CONFIG_CHEAT))
95 gui_set_image(shot_id, l->shot);
97 set_most_coins(&l->score.most_coins, -1);
99 if (config_get_d(CONFIG_MODE) == MODE_PRACTICE)
101 set_best_times(&l->score.best_times, -1, 0);
103 gui_set_label(status_id,
104 _("Play this bonus level in practice mode"));
106 gui_set_label(status_id,
107 _("Play this level in practice mode"));
111 set_best_times(&l->score.unlock_goal, -1, 1);
113 gui_set_label(status_id,
114 _("Play this bonus level in normal mode"));
116 gui_set_label(status_id, _("Play this level in normal mode"));
118 if (config_get_d(CONFIG_CHEAT))
120 gui_set_label(status_id, l->file);
124 else if (l->is_bonus)
125 gui_set_label(status_id,
126 _("Play in challenge mode to unlock extra bonus levels"));
128 gui_set_label(status_id,
129 _("Finish previous levels to unlock this level"));
132 static void start_over(id)
145 case START_CHALLENGE:
146 gui_set_image(shot_id, curr_set()->shot);
147 set_most_coins(&curr_set()->coin_score, -1);
148 set_best_times(&curr_set()->time_score, -1, 0);
149 gui_set_label(status_id, _("Challenge all levels from the first one"));
153 gui_set_label(status_id, _("Collect coins and unlock next level"));
157 gui_set_label(status_id, _("Train yourself without time nor coin"));
165 /*---------------------------------------------------------------------------*/
167 static int start_action(int i)
169 int mode = config_get_d(CONFIG_MODE);
171 audio_play(AUD_MENU, 1.0f);
176 return goto_state(&st_set);
178 config_set_d(CONFIG_MODE, MODE_NORMAL);
179 return goto_state(&st_start);
181 config_set_d(CONFIG_MODE, MODE_PRACTICE);
182 return goto_state(&st_start);
185 if (i == START_CHALLENGE)
187 /* On cheat, start challenge mode where you want */
188 if (config_get_d(CONFIG_CHEAT))
190 config_set_d(CONFIG_MODE, MODE_CHALLENGE);
191 return goto_state(&st_start);
194 mode = MODE_CHALLENGE;
199 const struct level *l = get_level(i);
201 if (!l->is_locked || config_get_d(CONFIG_CHEAT))
204 return goto_state(&st_level);
210 static int start_enter(void)
212 int w = config_get_d(CONFIG_WIDTH);
213 int h = config_get_d(CONFIG_HEIGHT);
214 int m = config_get_d(CONFIG_MODE);
219 /* Deactivate cheat */
220 if (m == MODE_CHALLENGE && !config_get_d(CONFIG_CHEAT))
223 config_set_d(CONFIG_MODE, m);
226 if ((id = gui_vstack(0)))
228 if ((jd = gui_hstack(id)))
231 gui_label(jd, _(curr_set()->name), GUI_SML, GUI_ALL,
234 gui_start(jd, _("Back"), GUI_SML, START_BACK, 0);
238 if ((jd = gui_harray(id)))
240 shot_id = gui_image(jd, curr_set()->shot, 7 * w / 16, 7 * h / 16);
242 if ((kd = gui_varray(jd)))
244 if ((ld = gui_harray(kd)))
246 gui_state(ld, _("Practice"), GUI_SML, START_PRACTICE,
248 gui_state(ld, _("Normal"), GUI_SML, START_NORMAL,
251 for (i = 0; i < 5; i++)
252 if ((ld = gui_harray(kd)))
253 for (j = 4; j >= 0; j--)
254 gui_level(ld, i * 5 + j);
256 gui_state(kd, _("Challenge"), GUI_SML, START_CHALLENGE,
257 m == MODE_CHALLENGE);
262 if ((jd = gui_harray(id)))
264 gui_most_coins(jd, 0);
265 gui_best_times(jd, 0);
269 status_id = gui_label(id, _("Choose a level to play"), GUI_SML, GUI_ALL,
272 gui_layout(id, 0, 0);
274 set_most_coins(NULL, -1);
275 set_best_times(NULL, -1, m != MODE_PRACTICE);
278 audio_music_fade_to(0.5f, "bgm/inter.ogg");
283 static void start_point(int id, int x, int y, int dx, int dy)
285 start_over(gui_point(id, x, y));
288 static void start_stick(int id, int a, int v)
290 int x = (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a)) ? v : 0;
291 int y = (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a)) ? v : 0;
293 start_over(gui_stick(id, x, y));
296 static int start_keybd(int c, int d)
298 if (d && c == SDLK_c && config_get_d(CONFIG_CHEAT))
301 return goto_state(&st_start);
304 if (d && c == SDLK_F12)
308 /* Iterate over all levels, taking a screenshot of each. */
310 for (i = 0; i < MAXLVL; i++)
311 if (set_level_exists(curr_set(), i))
318 static int start_buttn(int b, int d)
322 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
323 return start_action(gui_token(gui_click()));
324 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
325 return start_action(START_BACK);
330 /*---------------------------------------------------------------------------*/
332 struct state st_start = {