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"
35 /*---------------------------------------------------------------------------*/
48 extern struct state st_goal_bis;
50 static int goal_action(int i)
52 audio_play(AUD_MENU, 1.0f);
57 return goto_end_level();
60 return goto_save(&st_goal_bis, &st_goal_bis);
63 return goto_name(&st_goal_bis, &st_goal_bis);
66 return goto_state(&st_done);
70 return goto_state(&st_level);
73 return goto_state(&st_level);
79 static int goal_init(int * gidp)
81 const struct level_game *lg = curr_lg();
83 int state = lg->state;
84 const struct level *l = lg->level;
89 high = (lg->time_rank < 3) || (lg->goal_rank < 3) || (lg->coin_rank < 3);
91 if ((id = gui_vstack(0)))
95 if (state == GAME_SPEC)
96 gid = gui_label(id, _("Special Goal"), GUI_MED, GUI_ALL, gui_yel, gui_yel);
97 else if (state == GAME_FALL)
98 gid = gui_label(id, _("Fall-out!"), GUI_MED, GUI_ALL, gui_yel, gui_yel);
99 else if (state == GAME_TIME)
100 gid = gui_label(id, _("Time's Up!"), GUI_MED, GUI_ALL, gui_yel, gui_yel);
102 gid = gui_label(id, _("New Record"), GUI_MED, GUI_ALL, gui_grn, gui_grn);
104 gid = gui_label(id, _("GOAL"), GUI_LRG, GUI_ALL, gui_blu, gui_grn);
108 if (mode == MODE_CHALLENGE &&
109 (lg->state == GAME_GOAL || lg->state == GAME_SPEC || l->is_bonus))
111 int coins = lg->coins;
112 int score = lg->score - coins;
113 int balls = lg->balls - count_extra_balls(score, coins);
114 if ((jd = gui_hstack(id)))
116 if ((kd = gui_harray(jd)))
118 balls_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
119 gui_label(kd, _("Balls"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
121 if ((kd = gui_harray(jd)))
123 score_id = gui_count(kd, 1000, GUI_MED, GUI_RGT);
124 gui_label(kd, _("Score"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
126 if ((kd = gui_harray(jd)))
128 coins_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
129 gui_label(kd, _("Coins"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
132 gui_set_count(balls_id, balls);
133 gui_set_count(score_id, score);
134 gui_set_count(coins_id, coins);
139 balls_id = score_id = coins_id = 0;
142 if (state == GAME_GOAL)
145 if ((jd = gui_harray(id)))
147 gui_most_coins(jd, 1);
148 gui_best_times(jd, 1);
154 if ((jd = gui_harray(id)))
159 gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
161 nlid = gui_maybe(jd, _("Next Level"), GOAL_NEXT, lg->next_level != NULL);
163 b = mode != MODE_CHALLENGE ||
164 ((state == GAME_FALL || state == GAME_TIME) && !lg->dead && !l->is_bonus);
165 gui_maybe(jd, _("Retry Level"), GOAL_SAME, b);
167 gui_maybe(jd, _("Save Replay"), GOAL_SAVE, demo_play_saved());
169 /* default is next if the next level is newly unkocked */
170 if (nlid != 0 && lg->unlock)
175 gui_state(id, _("Change Player Name"), GUI_SML, GOAL_NAME, 0);
177 gui_layout(id, 0, 0);
178 if (gidp) *gidp = gid;
181 if (state == GAME_GOAL)
183 set_most_coins(&l->coin_score, lg->coin_rank);
184 if (mode == MODE_CHALLENGE || mode == MODE_NORMAL)
185 set_best_times(&l->goal_score, lg->goal_rank, 1);
187 set_best_times(&l->time_score, lg->time_rank, 0);
195 static int goal_enter(void)
202 gui_pulse(gid, 1.2f);
203 audio_music_fade_out(2.0f);
207 static int goal_bis_enter(void)
209 level_update_player_name();
210 return goal_init(NULL);
213 static void goal_timer(int id, float dt)
215 static float DT = 0.0f;
217 float gg[3] = { 0.0f, 9.8f, 0.0f };
218 float gf[3] = { 0.0f, -9.8f, 0.0f };
219 int state = curr_lg()->state;
223 if (time_state() < 2.f)
224 game_step((state == GAME_GOAL || state == GAME_SPEC) ? gg : gf, dt, NULL);
226 if (time_state() > 1.f && DT > 0.05f && coins_id != 0)
228 int coins = gui_value(coins_id);
231 int score = gui_value(score_id);
232 int balls = gui_value(balls_id);
234 gui_set_count(coins_id, coins - 1);
235 gui_pulse(coins_id, 1.1f);
237 gui_set_count(score_id, score + 1);
238 gui_pulse(score_id, 1.1f);
239 if ((score+1) % 100 == 0)
241 gui_set_count(balls_id, balls + 1);
242 gui_pulse(balls_id, 2.0f);
243 audio_play(AUD_BALL, 1.0f);
254 static int goal_buttn(int b, int d)
258 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
259 return goal_action(gui_token(gui_click()));
260 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
261 return goal_action(GOAL_BACK);
266 /*---------------------------------------------------------------------------*/
268 struct state st_goal = {
281 struct state st_goal_bis = {