From cb9c0f812695da554e1feb5afe71b38324b65103 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sun, 24 Dec 2023 11:04:11 +0100 Subject: new font and audio --- src/rounds.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/rounds.c') diff --git a/src/rounds.c b/src/rounds.c index 7d40493..88166c6 100644 --- a/src/rounds.c +++ b/src/rounds.c @@ -38,12 +38,14 @@ static float get_round_text_opacity() { return opacity; } +static int round_text_len = 0; void draw_round(platform_window* window) { if (_current_round.round_nr == 0) return; char round_text[30]; int window_center_x = _global_camera.x + window->width / 2; sprintf(round_text, "ROUND %d", _current_round.round_nr); + round_text_len = strlen(round_text); int text_w = renderer->calculate_text_width(fnt_24, round_text); int final_text_y = _global_camera.y + 20; @@ -64,7 +66,11 @@ void draw_round(platform_window* window) { renderer->render_text(fnt_20, window_center_x - (time_text_w/2), final_text_y, time_text, rgb(189, 39, 19)); } else if (_current_round.state == ROUND_SWITCHING) { - //float opacity = get_round_text_opacity(); + float delay_per_char = 0.1f; + int characters_visible_count = _current_round.round_timer/delay_per_char; + if (characters_visible_count > round_text_len) characters_visible_count = round_text_len; + round_text[characters_visible_count] = 0; + text_w = renderer->calculate_text_width(fnt_32, round_text); final_text_y = _global_camera.y + window->height/4.0f; int box_pad = 10; @@ -73,18 +79,29 @@ void draw_round(platform_window* window) { int box_w = text_w + box_pad*2; int box_h = fnt_32->px_h + box_pad*2; renderer->render_rectangle(box_x, box_y, box_w, box_h, rgba(255,0,0,100)); - renderer->render_text(fnt_32, window_center_x - (text_w/2)+1, final_text_y+1, round_text, rgba(0,0,0,120)); renderer->render_text(fnt_32, window_center_x - (text_w/2), final_text_y, round_text, rgba(255,255,255,255)); } } void update_round_server() { + static int visible_previously_count = 0; + _current_round.round_timer += SERVER_TICK_RATE; if (_current_round.state == ROUND_SWITCHING) { if (_current_round.round_timer >= ROUND_SWITCH_TIME) { _current_round.state = ROUND_SPAWNING; - _current_round.round_timer = 0.0f; + _current_round.round_timer = 0.0f; + visible_previously_count = 0; + } + + float delay_per_char = 0.1f; + int characters_visible_count = _current_round.round_timer/delay_per_char; + if (characters_visible_count > round_text_len) characters_visible_count = round_text_len; + if (visible_previously_count < characters_visible_count) { + add_ui_audio_event_to_queue(EVENT_CHARACTER_TYPE); + log_info("CHARACTER!"); + visible_previously_count = characters_visible_count; } } -- cgit v1.2.3-70-g09d2