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 /*---------------------------------------------------------------------------*/
47 static int goal_action(int i)
52 audio_play(AUD_MENU, 1.0f);
54 config_get_s(CONFIG_PLAYER, player, MAXNAM);
62 return goto_state(&st_save);
67 if (level_exit(NULL, 1))
68 return goto_state(&st_level);
69 else if (level_mode() == MODE_CHALLENGE)
70 return goto_state(&st_done);
72 return goto_state(&st_start);
77 if (level_exit(NULL, 0))
78 return goto_state(&st_level);
80 /* return goto_state(&st_done); */
81 /* This case can't occurs */
93 config_set_s(CONFIG_PLAYER, player);
94 level_name(curr_level(), player, time_i, coin_i);
95 set_most_coins(curr_level(), coin_i);
96 set_best_times(curr_level(), time_i);
103 player[l + 0] = gui_keyboard_char((char) i);
106 config_set_s(CONFIG_PLAYER, player);
107 level_name(curr_level(), player, time_i, coin_i);
108 set_most_coins(curr_level(), coin_i);
109 set_best_times(curr_level(), time_i);
115 static int goal_enter(void)
117 const char *s1 = _("New Record");
118 const char *s2 = _("GOAL");
124 high = level_sort(&time_i, &coin_i);
126 if ((id = gui_vstack(0)))
131 gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
133 gid = gui_label(id, s2, GUI_LRG, GUI_ALL, gui_blu, gui_grn);
137 if (level_mode() == MODE_CHALLENGE)
139 if ((jd = gui_hstack(id)))
141 if ((kd = gui_harray(jd)))
143 balls_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
144 gui_label(kd, _("Balls"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
146 if ((kd = gui_harray(jd)))
148 score_id = gui_count(kd, 1000, GUI_MED, GUI_RGT);
149 gui_label(kd, _("Score"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
151 if ((kd = gui_harray(jd)))
153 coins_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
154 gui_label(kd, _("Coins"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
157 gui_set_count(balls_id, curr_balls());
158 gui_set_count(score_id, curr_score());
159 gui_set_count(coins_id, curr_coins());
165 if ((jd = gui_harray(id)))
167 gui_most_coins(jd, 3, 1);
168 gui_best_times(jd, 3, 1);
173 if ((jd = gui_harray(id)))
175 gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
177 if (level_mode() != MODE_CHALLENGE)
178 gui_state(jd, _("Retry Level"), GUI_SML, GOAL_SAME, 0);
180 if (level_mode() == MODE_FREE) ;
181 else if (level_last())
182 gui_start(jd, _("Finish"), GUI_SML, GOAL_NEXT, 0);
184 gui_start(jd, _("Next Level"), GUI_SML, GOAL_NEXT, 0);
187 if (high) gui_keyboard(id);
189 gui_layout(id, 0, 0);
190 gui_pulse(gid, 1.2f);
193 set_most_coins(curr_level(), coin_i);
194 set_best_times(curr_level(), time_i);
196 audio_music_fade_out(2.0f);
203 static void goal_leave(int id)
208 static void goal_paint(int id, float st)
214 static void goal_timer(int id, float dt)
216 static float DT = 0.0f;
218 float g[3] = { 0.0f, 9.8f, 0.0f };
222 if (time_state() < 1.f)
231 int coins = curr_coins();
232 int score = curr_score();
233 int balls = curr_balls();
235 if (gui_value(coins_id) != coins)
237 gui_set_count(coins_id, coins);
238 gui_pulse(coins_id, 1.1f);
240 if (gui_value(score_id) != score)
242 gui_set_count(score_id, score);
243 gui_pulse(score_id, 1.1f);
245 if (gui_value(balls_id) != balls)
247 gui_set_count(balls_id, balls);
248 gui_pulse(balls_id, 2.0f);
259 static void goal_point(int id, int x, int y, int dx, int dy)
261 gui_pulse(gui_point(id, x, y), 1.2f);
264 static void goal_stick(int id, int a, int v)
266 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
267 gui_pulse(gui_stick(id, v, 0), 1.2f);
268 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
269 gui_pulse(gui_stick(id, 0, v), 1.2f);
272 static int goal_click(int b, int d)
274 if (b <= 0 && d == 1)
275 return goal_action(gui_token(gui_click()));
279 static int goal_keybd(int c, int d)
281 if (d && c == SDLK_ESCAPE)
282 goto_state(&st_over);
286 static int goal_buttn(int b, int d)
290 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
291 return goal_click(0, 1);
292 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
293 return goto_state(&st_over);
298 /*---------------------------------------------------------------------------*/
300 struct state st_goal = {