X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=ball%2Fhud.c;h=c339d4a1b653043adc5f9ad6cdad3ac01081891c;hb=76d05f44396a09df4f90e3d22bffe75c9665619c;hp=5ccee8772d0b1169cc2d4954e6dcb49edf0e3664;hpb=c7fbb8e859b7c1b25e16a92755461b8044a7d452;p=neverball diff --git a/ball/hud.c b/ball/hud.c index 5ccee87..c339d4a 100644 --- a/ball/hud.c +++ b/ball/hud.c @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003 Robert Kooima * * NEVERBALL is free software; you can redistribute it and/or modify @@ -20,8 +20,9 @@ #include "hud.h" #include "gui.h" #include "game.h" -#include "level.h" +#include "progress.h" #include "config.h" +#include "audio.h" /*---------------------------------------------------------------------------*/ @@ -40,26 +41,13 @@ static float view_timer; static void hud_fps(void) { - static int fps = 0; - static int then = 0; - static int count = 0; - - int now = SDL_GetTicks(); - - if (now - then > 250) - { - fps = count * 1000 / (now - then); - then = now; - count = 0; - - gui_set_count(fps_id, fps); - } - else count++; + gui_set_count(fps_id, config_perf()); } void hud_init(void) { int id; + char *str_view; if ((Rhud_id = gui_hstack(0))) { @@ -94,7 +82,10 @@ void hud_init(void) if ((time_id = gui_clock(0, 59999, GUI_MED, GUI_TOP))) gui_layout(time_id, 0, -1); - if ((view_id = gui_label(0, "xxxxxxxxxxxxxxx", GUI_SML, GUI_SW, gui_wht, gui_wht))) + str_view = strlen(STR_VIEW0) > strlen(STR_VIEW1) ? STR_VIEW0 : STR_VIEW1; + if (strlen(str_view) < strlen(STR_VIEW2)) + str_view = STR_VIEW2; + if ((view_id = gui_label(0, str_view, GUI_SML, GUI_SW, gui_wht, gui_wht))) gui_layout(view_id, 1, 1); if ((fps_id = gui_count(0, 1000, GUI_SML, GUI_SE))) @@ -112,8 +103,9 @@ void hud_free(void) void hud_paint(void) { - if (level_mode() == MODE_CHALLENGE) + if (curr_mode() == MODE_CHALLENGE) gui_paint(Lhud_id); + gui_paint(Rhud_id); gui_paint(time_id); @@ -124,25 +116,105 @@ void hud_paint(void) gui_paint(view_id); } -void hud_timer(float dt) +void hud_update(int pulse) { - const int clock = curr_clock(); - const int balls = curr_balls(); - const int coins = curr_coins(); - const int score = curr_score(); - const int goal = curr_goal(); - - if (gui_value(time_id) != clock) gui_set_clock(time_id, clock); - if (level_mode() == MODE_CHALLENGE) + int clock = curr_clock(); + int coins = curr_coins(); + int goal = curr_goal(); + int balls = curr_balls(); + int score = curr_score(); + + int c_id; + int last; + + if (!pulse) + { + /* reset the hud */ + + gui_pulse(ball_id, 0.f); + gui_pulse(time_id, 0.f); + gui_pulse(coin_id, 0.f); + } + + /* time and tick-tock */ + + if (clock != (last = gui_value(time_id))) { + gui_set_clock(time_id, clock); + + if (last > clock && pulse) + { + if (clock <= 1000 && (last / 100) > (clock / 100)) + { + audio_play(AUD_TICK, 1.f); + gui_pulse(time_id, 1.50); + } + else if (clock < 500 && (last / 50) > (clock / 50)) + { + audio_play(AUD_TOCK, 1.f); + gui_pulse(time_id, 1.25); + } + } + } + + /* balls and score + select coin widget */ + + switch (curr_mode()) + { + case MODE_CHALLENGE: if (gui_value(ball_id) != balls) gui_set_count(ball_id, balls); - if (gui_value(scor_id) != score) gui_set_count(scor_id, score); + if (gui_value(scor_id) != score) gui_set_count(scor_id, score); + + c_id = coin_id; + break; + + default: + c_id = coin_id; + break; + } + + + /* coins and pulse */ + + if (coins != (last = gui_value(c_id))) + { + last = coins - last; + + gui_set_count(c_id, coins); + + if (pulse && last > 0) + { + if (last >= 10) gui_pulse(coin_id, 2.00f); + else if (last >= 5) gui_pulse(coin_id, 1.50f); + else gui_pulse(coin_id, 1.25f); + + if (goal > 0) + { + if (last >= 10) gui_pulse(goal_id, 2.00f); + else if (last >= 5) gui_pulse(goal_id, 1.50f); + else gui_pulse(goal_id, 1.25f); + } + } + } + + /* goal and pulse */ + + if (goal != (last = gui_value(goal_id))) + { + gui_set_count(goal_id, goal); + + if (pulse && goal == 0 && last > 0) + gui_pulse(goal_id, 2.00f); } - if (gui_value(coin_id) != coins) gui_set_count(coin_id, coins); - if (gui_value(goal_id) != goal) gui_set_count(goal_id, goal); if (config_get_d(CONFIG_FPS)) hud_fps(); +} + +void hud_timer(float dt) +{ + + hud_update(1); view_timer -= dt; @@ -152,15 +224,10 @@ void hud_timer(float dt) gui_timer(view_id, dt); } -void hud_ball_pulse(float k) { gui_pulse(ball_id, k); } -void hud_time_pulse(float k) { gui_pulse(time_id, k); } -void hud_coin_pulse(float k) { gui_pulse(coin_id, k); } -void hud_goal_pulse(float k) { gui_pulse(goal_id, k); } - void hud_view_pulse(int c) { switch (c) - { + { case 0: gui_set_label(view_id, STR_VIEW0); break; case 1: gui_set_label(view_id, STR_VIEW1); break; case 2: gui_set_label(view_id, STR_VIEW2); break;