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 /*---------------------------------------------------------------------------*/
47 static int be_back_soon;
49 static int goal_action(int i)
51 audio_play(AUD_MENU, 1.0f);
59 if (curr_lg()->mode == MODE_CHALLENGE)
60 return goto_state(&st_over);
62 return goto_state(&st_start);
66 return goto_save(&st_goal, &st_goal);
71 return goto_name(&st_goal, &st_goal);
74 return goto_state(&st_done);
78 level_play(curr_lg()->level, curr_lg()->mode);
79 return goto_state(&st_level);
82 level_play(curr_lg()->level, curr_lg()->mode);
83 return goto_state(&st_level);
89 static int goal_enter(void)
93 const struct level_game *lg = curr_lg();
94 const struct level *l = lg->level;
98 high = (lg->time_rank < 3) || (lg->goal_rank < 3) || (lg->coin_rank < 3);
105 level_update_player_name();
109 if ((id = gui_vstack(0)))
114 gid = gui_label(id, _("New Record"), GUI_MED, GUI_ALL, gui_grn, gui_grn);
116 gid = gui_label(id, _("GOAL"), GUI_LRG, GUI_ALL, gui_blu, gui_grn);
120 if (lg->mode == MODE_CHALLENGE)
122 int coins = lg->coins;
123 int score = lg->score - coins;
124 int balls = lg->balls - count_extra_balls(score, coins);
126 if ((jd = gui_hstack(id)))
128 if ((kd = gui_harray(jd)))
130 balls_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
131 gui_label(kd, _("Balls"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
133 if ((kd = gui_harray(jd)))
135 score_id = gui_count(kd, 1000, GUI_MED, GUI_RGT);
136 gui_label(kd, _("Score"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
138 if ((kd = gui_harray(jd)))
140 coins_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
141 gui_label(kd, _("Coins"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
144 gui_set_count(balls_id, balls);
145 gui_set_count(score_id, score);
146 gui_set_count(coins_id, coins);
151 balls_id = score_id = coins_id = 0;
156 if ((jd = gui_harray(id)))
158 gui_most_coins(jd, 1);
159 gui_best_times(jd, 1);
164 if ((jd = gui_harray(id)))
166 int next_id = 0, retry_id = 0;
169 gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
171 next_id = gui_maybe(jd, _("Next Level"), GOAL_NEXT,
172 lg->next_level != NULL);
175 gui_start(jd, _("Game Over"), GUI_SML, GOAL_OVER, 0);
178 retry_id = gui_maybe(jd, _("Retry Level"), GOAL_SAME,
179 lg->mode != MODE_CHALLENGE);
182 gui_maybe(jd, _("Save Replay"), GOAL_SAVE, demo_play_saved());
184 /* Default is next if the next level is newly unlocked. */
186 if (next_id && lg->unlock)
188 else if (lg->mode != MODE_CHALLENGE)
192 /* FIXME, I'm ugly. */
195 gui_state(id, _("Change Player Name"), GUI_SML, GOAL_NAME, 0);
197 gui_pulse(gid, 1.2f);
198 gui_layout(id, 0, 0);
202 set_most_coins(&l->score.most_coins, lg->coin_rank);
204 if (lg->mode == MODE_CHALLENGE || lg->mode == MODE_NORMAL)
205 set_best_times(&l->score.unlock_goal, lg->goal_rank, 1);
207 set_best_times(&l->score.best_times, lg->time_rank, 0);
209 audio_music_fade_out(2.0f);
216 static void goal_timer(int id, float dt)
218 static float DT = 0.0f;
220 float g[3] = { 0.0f, 9.8f, 0.0f };
224 if (time_state() < 1.f)
227 /* demo_play_step(dt); */
229 else if (DT > 0.05f && coins_id)
231 int coins = gui_value(coins_id);
235 int score = gui_value(score_id);
236 int balls = gui_value(balls_id);
238 gui_set_count(coins_id, coins - 1);
239 gui_pulse(coins_id, 1.1f);
241 gui_set_count(score_id, score + 1);
242 gui_pulse(score_id, 1.1f);
244 if ((score + 1) % 100 == 0)
246 gui_set_count(balls_id, balls + 1);
247 gui_pulse(balls_id, 2.0f);
248 audio_play(AUD_BALL, 1.0f);
258 static int goal_buttn(int b, int d)
262 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
263 return goal_action(gui_token(gui_click()));
264 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
265 return goal_action(GOAL_BACK);
271 void goal_leave(int id)
273 /* HACK: don't run animation if only "visiting" a state. */
274 st_goal.timer = be_back_soon ? shared_timer : goal_timer;
280 /*---------------------------------------------------------------------------*/
282 struct state st_goal = {