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.
27 /*---------------------------------------------------------------------------*/
42 static float view_timer;
44 static void hud_fps(void)
50 int now = SDL_GetTicks();
54 fps = count * 1000 / (now - then);
58 gui_set_count(fps_id, fps);
68 if ((Rhud_id = gui_hstack(0)))
70 if ((id = gui_vstack(Rhud_id)))
72 gui_label(id, _("Coins"), GUI_SML, 0, gui_wht, gui_wht);
73 gui_label(id, _("Goal"), GUI_SML, 0, gui_wht, gui_wht);
75 if ((id = gui_vstack(Rhud_id)))
77 coin_id = gui_count(id, 100, GUI_SML, GUI_NW);
78 goal_id = gui_count(id, 10, GUI_SML, 0);
80 gui_layout(Rhud_id, +1, -1);
83 if ((Rhud2_id = gui_hstack(0)))
85 gui_label(Rhud2_id, _("Coins"), GUI_SML, 0, gui_wht, gui_wht);
86 coin2_id = gui_count(Rhud2_id, 100, GUI_SML, GUI_NW);
87 gui_layout(Rhud2_id, +1, -1);
90 if ((Lhud_id = gui_hstack(0)))
92 if ((id = gui_vstack(Lhud_id)))
94 ball_id = gui_count(id, 10, GUI_SML, GUI_NE);
95 scor_id = gui_count(id, 1000, GUI_SML, 0);
97 if ((id = gui_vstack(Lhud_id)))
99 gui_label(id, _("Balls"), GUI_SML, 0, gui_wht, gui_wht);
100 gui_label(id, _("Score"), GUI_SML, 0, gui_wht, gui_wht);
102 gui_layout(Lhud_id, -1, -1);
105 if ((time_id = gui_clock(0, 59999, GUI_MED, GUI_TOP)))
106 gui_layout(time_id, 0, -1);
108 str_view = strlen(STR_VIEW0) > strlen(STR_VIEW1) ? STR_VIEW0 : STR_VIEW1;
109 if (strlen(str_view) < strlen(STR_VIEW2))
110 str_view = STR_VIEW2;
111 if ((view_id = gui_label(0, str_view, GUI_SML, GUI_SW, gui_wht, gui_wht)))
112 gui_layout(view_id, 1, 1);
114 if ((fps_id = gui_count(0, 1000, GUI_SML, GUI_SE)))
115 gui_layout(fps_id, -1, 1);
129 int mode = level_mode();
130 if (mode == MODE_CHALLENGE)
132 if (mode == MODE_PRACTICE || mode == MODE_SINGLE)
138 if (config_get_d(CONFIG_FPS))
141 if (view_timer > 0.0f)
145 void hud_update(int pulse)
147 const int clock = curr_clock();
148 const int balls = curr_balls();
149 const int coins = curr_coins();
150 const int score = curr_score();
151 const int goal = curr_goal();
152 int mode = level_mode();
159 gui_pulse(ball_id, 0.f);
160 gui_pulse(time_id, 0.f);
161 gui_pulse(coin_id, 0.f);
164 /* time and tick-tock */
165 last = gui_value(time_id);
168 gui_set_clock(time_id, clock);
169 if (last > clock && pulse && mode != MODE_PRACTICE && mode != MODE_SINGLE)
171 if (clock <= 1000 && (last / 100) > (clock / 100))
173 audio_play(AUD_TICK, 1.f);
174 gui_pulse(time_id, 1.50);
176 else if (clock < 500 && (last / 50) > (clock / 50))
178 audio_play(AUD_TOCK, 1.f);
179 gui_pulse(time_id, 1.25);
184 /* balls and score + select coin widget */
185 if (mode == MODE_CHALLENGE)
187 if (gui_value(ball_id) != balls) gui_set_count(ball_id, balls);
188 if (gui_value(scor_id) != score) gui_set_count(scor_id, score);
190 } else if (mode == MODE_NORMAL)
195 /* coins and pulse */
196 last = gui_value(c_id);
200 gui_set_count(c_id, coins);
201 if (pulse && last > 0)
203 if (last >= 10) gui_pulse(coin_id, 2.00f);
204 else if (last >= 5) gui_pulse(coin_id, 1.50f);
205 else gui_pulse(coin_id, 1.25f);
209 if (last >= 10) gui_pulse(goal_id, 2.00f);
210 else if (last >= 5) gui_pulse(goal_id, 1.50f);
211 else gui_pulse(goal_id,1.25f);
217 last = gui_value(goal_id);
220 gui_set_count(goal_id, goal);
221 if (pulse && goal == 0 && last > 0)
222 gui_pulse(goal_id, 2.00f);
226 if (config_get_d(CONFIG_FPS))
230 void hud_timer(float dt)
237 gui_timer(Rhud_id, dt);
238 gui_timer(Lhud_id, dt);
239 gui_timer(time_id, dt);
240 gui_timer(view_id, dt);
243 void hud_view_pulse(int c)
247 case 0: gui_set_label(view_id, STR_VIEW0); break;
248 case 1: gui_set_label(view_id, STR_VIEW1); break;
249 case 2: gui_set_label(view_id, STR_VIEW2); break;
252 gui_pulse(view_id, 1.2f);
256 /*---------------------------------------------------------------------------*/