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 #include "game_common.h"
28 #include "game_client.h"
30 /*---------------------------------------------------------------------------*/
43 static float view_timer;
45 static void hud_fps(void)
47 gui_set_count(fps_id, video_perf());
56 if ((Rhud_id = gui_hstack(0)))
58 if ((id = gui_vstack(Rhud_id)))
60 gui_label(id, _("Coins"), GUI_SML, 0, gui_wht, gui_wht);
61 gui_label(id, _("Goal"), GUI_SML, 0, gui_wht, gui_wht);
63 if ((id = gui_vstack(Rhud_id)))
65 coin_id = gui_count(id, 100, GUI_SML, GUI_NW);
66 goal_id = gui_count(id, 10, GUI_SML, 0);
68 gui_layout(Rhud_id, +1, -1);
71 if ((Lhud_id = gui_hstack(0)))
73 if ((id = gui_vstack(Lhud_id)))
75 ball_id = gui_count(id, 10, GUI_SML, GUI_NE);
76 scor_id = gui_count(id, 1000, GUI_SML, 0);
78 if ((id = gui_vstack(Lhud_id)))
80 gui_label(id, _("Balls"), GUI_SML, 0, gui_wht, gui_wht);
81 gui_label(id, _("Score"), GUI_SML, 0, gui_wht, gui_wht);
83 gui_layout(Lhud_id, -1, -1);
86 if ((time_id = gui_clock(0, 59999, GUI_MED, GUI_TOP)))
87 gui_layout(time_id, 0, -1);
90 /* Find the longest view name. */
92 for (str_view = "", v = VIEW_NONE + 1; v < VIEW_MAX; v++)
93 if (strlen(view_to_str(v)) > strlen(str_view))
94 str_view = view_to_str(v);
96 if ((view_id = gui_label(0, str_view, GUI_SML, GUI_SW, gui_wht, gui_wht)))
97 gui_layout(view_id, 1, 1);
99 if ((fps_id = gui_count(0, 1000, GUI_SML, GUI_SE)))
100 gui_layout(fps_id, -1, 1);
114 if (curr_mode() == MODE_CHALLENGE)
120 if (config_get_d(CONFIG_FPS))
123 if (view_timer > 0.0f)
127 void hud_update(int pulse)
129 int clock = curr_clock();
130 int coins = curr_coins();
131 int goal = curr_goal();
132 int balls = curr_balls();
133 int score = curr_score();
142 gui_pulse(ball_id, 0.f);
143 gui_pulse(time_id, 0.f);
144 gui_pulse(coin_id, 0.f);
147 /* time and tick-tock */
149 if (clock != (last = gui_value(time_id)))
151 gui_set_clock(time_id, clock);
153 if (last > clock && pulse)
155 if (clock <= 1000 && (last / 100) > (clock / 100))
157 audio_play(AUD_TICK, 1.f);
158 gui_pulse(time_id, 1.50);
160 else if (clock < 500 && (last / 50) > (clock / 50))
162 audio_play(AUD_TOCK, 1.f);
163 gui_pulse(time_id, 1.25);
168 /* balls and score + select coin widget */
173 if (gui_value(ball_id) != balls) gui_set_count(ball_id, balls);
174 if (gui_value(scor_id) != score) gui_set_count(scor_id, score);
185 /* coins and pulse */
187 if (coins != (last = gui_value(c_id)))
191 gui_set_count(c_id, coins);
193 if (pulse && last > 0)
195 if (last >= 10) gui_pulse(coin_id, 2.00f);
196 else if (last >= 5) gui_pulse(coin_id, 1.50f);
197 else gui_pulse(coin_id, 1.25f);
201 if (last >= 10) gui_pulse(goal_id, 2.00f);
202 else if (last >= 5) gui_pulse(goal_id, 1.50f);
203 else gui_pulse(goal_id, 1.25f);
210 if (goal != (last = gui_value(goal_id)))
212 gui_set_count(goal_id, goal);
214 if (pulse && goal == 0 && last > 0)
215 gui_pulse(goal_id, 2.00f);
218 if (config_get_d(CONFIG_FPS))
222 void hud_timer(float dt)
229 gui_timer(Rhud_id, dt);
230 gui_timer(Lhud_id, dt);
231 gui_timer(time_id, dt);
232 gui_timer(view_id, dt);
235 void hud_view_pulse(int c)
237 gui_set_label(view_id, view_to_str(c));
238 gui_pulse(view_id, 1.2f);
242 /*---------------------------------------------------------------------------*/