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 struct set *s = curr_set();
63 const struct level *l;
65 const GLfloat *fore, *back;
67 if (!set_level_exists(s, i))
77 fore = l->is_bonus ? gui_grn : gui_wht;
78 back = l->is_completed ? fore : gui_yel;
81 fore = back = gui_gry;
82 jd = gui_label(id, l->numbername, GUI_SML, GUI_ALL, back, fore);
86 static void start_over_level(i)
88 const struct level *l = get_level(i);
89 if (!l->is_locked || config_get_d(CONFIG_CHEAT))
91 gui_set_image(shot_id, l->shot);
93 set_most_coins(&l->coin_score, -1);
95 if (config_get_d(CONFIG_MODE) == MODE_PRACTICE)
97 set_best_times(&l->time_score, -1, 0);
99 gui_set_label(status_id,
100 _("Play this bonus level in practice mode"));
102 gui_set_label(status_id,
103 _("Play this level in practice mode"));
107 set_best_times(&l->goal_score, -1, 1);
109 gui_set_label(status_id,
110 _("Play this bonus level in normal mode"));
112 gui_set_label(status_id, _("Play this level in normal mode"));
114 if (config_get_d(CONFIG_CHEAT))
116 gui_set_label(status_id, l->file);
120 else if (l->is_bonus)
121 gui_set_label(status_id,
122 _("Play in challenge mode to unlock extra bonus levels"));
124 gui_set_label(status_id,
125 _("Finish previous levels to unlock this level"));
128 static void start_over(id)
141 case START_CHALLENGE:
142 gui_set_image(shot_id, curr_set()->shot);
143 set_most_coins(&curr_set()->coin_score, -1);
144 set_best_times(&curr_set()->time_score, -1, 0);
145 gui_set_label(status_id, _("Challenge all levels from the first one"));
149 gui_set_label(status_id, _("Collect coins and unlock next level"));
153 gui_set_label(status_id, _("Train yourself without time nor coin"));
161 /*---------------------------------------------------------------------------*/
163 static int start_action(int i)
165 int mode = config_get_d(CONFIG_MODE);
166 audio_play(AUD_MENU, 1.0f);
169 return goto_state(&st_set);
170 else if (i == START_NORMAL)
172 config_set_d(CONFIG_MODE, MODE_NORMAL);
173 return goto_state(&st_start);
175 else if (i == START_PRACTICE)
177 config_set_d(CONFIG_MODE, MODE_PRACTICE);
178 return goto_state(&st_start);
181 if (i == START_CHALLENGE)
183 /* On cheat, start challenge mode where you want */
184 if (config_get_d(CONFIG_CHEAT))
186 config_set_d(CONFIG_MODE, MODE_CHALLENGE);
187 return goto_state(&st_start);
190 mode = MODE_CHALLENGE;
195 const struct level *l = get_level(i);
196 if (!l->is_locked || config_get_d(CONFIG_CHEAT))
199 return goto_state(&st_level);
205 static int start_enter(void)
207 int w = config_get_d(CONFIG_WIDTH);
208 int h = config_get_d(CONFIG_HEIGHT);
209 int m = config_get_d(CONFIG_MODE);
214 /* Desactivate cheat */
215 if (m == MODE_CHALLENGE && !config_get_d(CONFIG_CHEAT))
218 config_set_d(CONFIG_MODE, m);
221 if ((id = gui_vstack(0)))
223 if ((jd = gui_hstack(id)))
226 gui_label(jd, _(curr_set()->name), GUI_SML, GUI_ALL,
229 gui_start(jd, _("Back"), GUI_SML, START_BACK, 0);
233 if ((jd = gui_harray(id)))
235 shot_id = gui_image(jd, curr_set()->shot, 7 * w / 16, 7 * h / 16);
237 if ((kd = gui_varray(jd)))
239 if ((ld = gui_harray(kd)))
241 gui_state(ld, _("Practice"), GUI_SML, START_PRACTICE,
243 gui_state(ld, _("Normal"), GUI_SML, START_NORMAL,
246 for (i = 0; i < 5; i++)
247 if ((ld = gui_harray(kd)))
248 for (j = 4; j >= 0; j--)
249 gui_level(ld, i * 5 + j);
251 gui_state(kd, _("Challenge"), GUI_SML, START_CHALLENGE ,
252 m == MODE_CHALLENGE);
257 if ((jd = gui_harray(id)))
259 gui_most_coins(jd, 0);
260 gui_best_times(jd, 0);
265 status_id = gui_label(id, _("Choose a level to play"), GUI_SML, GUI_ALL,
268 gui_layout(id, 0, 0);
270 set_most_coins(NULL, -1);
271 set_best_times(NULL, -1, m != MODE_PRACTICE);
277 static void start_point(int id, int x, int y, int dx, int dy)
279 start_over(gui_point(id, x, y));
282 static void start_stick(int id, int a, int v)
284 int x = (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a)) ? v : 0;
285 int y = (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a)) ? v : 0;
287 start_over(gui_stick(id, x, y));
290 static int start_keybd(int c, int d)
292 if (d && c == SDLK_c && config_get_d(CONFIG_CHEAT))
295 return goto_state(&st_start);
298 if (d && c == SDLK_F12)
302 /* Iterate over all levels, taking a screenshot of each. */
304 for (i = 0; i < MAXLVL; i++)
305 if (set_level_exists(curr_set(), i))
312 static int start_buttn(int b, int d)
316 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
317 return start_action(gui_token(gui_click()));
318 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
319 return start_action(START_BACK);
324 /*---------------------------------------------------------------------------*/
326 struct state st_start = {