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 /*---------------------------------------------------------------------------*/
51 static int be_back_soon;
53 static int goal_action(int i)
55 audio_play(AUD_MENU, 1.0f);
64 return goto_state(&st_over);
70 return goto_save(&st_goal, &st_goal);
77 return goto_name(&st_goal, &st_goal, 0);
81 return goto_state(&st_done);
85 return goto_state(&st_level);
89 return goto_state(&st_level);
95 static int goal_enter(void)
97 const char *s1 = _("New Record");
98 const char *s2 = _("GOAL");
99 const char *s3 = _("Congratulations!");
103 struct level_game *lg = curr_lg();
104 const struct level *l = lg->level;
108 high = (lg->time_rank < 3) || (lg->goal_rank < 3) || (lg->coin_rank < 3);
115 level_update_player_name();
119 if ((id = gui_vstack(0)))
123 if (lg->mode == MODE_CHALLENGE && lg->bonus)
127 sprintf(buf, _("You have unlocked bonus level %s!"),
130 gid = gui_label(id, s3, GUI_MED, GUI_ALL, gui_grn, gui_red);
131 gid = gui_label(id, buf, GUI_SML, GUI_ALL, gui_blu, gui_grn);
134 lg->bonus_repr = NULL;
138 gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
140 gid = gui_label(id, s2, GUI_LRG, GUI_ALL, gui_blu, gui_grn);
144 if (lg->mode == MODE_CHALLENGE)
146 int coins = lg->coins;
147 int score = lg->score - coins;
148 int balls = lg->balls - count_extra_balls(score, coins);
150 if ((jd = gui_hstack(id)))
152 if ((kd = gui_harray(jd)))
154 balls_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
155 gui_label(kd, _("Balls"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
157 if ((kd = gui_harray(jd)))
159 score_id = gui_count(kd, 1000, GUI_MED, GUI_RGT);
160 gui_label(kd, _("Score"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
162 if ((kd = gui_harray(jd)))
164 coins_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
165 gui_label(kd, _("Coins"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
168 gui_set_count(balls_id, balls);
169 gui_set_count(score_id, score);
170 gui_set_count(coins_id, coins);
175 balls_id = score_id = coins_id = 0;
180 if ((jd = gui_harray(id)))
182 gui_most_coins(jd, 1);
183 gui_best_times(jd, 1);
188 if ((jd = gui_harray(id)))
190 int next_id = 0, retry_id = 0;
193 gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
195 next_id = gui_maybe(jd, _("Next Level"), GOAL_NEXT,
196 lg->next_level != NULL);
199 gui_start(jd, _("Game Over"), GUI_SML, GOAL_OVER, 0);
202 retry_id = gui_maybe(jd, _("Retry Level"), GOAL_SAME,
203 lg->mode != MODE_CHALLENGE);
206 gui_maybe(jd, _("Save Replay"), GOAL_SAVE, demo_saved());
208 /* Default is next if the next level is newly unlocked. */
210 if (next_id && lg->unlock)
212 else if (lg->mode != MODE_CHALLENGE)
216 /* FIXME, I'm ugly. */
219 gui_state(id, _("Change Player Name"), GUI_SML, GOAL_NAME, 0);
221 gui_pulse(gid, 1.2f);
222 gui_layout(id, 0, 0);
226 set_most_coins(&l->score.most_coins, lg->coin_rank);
228 if (lg->mode == MODE_CHALLENGE || lg->mode == MODE_NORMAL)
229 set_best_times(&l->score.unlock_goal, lg->goal_rank, 1);
231 set_best_times(&l->score.best_times, lg->time_rank, 0);
233 audio_music_fade_out(2.0f);
240 static void goal_timer(int id, float dt)
242 static float t = 0.0f;
244 float g[3] = { 0.0f, 9.8f, 0.0f };
248 if (time_state() < 1.f)
253 else if (t > 0.05f && coins_id)
255 int coins = gui_value(coins_id);
259 int score = gui_value(score_id);
260 int balls = gui_value(balls_id);
262 gui_set_count(coins_id, coins - 1);
263 gui_pulse(coins_id, 1.1f);
265 gui_set_count(score_id, score + 1);
266 gui_pulse(score_id, 1.1f);
268 if ((score + 1) % 100 == 0)
270 gui_set_count(balls_id, balls + 1);
271 gui_pulse(balls_id, 2.0f);
272 audio_play(AUD_BALL, 1.0f);
281 static int goal_buttn(int b, int d)
285 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
286 return goal_action(gui_token(gui_click()));
287 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
288 return goal_action(GOAL_BACK);
293 static void goal_leave(int id)
295 /* HACK: don't run animation if only "visiting" a state. */
296 st_goal.timer = be_back_soon ? shared_timer : goal_timer;
301 /*---------------------------------------------------------------------------*/
303 struct state st_goal = {