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.
34 /*---------------------------------------------------------------------------*/
51 extern struct state st_goal_bis;
53 static int goal_action(int i)
55 audio_play(AUD_MENU, 1.0f);
60 if (level_mode() == MODE_CHALLENGE)
61 return goto_state(&st_over);
63 return goto_state(&st_start);
68 return goto_save(&st_goal_bis, &st_goal_bis);
73 return goto_name(&st_goal_bis, &st_goal_bis);
78 return goto_state(&st_done);
84 return goto_state(&st_level);
89 return goto_state(&st_level);
95 static int goal_init(int * gidp)
97 const char *s1 = _("New Record");
98 const char *s2 = _("GOAL");
102 if ((id = gui_vstack(0)))
107 gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
109 gid = gui_label(id, s2, GUI_LRG, GUI_ALL, gui_blu, gui_grn);
113 if (level_mode() == MODE_CHALLENGE)
115 if ((jd = gui_hstack(id)))
117 if ((kd = gui_harray(jd)))
119 balls_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
120 gui_label(kd, _("Balls"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
122 if ((kd = gui_harray(jd)))
124 score_id = gui_count(kd, 1000, GUI_MED, GUI_RGT);
125 gui_label(kd, _("Score"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
127 if ((kd = gui_harray(jd)))
129 coins_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
130 gui_label(kd, _("Coins"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
133 gui_set_count(balls_id, curr_balls());
134 gui_set_count(score_id, curr_score());
135 gui_set_count(coins_id, curr_coins());
141 if ((jd = gui_harray(id)))
143 gui_most_coins(jd, 3, 1);
144 gui_best_times(jd, 3, 1);
149 if ((jd = gui_harray(id)))
151 if (demo_play_saved())
152 gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
154 gui_label(jd, _("Save Replay"), GUI_SML, GUI_ALL, gui_blk, gui_blk);
156 if (level_mode() != MODE_CHALLENGE)
157 gui_start(jd, _("Retry Level"), GUI_SML, GOAL_SAME, 0);
159 if (level_mode() == MODE_CHALLENGE && level_last())
160 gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
161 else if (level_opened(curr_level()+1))
162 gui_state(jd, _("Next Level"), GUI_SML, GOAL_NEXT, 0);
164 gui_label(jd, _("Next Level"), GUI_SML, GUI_ALL, gui_blk, gui_blk);
168 gui_state(id, _("Change Player Name"), GUI_SML, GOAL_NAME, 0);
170 gui_layout(id, 0, 0);
171 if (gidp) *gidp = gid;
174 set_most_coins(curr_level(), coin_i);
175 set_best_times(curr_level(), time_i);
182 static int goal_enter(void)
189 high = level_sort(&time_i, &coin_i);
193 gui_pulse(gid, 1.2f);
194 audio_music_fade_out(2.0f);
198 static int goal_bis_enter(void)
201 config_get_s(CONFIG_PLAYER, player, MAXNAM);
202 level_name(curr_level(), player, time_i, coin_i);
203 return goal_init(NULL);
206 static void goal_leave(int id)
211 static void goal_paint(int id, float st)
217 static void goal_timer(int id, float dt)
219 static float DT = 0.0f;
221 float g[3] = { 0.0f, 9.8f, 0.0f };
225 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_bis_timer(int id, float dt)
265 static void goal_point(int id, int x, int y, int dx, int dy)
267 gui_pulse(gui_point(id, x, y), 1.2f);
270 static void goal_stick(int id, int a, int v)
272 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
273 gui_pulse(gui_stick(id, v, 0), 1.2f);
274 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
275 gui_pulse(gui_stick(id, 0, v), 1.2f);
278 static int goal_click(int b, int d)
280 if (b <= 0 && d == 1)
281 return goal_action(gui_token(gui_click()));
285 static int goal_buttn(int b, int d)
289 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
290 return goal_click(0, 1);
291 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
292 goal_action(GOAL_BACK);
297 /*---------------------------------------------------------------------------*/
299 struct state st_goal = {
312 struct state st_goal_bis = {