2 * Copyright (C) 2003 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.
25 #include "st_shared.h"
27 #include "st_play_end.h"
35 /*---------------------------------------------------------------------------*/
37 #define PLAY_END_NEXT 2
38 #define PLAY_END_SAME 3
39 #define PLAY_END_SAVE 4
40 #define PLAY_END_BACK 5
41 #define PLAY_END_DONE 6
42 #define PLAY_END_NAME 7
43 #define PLAY_END_OVER 8
50 extern struct state st_play_end_bis;
52 static int play_end_action(int i)
54 audio_play(AUD_MENU, 1.0f);
60 return goto_end_level();
63 return goto_save(&st_play_end_bis, &st_play_end_bis);
66 return goto_name(&st_play_end_bis, &st_play_end_bis);
69 return goto_state(&st_done);
73 level_play(curr_lg()->level, curr_lg()->mode);
74 return goto_state(&st_level);
77 level_play(curr_lg()->level, curr_lg()->mode);
78 return goto_state(&st_level);
84 static void play_end_over(int id)
89 switch (gui_token(id))
95 gui_set_label(status_id, _("Save a replay file"));
98 case PLAY_END_SAVE | GUI_NULL_MASK:
99 gui_set_label(status_id, _("Replay file already saved"));
103 gui_set_label(status_id, _("Change the player's name"));
107 gui_set_label(status_id, _("You complete the set"));
111 gui_set_label(status_id, _("Play the next level"));
114 case PLAY_END_NEXT | GUI_NULL_MASK:
115 if (curr_lg()->mode == MODE_PRACTICE)
116 gui_set_label(status_id,
117 _("Cannot unlock in practice mode"));
119 gui_set_label(status_id,
120 _("Finish this level to unlock the next one"));
124 gui_set_label(status_id, _("Replay this level"));
127 case PLAY_END_SAME | GUI_NULL_MASK:
128 gui_set_label(status_id, _("You cannot replay in challenge mode"));
132 gui_set_label(status_id, "");
137 static int play_end_init(int *gidp)
139 const struct level_game *lg = curr_lg();
141 int state = lg->state;
142 const struct level *l = lg->level;
147 high = (lg->time_rank < 3) || (lg->goal_rank < 3) || (lg->coin_rank < 3);
149 if ((id = gui_vstack(0)))
153 if (state == GAME_FALL)
154 gid = gui_label(id, _("Fall-out!"), GUI_MED, GUI_ALL,
156 else if (state == GAME_TIME)
157 gid = gui_label(id, _("Time's Up!"), GUI_MED, GUI_ALL,
160 gid = gui_label(id, _("New Record"), GUI_MED, GUI_ALL,
163 gid = gui_label(id, _("GOAL"), GUI_LRG, GUI_ALL,
168 if (mode == MODE_CHALLENGE &&
169 (lg->state == GAME_GOAL || l->is_bonus))
171 int coins = lg->coins;
172 int score = lg->score - coins;
173 int balls = lg->balls - count_extra_balls(score, coins);
174 if ((jd = gui_hstack(id)))
176 if ((kd = gui_harray(jd)))
178 balls_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
179 gui_label(kd, _("Balls"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
181 if ((kd = gui_harray(jd)))
183 score_id = gui_count(kd, 1000, GUI_MED, GUI_RGT);
184 gui_label(kd, _("Score"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
186 if ((kd = gui_harray(jd)))
188 coins_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
189 gui_label(kd, _("Coins"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
192 gui_set_count(balls_id, balls);
193 gui_set_count(score_id, score);
194 gui_set_count(coins_id, coins);
199 balls_id = score_id = coins_id = 0;
202 if (state == GAME_GOAL)
205 if ((jd = gui_harray(id)))
207 gui_most_coins(jd, 1);
208 gui_best_times(jd, 1);
214 if ((jd = gui_harray(id)))
216 int nlid = 0, rlid = 0;
220 gui_start(jd, _("Finish"), GUI_SML, PLAY_END_DONE, 0);
222 nlid = gui_maybe(jd, _("Next Level"), PLAY_END_NEXT,
223 lg->next_level != NULL);
226 gui_start(jd, _("Game Over"), GUI_SML, PLAY_END_OVER, 0);
229 b = mode != MODE_CHALLENGE || ((state == GAME_FALL || state == GAME_TIME) && !lg->dead && !l->is_bonus);
230 rlid = gui_maybe(jd, _("Retry Level"), PLAY_END_SAME, b);
233 gui_maybe(jd, _("Save Replay"), PLAY_END_SAVE, demo_play_saved());
235 /* default is next if the next level is newly unlocked */
236 if (nlid != 0 && lg->unlock)
243 gui_state(id, _("Change Player Name"), GUI_SML, PLAY_END_NAME, 0);
246 status_id = gui_label(id, "Neverball", GUI_SML, GUI_ALL, 0, 0);
248 gui_layout(id, 0, 0);
249 if (gidp) *gidp = gid;
252 if (state == GAME_GOAL)
254 set_most_coins(&l->score.most_coins, lg->coin_rank);
255 if (mode == MODE_CHALLENGE || mode == MODE_NORMAL)
256 set_best_times(&l->score.unlock_goal, lg->goal_rank, 1);
258 set_best_times(&l->score.best_times, lg->time_rank, 0);
266 static int play_end_enter(void)
271 r = play_end_init(&gid);
273 gui_pulse(gid, 1.2f);
274 audio_music_fade_out(2.0f);
278 static int play_end_bis_enter(void)
280 level_update_player_name();
281 return play_end_init(NULL);
284 static void play_end_timer(int id, float dt)
286 static float DT = 0.0f;
288 float gg[3] = { 0.0f, 9.8f, 0.0f };
289 float gf[3] = { 0.0f, -9.8f, 0.0f };
290 int state = curr_lg()->state;
294 if (state != GAME_TIME)
296 if (time_state() < 2.f)
297 game_step(state == GAME_GOAL ? gg : gf, dt, 0);
300 if (time_state() > 1.f && DT > 0.05f && coins_id != 0)
302 int coins = gui_value(coins_id);
305 int score = gui_value(score_id);
306 int balls = gui_value(balls_id);
308 gui_set_count(coins_id, coins - 1);
309 gui_pulse(coins_id, 1.1f);
311 gui_set_count(score_id, score + 1);
312 gui_pulse(score_id, 1.1f);
314 if ((score + 1) % 100 == 0)
316 gui_set_count(balls_id, balls + 1);
317 gui_pulse(balls_id, 2.0f);
318 audio_play(AUD_BALL, 1.0f);
329 void play_end_stick(int id, int a, int v)
331 play_end_over(shared_stick_basic(id, a, v));
334 void play_end_point(int id, int x, int y, int dx, int dy)
336 play_end_over(shared_point_basic(id, x, y));
339 static int play_end_buttn(int b, int d)
343 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
344 return play_end_action(gui_token(gui_click()));
345 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
346 return play_end_action(PLAY_END_BACK);
351 /*---------------------------------------------------------------------------*/
353 struct state st_play_end = {
366 struct state st_play_end_bis = {