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.
30 #include "st_shared.h"
32 /*---------------------------------------------------------------------------*/
49 static int be_back_soon;
51 static int goal_action(int i)
53 audio_play(AUD_MENU, 1.0f);
62 return goto_state(&st_over);
68 return goto_save(&st_goal, &st_goal);
75 return goto_name(&st_goal, &st_goal);
79 return goto_state(&st_done);
83 return goto_state(&st_level);
87 return goto_state(&st_level);
93 static int goal_enter(void)
95 const char *s1 = _("New Record");
96 const char *s2 = _("GOAL");
100 const struct level_game *lg = curr_lg();
101 const struct level *l = lg->level;
105 high = (lg->time_rank < 3) || (lg->goal_rank < 3) || (lg->coin_rank < 3);
112 level_update_player_name();
116 if ((id = gui_vstack(0)))
121 gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
123 gid = gui_label(id, s2, GUI_LRG, GUI_ALL, gui_blu, gui_grn);
127 if (lg->mode == MODE_CHALLENGE)
129 int coins = lg->coins;
130 int score = lg->score - coins;
131 int balls = lg->balls - count_extra_balls(score, coins);
133 if ((jd = gui_hstack(id)))
135 if ((kd = gui_harray(jd)))
137 balls_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
138 gui_label(kd, _("Balls"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
140 if ((kd = gui_harray(jd)))
142 score_id = gui_count(kd, 1000, GUI_MED, GUI_RGT);
143 gui_label(kd, _("Score"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
145 if ((kd = gui_harray(jd)))
147 coins_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
148 gui_label(kd, _("Coins"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
151 gui_set_count(balls_id, balls);
152 gui_set_count(score_id, score);
153 gui_set_count(coins_id, coins);
158 balls_id = score_id = coins_id = 0;
163 if ((jd = gui_harray(id)))
165 gui_most_coins(jd, 1);
166 gui_best_times(jd, 1);
171 if ((jd = gui_harray(id)))
173 int next_id = 0, retry_id = 0;
176 gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
178 next_id = gui_maybe(jd, _("Next Level"), GOAL_NEXT,
179 lg->next_level != NULL);
182 gui_start(jd, _("Game Over"), GUI_SML, GOAL_OVER, 0);
185 retry_id = gui_maybe(jd, _("Retry Level"), GOAL_SAME,
186 lg->mode != MODE_CHALLENGE);
189 gui_maybe(jd, _("Save Replay"), GOAL_SAVE, demo_saved());
191 /* Default is next if the next level is newly unlocked. */
193 if (next_id && lg->unlock)
195 else if (lg->mode != MODE_CHALLENGE)
199 /* FIXME, I'm ugly. */
202 gui_state(id, _("Change Player Name"), GUI_SML, GOAL_NAME, 0);
204 gui_pulse(gid, 1.2f);
205 gui_layout(id, 0, 0);
209 set_most_coins(&l->score.most_coins, lg->coin_rank);
211 if (lg->mode == MODE_CHALLENGE || lg->mode == MODE_NORMAL)
212 set_best_times(&l->score.unlock_goal, lg->goal_rank, 1);
214 set_best_times(&l->score.best_times, lg->time_rank, 0);
216 audio_music_fade_out(2.0f);
223 static void goal_timer(int id, float dt)
225 static float DT = 0.0f;
227 float g[3] = { 0.0f, 9.8f, 0.0f };
231 if (time_state() < 1.f)
236 else if (DT > 0.05f && coins_id)
238 int coins = gui_value(coins_id);
242 int score = gui_value(score_id);
243 int balls = gui_value(balls_id);
245 gui_set_count(coins_id, coins - 1);
246 gui_pulse(coins_id, 1.1f);
248 gui_set_count(score_id, score + 1);
249 gui_pulse(score_id, 1.1f);
251 if ((score + 1) % 100 == 0)
253 gui_set_count(balls_id, balls + 1);
254 gui_pulse(balls_id, 2.0f);
255 audio_play(AUD_BALL, 1.0f);
264 static int goal_buttn(int b, int d)
268 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
269 return goal_action(gui_token(gui_click()));
270 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
271 return goal_action(GOAL_BACK);
276 static void goal_leave(int id)
278 /* HACK: don't run animation if only "visiting" a state. */
279 st_goal.timer = be_back_soon ? shared_timer : goal_timer;
284 /*---------------------------------------------------------------------------*/
286 struct state st_goal = {