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);
70 return goto_state(&st_done);
75 if (level_exit(NULL, 0))
76 return goto_state(&st_level);
78 return goto_state(&st_done);
89 config_set_s(CONFIG_PLAYER, player);
90 level_name(curr_level(), player, time_i, coin_i);
91 set_most_coins(curr_level(), 4);
92 set_best_times(curr_level(), 4);
99 player[l + 0] = gui_keyboard_char((char) i);
102 config_set_s(CONFIG_PLAYER, player);
103 level_name(curr_level(), player, time_i, coin_i);
104 set_most_coins(curr_level(), 4);
105 set_best_times(curr_level(), 4);
111 static int goal_enter(void)
113 const char *s1 = "New Record";
114 const char *s2 = "GOAL";
120 high = level_sort(&time_i, &coin_i);
122 if ((id = gui_vstack(0)))
127 gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
129 gid = gui_label(id, s2, GUI_LRG, GUI_ALL, gui_blu, gui_grn);
133 if ((jd = gui_harray(id)))
135 if ((kd = gui_harray(jd)))
137 balls_id = gui_count(kd, 10, GUI_MED, GUI_RGT);
138 gui_label(kd, "Balls", GUI_SML, GUI_LFT, gui_wht, gui_wht);
140 if ((kd = gui_harray(jd)))
142 score_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
143 gui_label(kd, "Score", GUI_SML, GUI_LFT, gui_wht, gui_wht);
145 if ((kd = gui_harray(jd)))
147 coins_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
148 gui_label(kd, "Coins", GUI_SML, GUI_LFT, gui_wht, gui_wht);
151 gui_set_count(balls_id, curr_balls());
152 gui_set_count(score_id, curr_score());
153 gui_set_count(coins_id, curr_coins());
158 if ((jd = gui_harray(id)))
160 gui_most_coins(jd, 4, coin_i);
161 gui_best_times(jd, 4, time_i);
166 if ((jd = gui_harray(id)))
168 gui_state(jd, "Save Replay", GUI_SML, GOAL_SAVE, 0);
169 gui_state(jd, "Retry Level", GUI_SML, GOAL_SAME, 0);
172 gui_start(jd, "Finish", GUI_SML, GOAL_NEXT, 0);
174 gui_start(jd, "Next Level", GUI_SML, GOAL_NEXT, 0);
177 if (high) gui_keyboard(id);
179 gui_layout(id, 0, 0);
180 gui_pulse(gid, 1.2f);
183 set_most_coins(curr_level(), 4);
184 set_best_times(curr_level(), 4);
186 audio_music_fade_out(2.0f);
187 audio_play(AUD_GOAL, 1.0f);
194 static void goal_leave(int id)
199 static void goal_paint(int id, float st)
205 static void goal_timer(int id, float dt)
207 static float DT = 0.0f;
209 float g[3] = { 0.0f, 9.8f, 0.0f };
213 if (time_state() < 1.f)
222 int coins = curr_coins();
223 int score = curr_score();
224 int balls = curr_balls();
226 if (gui_value(coins_id) != coins)
228 gui_set_count(coins_id, coins);
229 gui_pulse(coins_id, 1.1f);
231 if (gui_value(score_id) != score)
233 gui_set_count(score_id, score);
234 gui_pulse(score_id, 1.1f);
236 if (gui_value(balls_id) != balls)
238 gui_set_count(balls_id, balls);
239 gui_pulse(balls_id, 2.0f);
250 static void goal_point(int id, int x, int y, int dx, int dy)
252 gui_pulse(gui_point(id, x, y), 1.2f);
255 static void goal_stick(int id, int a, int v)
257 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
258 gui_pulse(gui_stick(id, v, 0), 1.2f);
259 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
260 gui_pulse(gui_stick(id, 0, v), 1.2f);
263 static int goal_click(int b, int d)
265 if (b <= 0 && d == 1)
266 return goal_action(gui_token(gui_click()));
270 static int goal_keybd(int c, int d)
272 if (d && c == SDLK_ESCAPE)
273 goto_state(&st_over);
277 static int goal_buttn(int b, int d)
281 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
282 return goal_click(0, 1);
283 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
284 return goto_state(&st_over);
289 /*---------------------------------------------------------------------------*/
291 struct state st_goal = {