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 /*---------------------------------------------------------------------------*/
52 extern struct state st_goal_bis;
54 static int goal_action(int i)
56 audio_play(AUD_MENU, 1.0f);
61 return goto_end_level();
64 return goto_save(&st_goal_bis, &st_goal_bis);
67 return goto_name(&st_goal_bis, &st_goal_bis);
70 return goto_state(&st_done);
74 return goto_state(&st_level);
77 return goto_state(&st_level);
83 static int goal_init(int * gidp)
85 const char *s1 = _("New Record");
86 const char *s2 = _("GOAL");
90 if ((id = gui_vstack(0)))
95 gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
97 gid = gui_label(id, s2, GUI_LRG, GUI_ALL, gui_blu, gui_grn);
101 if (level_mode() == MODE_CHALLENGE)
103 int coins = curr_coins();
104 int score = curr_score() - coins;
105 int balls = curr_balls() - count_extra_balls(score, coins);
106 if ((jd = gui_hstack(id)))
108 if ((kd = gui_harray(jd)))
110 balls_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
111 gui_label(kd, _("Balls"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
113 if ((kd = gui_harray(jd)))
115 score_id = gui_count(kd, 1000, GUI_MED, GUI_RGT);
116 gui_label(kd, _("Score"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
118 if ((kd = gui_harray(jd)))
120 coins_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
121 gui_label(kd, _("Coins"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
124 gui_set_count(balls_id, balls);
125 gui_set_count(score_id, score);
126 gui_set_count(coins_id, coins);
132 if ((jd = gui_harray(id)))
134 gui_most_coins(jd, 3, 1);
135 gui_best_times(jd, 3, 1);
140 if ((jd = gui_harray(id)))
142 if (demo_play_saved())
143 gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
145 gui_label(jd, _("Save Replay"), GUI_SML, GUI_ALL, gui_blk, gui_blk);
147 if (level_mode() != MODE_CHALLENGE)
148 gui_start(jd, _("Retry Level"), GUI_SML, GOAL_SAME, 0);
150 if (level_mode() == MODE_CHALLENGE && level_last())
151 gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
152 else if (level_opened(curr_level()+1))
153 gui_state(jd, _("Next Level"), GUI_SML, GOAL_NEXT, 0);
154 else if (level_mode() != MODE_SINGLE)
155 gui_label(jd, _("Next Level"), GUI_SML, GUI_ALL, gui_blk, gui_blk);
159 gui_state(id, _("Change Player Name"), GUI_SML, GOAL_NAME, 0);
161 gui_layout(id, 0, 0);
162 if (gidp) *gidp = gid;
165 set_most_coins(curr_level(), coin_i);
166 set_best_times(curr_level(), time_i);
173 static int goal_enter(void)
180 high = level_sort(&time_i, &coin_i);
184 gui_pulse(gid, 1.2f);
185 audio_music_fade_out(2.0f);
189 static int goal_bis_enter(void)
192 config_get_s(CONFIG_PLAYER, player, MAXNAM);
193 level_name(curr_level(), player, time_i, coin_i);
194 return goal_init(NULL);
197 static void goal_timer(int id, float dt)
199 static float DT = 0.0f;
201 float g[3] = { 0.0f, 9.8f, 0.0f };
205 if (time_state() < 1.f)
207 else if (DT > 0.05f && level_mode() == MODE_CHALLENGE)
209 int coins = gui_value(coins_id);
212 int score = gui_value(score_id);
213 int balls = gui_value(balls_id);
215 gui_set_count(coins_id, coins - 1);
216 gui_pulse(coins_id, 1.1f);
218 gui_set_count(score_id, score + 1);
219 gui_pulse(score_id, 1.1f);
220 if ((score+1) % 100 == 0)
222 gui_set_count(balls_id, balls + 1);
223 gui_pulse(balls_id, 2.0f);
224 audio_play(AUD_BALL, 1.0f);
235 static int goal_buttn(int b, int d)
239 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
240 return goal_action(gui_token(gui_click()));
241 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
242 return goal_action(GOAL_BACK);
247 /*---------------------------------------------------------------------------*/
249 struct state st_goal = {
262 struct state st_goal_bis = {