2 * Copyright (C) 2007 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.
32 #include "st_shared.h"
34 /*---------------------------------------------------------------------------*/
52 static int goal_action(int i)
54 audio_play(AUD_MENU, 1.0f);
63 return goto_state(&st_over);
69 return goto_save(&st_goal, &st_goal);
76 return goto_name(&st_goal, &st_goal, 0);
81 return goto_state(&st_done);
88 return goto_state(&st_goal);
92 return goto_state(&st_level);
97 return goto_state(&st_level);
104 static int goal_enter(void)
106 const char *s1 = _("New Record");
107 const char *s2 = _("GOAL");
111 const struct level *l = get_level(curr_level());
113 int high = progress_lvl_high();
121 if ((id = gui_vstack(0)))
126 gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
128 gid = gui_label(id, s2, GUI_LRG, GUI_ALL, gui_blu, gui_grn);
132 if (curr_mode() == MODE_CHALLENGE)
134 int coins, score, balls;
135 char msg[MAXSTR] = "";
138 /* Reverse-engineer initial score and balls. */
143 score = curr_score();
144 balls = curr_balls();
148 coins = curr_coins();
149 score = curr_score() - coins;
150 balls = curr_balls();
152 for (i = curr_score(); i > score; i--)
153 if (progress_reward_ball(i))
157 sprintf(msg, ngettext("%d new bonus level",
158 "%d new bonus levels",
159 curr_bonus()), curr_bonus());
161 if ((jd = gui_hstack(id)))
164 if ((kd = gui_harray(jd)))
166 balls_id = gui_count(kd, 100, GUI_MED, GUI_NE);
167 gui_label(kd, _("Balls"), GUI_SML, 0, gui_wht, gui_wht);
169 if ((kd = gui_harray(jd)))
171 score_id = gui_count(kd, 1000, GUI_MED, 0);
172 gui_label(kd, _("Score"), GUI_SML, 0, gui_wht, gui_wht);
174 if ((kd = gui_harray(jd)))
176 coins_id = gui_count(kd, 100, GUI_MED, 0);
177 gui_label(kd, _("Coins"), GUI_SML, GUI_NW, gui_wht, gui_wht);
180 gui_set_count(balls_id, balls);
181 gui_set_count(score_id, score);
182 gui_set_count(coins_id, coins);
186 gui_label(id, msg, GUI_SML, GUI_BOT, 0, 0);
192 balls_id = score_id = coins_id = 0;
195 if ((jd = gui_hstack(id)))
196 gui_score_board(jd, GUI_MOST_COINS |
198 GUI_UNLOCK_GOAL, 1, high);
202 if ((jd = gui_harray(id)))
205 gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
207 if (progress_next_avail())
208 gui_start(jd, _("Next Level"), GUI_SML, GOAL_NEXT, 0);
210 if (progress_same_avail())
211 gui_start(jd, _("Retry Level"), GUI_SML, GOAL_SAME, 0);
214 gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
218 gui_pulse(gid, 1.2f);
220 gui_layout(id, 0, 0);
224 set_score_board(&l->score.most_coins, progress_coin_rank(),
225 &l->score.best_times, progress_time_rank(),
226 &l->score.unlock_goal, progress_goal_rank());
228 audio_music_fade_out(2.0f);
238 static void goal_timer(int id, float dt)
240 static float t = 0.0f;
242 float g[3] = { 0.0f, 9.8f, 0.0f };
246 if (time_state() < 1.f)
251 else if (t > 0.05f && coins_id)
253 int coins = gui_value(coins_id);
257 int score = gui_value(score_id);
258 int balls = gui_value(balls_id);
260 gui_set_count(coins_id, coins - 1);
261 gui_pulse(coins_id, 1.1f);
263 gui_set_count(score_id, score + 1);
264 gui_pulse(score_id, 1.1f);
266 if (progress_reward_ball(score + 1))
268 gui_set_count(balls_id, balls + 1);
269 gui_pulse(balls_id, 2.0f);
270 audio_play(AUD_BALL, 1.0f);
279 static int goal_keybd(int c, int d)
283 if (config_tst_d(CONFIG_KEY_SCORE_NEXT, c))
284 return goal_action(gui_score_next(gui_score_get()));
285 if (config_tst_d(CONFIG_KEY_RESTART, c) && progress_same_avail())
286 return goal_action(GOAL_SAME);
292 static int goal_buttn(int b, int d)
296 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
297 return goal_action(gui_token(gui_click()));
298 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
299 return goal_action(GOAL_BACK);
304 static void goal_leave(int id)
306 /* HACK: don't run animation if only "visiting" a state. */
307 st_goal.timer = resume ? shared_timer : goal_timer;
312 /*---------------------------------------------------------------------------*/
314 struct state st_goal = {