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);
80 return goto_state(&st_done);
87 return goto_state(&st_goal);
91 return goto_state(&st_level);
96 return goto_state(&st_level);
103 static int goal_enter(void)
105 const char *s1 = _("New Record");
106 const char *s2 = _("GOAL");
110 const struct level *l = get_level(curr_level());
112 int high = progress_lvl_high();
120 if ((id = gui_vstack(0)))
125 gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
127 gid = gui_label(id, s2, GUI_LRG, GUI_ALL, gui_blu, gui_grn);
131 if (curr_mode() == MODE_CHALLENGE)
133 int coins, score, balls;
134 char msg[MAXSTR] = "";
137 /* Reverse-engineer initial score and balls. */
142 score = curr_score();
143 balls = curr_balls();
147 coins = curr_coins();
148 score = curr_score() - coins;
149 balls = curr_balls();
151 for (i = curr_score(); i > score; i--)
152 if (progress_reward_ball(i))
156 sprintf(msg, ngettext("%d new bonus level",
157 "%d new bonus levels",
158 curr_bonus()), curr_bonus());
160 if ((jd = gui_hstack(id)))
163 if ((kd = gui_harray(jd)))
165 balls_id = gui_count(kd, 100, GUI_MED, GUI_NE);
166 gui_label(kd, _("Balls"), GUI_SML, 0, gui_wht, gui_wht);
168 if ((kd = gui_harray(jd)))
170 score_id = gui_count(kd, 1000, GUI_MED, 0);
171 gui_label(kd, _("Score"), GUI_SML, 0, gui_wht, gui_wht);
173 if ((kd = gui_harray(jd)))
175 coins_id = gui_count(kd, 100, GUI_MED, 0);
176 gui_label(kd, _("Coins"), GUI_SML, GUI_NW, gui_wht, gui_wht);
179 gui_set_count(balls_id, balls);
180 gui_set_count(score_id, score);
181 gui_set_count(coins_id, coins);
185 gui_label(id, msg, GUI_SML, GUI_BOT, 0, 0);
191 balls_id = score_id = coins_id = 0;
194 if ((jd = gui_hstack(id)))
195 gui_score_board(jd, 1, high);
199 if ((jd = gui_harray(id)))
202 gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
204 if (progress_next_avail())
205 gui_start(jd, _("Next Level"), GUI_SML, GOAL_NEXT, 0);
207 if (progress_same_avail())
208 gui_start(jd, _("Retry Level"), GUI_SML, GOAL_SAME, 0);
211 gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
215 gui_pulse(gid, 1.2f);
217 gui_layout(id, 0, 0);
221 set_score_board(&l->score.most_coins, progress_coin_rank(),
222 &l->score.best_times, progress_time_rank(),
223 &l->score.unlock_goal, progress_goal_rank());
225 audio_music_fade_out(2.0f);
235 static void goal_timer(int id, float dt)
237 static float t = 0.0f;
239 float g[3] = { 0.0f, 9.8f, 0.0f };
243 if (time_state() < 1.f)
248 else if (t > 0.05f && coins_id)
250 int coins = gui_value(coins_id);
254 int score = gui_value(score_id);
255 int balls = gui_value(balls_id);
257 gui_set_count(coins_id, coins - 1);
258 gui_pulse(coins_id, 1.1f);
260 gui_set_count(score_id, score + 1);
261 gui_pulse(score_id, 1.1f);
263 if (progress_reward_ball(score + 1))
265 gui_set_count(balls_id, balls + 1);
266 gui_pulse(balls_id, 2.0f);
267 audio_play(AUD_BALL, 1.0f);
276 static int goal_keybd(int c, int d)
278 if (d && config_tst_d(CONFIG_KEY_SCORE_NEXT, c))
279 return goal_action(gui_score_next(gui_score_get()));
284 static int goal_buttn(int b, int d)
288 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
289 return goal_action(gui_token(gui_click()));
290 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
291 return goal_action(GOAL_BACK);
296 static void goal_leave(int id)
298 /* HACK: don't run animation if only "visiting" a state. */
299 st_goal.timer = resume ? shared_timer : goal_timer;
304 /*---------------------------------------------------------------------------*/
306 struct state st_goal = {