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 char *s1 = _("New Record");
82 const char *s2 = _("GOAL");
83 const struct level_game *lg = curr_lg();
84 int mode = curr_lg()->mode;
85 const struct level *level = lg->level;
90 high = (lg->time_rank < 3) || (lg->goal_rank < 3) || (lg->coin_rank < 3);
92 if ((id = gui_vstack(0)))
97 gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
99 gid = gui_label(id, s2, GUI_LRG, GUI_ALL, gui_blu, gui_grn);
103 if (mode == MODE_CHALLENGE)
105 int coins = lg->coins;
106 int score = lg->score - coins;
107 int balls = lg->balls - count_extra_balls(score, coins);
108 if ((jd = gui_hstack(id)))
110 if ((kd = gui_harray(jd)))
112 balls_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
113 gui_label(kd, _("Balls"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
115 if ((kd = gui_harray(jd)))
117 score_id = gui_count(kd, 1000, GUI_MED, GUI_RGT);
118 gui_label(kd, _("Score"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
120 if ((kd = gui_harray(jd)))
122 coins_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
123 gui_label(kd, _("Coins"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
126 gui_set_count(balls_id, balls);
127 gui_set_count(score_id, score);
128 gui_set_count(coins_id, coins);
134 if ((jd = gui_harray(id)))
136 gui_most_coins(jd, 1);
137 gui_best_times(jd, 1);
142 if ((jd = gui_harray(id)))
144 if (demo_play_saved())
145 gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
147 gui_label(jd, _("Save Replay"), GUI_SML, GUI_ALL, gui_blk, gui_blk);
149 if (mode != MODE_CHALLENGE)
150 gui_start(jd, _("Retry Level"), GUI_SML, GOAL_SAME, 0);
153 gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
154 else if (lg->next_level != NULL)
155 gui_state(jd, _("Next Level"), GUI_SML, GOAL_NEXT, 0);
156 else if (mode != MODE_SINGLE)
157 gui_label(jd, _("Next Level"), GUI_SML, GUI_ALL, gui_blk, gui_blk);
161 gui_state(id, _("Change Player Name"), GUI_SML, GOAL_NAME, 0);
163 gui_layout(id, 0, 0);
164 if (gidp) *gidp = gid;
167 set_most_coins(&level->coin_score, lg->coin_rank);
168 if (mode == MODE_CHALLENGE || mode == MODE_NORMAL)
169 set_best_times(&level->goal_score, lg->goal_rank, 1);
171 set_best_times(&level->time_score, lg->time_rank, 0);
178 static int goal_enter(void)
185 gui_pulse(gid, 1.2f);
186 audio_music_fade_out(2.0f);
190 static int goal_bis_enter(void)
192 level_update_player_name();
193 return goal_init(NULL);
196 static void goal_timer(int id, float dt)
198 static float DT = 0.0f;
200 float g[3] = { 0.0f, 9.8f, 0.0f };
204 if (time_state() < 1.f)
205 game_step(g, dt, NULL);
206 else if (DT > 0.05f && curr_lg()->mode == MODE_CHALLENGE)
208 int coins = gui_value(coins_id);
211 int score = gui_value(score_id);
212 int balls = gui_value(balls_id);
214 gui_set_count(coins_id, coins - 1);
215 gui_pulse(coins_id, 1.1f);
217 gui_set_count(score_id, score + 1);
218 gui_pulse(score_id, 1.1f);
219 if ((score+1) % 100 == 0)
221 gui_set_count(balls_id, balls + 1);
222 gui_pulse(balls_id, 2.0f);
223 audio_play(AUD_BALL, 1.0f);
234 static int goal_buttn(int b, int d)
238 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
239 return goal_action(gui_token(gui_click()));
240 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
241 return goal_action(GOAL_BACK);
246 /*---------------------------------------------------------------------------*/
248 struct state st_goal = {
261 struct state st_goal_bis = {