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, 1, high);
200 if ((jd = gui_harray(id)))
203 gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
205 if (progress_next_avail())
206 gui_start(jd, _("Next Level"), GUI_SML, GOAL_NEXT, 0);
208 if (progress_same_avail())
209 gui_start(jd, _("Retry Level"), GUI_SML, GOAL_SAME, 0);
212 gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
216 gui_pulse(gid, 1.2f);
218 gui_layout(id, 0, 0);
222 set_score_board(&l->score.most_coins, progress_coin_rank(),
223 &l->score.best_times, progress_time_rank(),
224 &l->score.unlock_goal, progress_goal_rank());
226 audio_music_fade_out(2.0f);
236 static void goal_timer(int id, float dt)
238 static float t = 0.0f;
240 float g[3] = { 0.0f, 9.8f, 0.0f };
244 if (time_state() < 1.f)
249 else if (t > 0.05f && coins_id)
251 int coins = gui_value(coins_id);
255 int score = gui_value(score_id);
256 int balls = gui_value(balls_id);
258 gui_set_count(coins_id, coins - 1);
259 gui_pulse(coins_id, 1.1f);
261 gui_set_count(score_id, score + 1);
262 gui_pulse(score_id, 1.1f);
264 if (progress_reward_ball(score + 1))
266 gui_set_count(balls_id, balls + 1);
267 gui_pulse(balls_id, 2.0f);
268 audio_play(AUD_BALL, 1.0f);
277 static int goal_keybd(int c, int d)
279 if (d && config_tst_d(CONFIG_KEY_SCORE_NEXT, c))
280 return goal_action(gui_score_next(gui_score_get()));
285 static int goal_buttn(int b, int d)
289 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
290 return goal_action(gui_token(gui_click()));
291 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
292 return goal_action(GOAL_BACK);
297 static void goal_leave(int id)
299 /* HACK: don't run animation if only "visiting" a state. */
300 st_goal.timer = resume ? shared_timer : goal_timer;
305 /*---------------------------------------------------------------------------*/
307 struct state st_goal = {