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.
33 /*---------------------------------------------------------------------------*/
49 extern struct state st_goal_bis;
51 static int goal_action(int i)
56 audio_play(AUD_MENU, 1.0f);
58 config_get_s(CONFIG_PLAYER, player, MAXNAM);
64 if (level_mode() == MODE_CHALLENGE)
65 return goto_state(&st_over);
67 return goto_state(&st_start);
72 return goto_save(&st_goal_bis);
83 return goto_state(&st_level);
88 return goto_state(&st_level);
99 config_set_s(CONFIG_PLAYER, player);
100 level_name(curr_level(), player, time_i, coin_i);
101 set_most_coins(curr_level(), coin_i);
102 set_best_times(curr_level(), time_i);
109 player[l + 0] = gui_keyboard_char((char) i);
112 config_set_s(CONFIG_PLAYER, player);
113 level_name(curr_level(), player, time_i, coin_i);
114 set_most_coins(curr_level(), coin_i);
115 set_best_times(curr_level(), time_i);
121 static int goal_init(int * gidp, int save)
123 const char *s1 = _("New Record");
124 const char *s2 = _("GOAL");
128 if ((id = gui_vstack(0)))
133 gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
135 gid = gui_label(id, s2, GUI_LRG, GUI_ALL, gui_blu, gui_grn);
139 if (level_mode() == MODE_CHALLENGE)
141 if ((jd = gui_hstack(id)))
143 if ((kd = gui_harray(jd)))
145 balls_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
146 gui_label(kd, _("Balls"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
148 if ((kd = gui_harray(jd)))
150 score_id = gui_count(kd, 1000, GUI_MED, GUI_RGT);
151 gui_label(kd, _("Score"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
153 if ((kd = gui_harray(jd)))
155 coins_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
156 gui_label(kd, _("Coins"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
159 gui_set_count(balls_id, curr_balls());
160 gui_set_count(score_id, curr_score());
161 gui_set_count(coins_id, curr_coins());
167 if ((jd = gui_harray(id)))
169 gui_most_coins(jd, 3, 1);
170 gui_best_times(jd, 3, 1);
175 if ((jd = gui_harray(id)))
178 gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
180 gui_label(jd, _("Save Replay"), GUI_SML, GUI_ALL, gui_blk, gui_blk);
182 if (level_mode() != MODE_CHALLENGE)
183 gui_state(jd, _("Retry Level"), GUI_SML, GOAL_SAME, 0);
185 if (level_mode() == MODE_CHALLENGE && level_last())
186 gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
187 else if (level_opened(curr_level()+1))
188 gui_start(jd, _("Next Level"), GUI_SML, GOAL_NEXT, 0);
190 gui_label(jd, _("Next Level"), GUI_SML, GUI_ALL, gui_blk, gui_blk);
193 if (high) gui_keyboard(id);
195 gui_layout(id, 0, 0);
196 if (gidp) *gidp = gid;
199 set_most_coins(curr_level(), coin_i);
200 set_best_times(curr_level(), time_i);
207 static int goal_enter(void)
214 high = level_sort(&time_i, &coin_i);
216 r = goal_init(&gid, 1);
218 gui_pulse(gid, 1.2f);
219 audio_music_fade_out(2.0f);
223 static int goal_bis_enter(void)
225 return goal_init(NULL, 0);
228 static void goal_leave(int id)
233 static void goal_paint(int id, float st)
239 static void goal_timer(int id, float dt)
241 static float DT = 0.0f;
243 float g[3] = { 0.0f, 9.8f, 0.0f };
247 if (time_state() < 1.f)
256 int coins = curr_coins();
257 int score = curr_score();
258 int balls = curr_balls();
260 if (gui_value(coins_id) != coins)
262 gui_set_count(coins_id, coins);
263 gui_pulse(coins_id, 1.1f);
265 if (gui_value(score_id) != score)
267 gui_set_count(score_id, score);
268 gui_pulse(score_id, 1.1f);
270 if (gui_value(balls_id) != balls)
272 gui_set_count(balls_id, balls);
273 gui_pulse(balls_id, 2.0f);
284 static void goal_bis_timer(int id, float dt)
290 static void goal_point(int id, int x, int y, int dx, int dy)
292 gui_pulse(gui_point(id, x, y), 1.2f);
295 static void goal_stick(int id, int a, int v)
297 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
298 gui_pulse(gui_stick(id, v, 0), 1.2f);
299 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
300 gui_pulse(gui_stick(id, 0, v), 1.2f);
303 static int goal_click(int b, int d)
305 if (b <= 0 && d == 1)
306 return goal_action(gui_token(gui_click()));
310 static int goal_keybd(int c, int d)
312 if (d && c == SDLK_ESCAPE)
313 goal_action(GOAL_BACK);
317 static int goal_buttn(int b, int d)
321 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
322 return goal_click(0, 1);
323 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
324 goal_action(GOAL_BACK);
329 /*---------------------------------------------------------------------------*/
331 struct state st_goal = {
344 struct state st_goal_bis = {