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.
28 #include "game_common.h"
29 #include "game_client.h"
31 /*---------------------------------------------------------------------------*/
45 static int speed_ids[SPEED_MAX];
47 static const char *speed_labels[SPEED_MAX] = {
48 "", "8", "4", "2", "1", "2", "4", "8"
51 static float view_timer;
52 static float speed_timer;
54 static void hud_fps(void)
56 gui_set_count(fps_id, video_perf());
65 if ((Rhud_id = gui_hstack(0)))
67 if ((id = gui_vstack(Rhud_id)))
69 gui_label(id, _("Coins"), GUI_SML, 0, gui_wht, gui_wht);
70 gui_label(id, _("Goal"), GUI_SML, 0, gui_wht, gui_wht);
72 if ((id = gui_vstack(Rhud_id)))
74 coin_id = gui_count(id, 100, GUI_SML, GUI_NW);
75 goal_id = gui_count(id, 10, GUI_SML, 0);
77 gui_layout(Rhud_id, +1, -1);
80 if ((Lhud_id = gui_hstack(0)))
82 if ((id = gui_vstack(Lhud_id)))
84 ball_id = gui_count(id, 10, GUI_SML, GUI_NE);
85 scor_id = gui_count(id, 1000, GUI_SML, 0);
87 if ((id = gui_vstack(Lhud_id)))
89 gui_label(id, _("Balls"), GUI_SML, 0, gui_wht, gui_wht);
90 gui_label(id, _("Score"), GUI_SML, 0, gui_wht, gui_wht);
92 gui_layout(Lhud_id, -1, -1);
95 if ((time_id = gui_clock(0, 59999, GUI_MED, GUI_TOP)))
96 gui_layout(time_id, 0, -1);
99 /* Find the longest view name. */
101 for (str_view = "", v = VIEW_NONE + 1; v < VIEW_MAX; v++)
102 if (strlen(view_to_str(v)) > strlen(str_view))
103 str_view = view_to_str(v);
105 if ((view_id = gui_label(0, str_view, GUI_SML, GUI_SW, gui_wht, gui_wht)))
106 gui_layout(view_id, 1, 1);
108 if ((fps_id = gui_count(0, 1000, GUI_SML, GUI_SE)))
109 gui_layout(fps_id, -1, 1);
111 if ((speed_id = gui_varray(0)))
115 for (i = SPEED_MAX - 1; i > SPEED_NONE; i--)
119 if (i == SPEED_MAX - 1)
121 if (i == SPEED_NONE + 1)
124 speed_ids[i] = gui_label(speed_id, speed_labels[i],
125 GUI_SML, rect, 0, 0);
128 gui_layout(speed_id, +1, 0);
143 if (curr_mode() == MODE_CHALLENGE)
149 if (config_get_d(CONFIG_FPS))
156 void hud_update(int pulse)
158 int clock = curr_clock();
159 int coins = curr_coins();
160 int goal = curr_goal();
161 int balls = curr_balls();
162 int score = curr_score();
171 gui_pulse(ball_id, 0.f);
172 gui_pulse(time_id, 0.f);
173 gui_pulse(coin_id, 0.f);
178 /* time and tick-tock */
180 if (clock != (last = gui_value(time_id)))
182 gui_set_clock(time_id, clock);
184 if (last > clock && pulse)
186 if (clock <= 1000 && (last / 100) > (clock / 100))
188 audio_play(AUD_TICK, 1.f);
189 gui_pulse(time_id, 1.50);
191 else if (clock < 500 && (last / 50) > (clock / 50))
193 audio_play(AUD_TOCK, 1.f);
194 gui_pulse(time_id, 1.25);
199 /* balls and score + select coin widget */
204 if (gui_value(ball_id) != balls) gui_set_count(ball_id, balls);
205 if (gui_value(scor_id) != score) gui_set_count(scor_id, score);
216 /* coins and pulse */
218 if (coins != (last = gui_value(c_id)))
222 gui_set_count(c_id, coins);
224 if (pulse && last > 0)
226 if (last >= 10) gui_pulse(coin_id, 2.00f);
227 else if (last >= 5) gui_pulse(coin_id, 1.50f);
228 else gui_pulse(coin_id, 1.25f);
232 if (last >= 10) gui_pulse(goal_id, 2.00f);
233 else if (last >= 5) gui_pulse(goal_id, 1.50f);
234 else gui_pulse(goal_id, 1.25f);
241 if (goal != (last = gui_value(goal_id)))
243 gui_set_count(goal_id, goal);
245 if (pulse && goal == 0 && last > 0)
246 gui_pulse(goal_id, 2.00f);
249 if (config_get_d(CONFIG_FPS))
253 void hud_timer(float dt)
257 gui_timer(Rhud_id, dt);
258 gui_timer(Lhud_id, dt);
259 gui_timer(time_id, dt);
265 /*---------------------------------------------------------------------------*/
267 void hud_view_pulse(int c)
269 gui_set_label(view_id, view_to_str(c));
270 gui_pulse(view_id, 1.2f);
274 void hud_view_timer(float dt)
277 gui_timer(view_id, dt);
280 void hud_view_paint(void)
282 if (view_timer > 0.0f)
286 /*---------------------------------------------------------------------------*/
288 void hud_speed_pulse(int speed)
292 for (i = SPEED_NONE + 1; i < SPEED_MAX; i++)
294 const GLubyte *c = gui_gry;
296 if (speed != SPEED_NONE)
298 if (i > SPEED_NORMAL && i <= speed)
300 else if (i < SPEED_NORMAL && i >= speed)
302 else if (i == SPEED_NORMAL)
306 gui_set_color(speed_ids[i], c, c);
309 gui_pulse(speed_ids[i], 1.2f);
315 void hud_speed_timer(float dt)
318 gui_timer(speed_id, dt);
321 void hud_speed_paint(void)
323 if (speed_timer > 0.0f)
327 /*---------------------------------------------------------------------------*/