diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-05-17 22:48:25 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-05-17 22:48:25 +0200 |
| commit | 003c13a4ae07c3ec15a31df0f7f65e3d1ffe9ae0 (patch) | |
| tree | a56b0e1d84d297c5869e8272fcac58c298a51ed5 /src | |
| parent | f06351b8a04d0a68628b05bed884832840998c6c (diff) | |
game fade in and out
Diffstat (limited to 'src')
| -rw-r--r-- | src/asset_defs.c | 1 | ||||
| -rw-r--r-- | src/game.c | 14 | ||||
| -rw-r--r-- | src/overlay.c | 43 | ||||
| -rw-r--r-- | src/protocol.c | 1 | ||||
| -rw-r--r-- | src/rounds.c | 24 |
5 files changed, 69 insertions, 14 deletions
diff --git a/src/asset_defs.c b/src/asset_defs.c index 495f064..171c759 100644 --- a/src/asset_defs.c +++ b/src/asset_defs.c @@ -33,6 +33,7 @@ void load_assets() { // Assets loaded at match start. // UI img_red_border = assets_load_image_from_file("data/imgs/ui/red_border.png"); img_heart = assets_load_image_from_file("data/imgs/ui/heart.png"); + img_skull = assets_load_image_from_file("data/imgs/ui/skull.png"); img_hurt_overlay_left = assets_load_image_from_file("data/imgs/ui/hurt_overlay_left.png"); img_hurt_overlay_right = assets_load_image_from_file("data/imgs/ui/hurt_overlay_right.png"); img_stats_overlay = assets_load_image_from_file("data/imgs/ui/stats_overlay.png"); @@ -1,6 +1,8 @@ #include "../include/game.h" #include "../include/pathfinding.h" +bool game_is_paused = false; + static void server_on_client_disconnect(network_client c) { for (int i = 0; i < MAX_PLAYERS; i++) { player p = players[i]; @@ -241,6 +243,17 @@ static void rotate_user(platform_window* window, protocol_user_look *message) { p->diry = message->diry; } +bool every_player_died() +{ + for (int i = 0; i < MAX_PLAYERS; i++) { + player p = players[i]; + if (!p.active) continue; + // TODO: if player is disconnected for 2+ min, kill player. + if (p.health != 0) return false; + } + return true; +} + static void set_ping_for_player(protocol_generic_message* msg) { u64 diff = platform_get_time(TIME_FULL, TIME_MILI_S) - msg->send_timestamp; @@ -430,6 +443,7 @@ void update_client(platform_window* window) { case MESSAGE_ROUND_DATA: { protocol_round* msg_round = (protocol_round*)msg; _current_round = msg_round->round; + game_is_paused = msg_round->game_is_paused; } break; case MESSAGE_ZOMBIE_LIST: { diff --git a/src/overlay.c b/src/overlay.c index 185173e..988406e 100644 --- a/src/overlay.c +++ b/src/overlay.c @@ -234,23 +234,30 @@ static void draw_hurt_borders(platform_window* window) { if (!p) return; if (p->max_health == p->health) return; - if (p->health == 0) return; - - float freq = 1.0f * (p->health/(float)p->max_health); - static float heatbeat_timestamp = 0.0f; - heatbeat_timestamp += update_delta; + if (p->health == 0) + { + int skull_size = window->width / 7; + renderer->render_image(img_skull, + _global_camera.x + (window->width/2)-(skull_size/2), + _global_camera.y + (window->height/2)-(skull_size/2), skull_size, skull_size); + } + else { + float freq = 1.0f * (p->health/(float)p->max_health); + static float heatbeat_timestamp = 0.0f; + heatbeat_timestamp += update_delta; - float opacity = 1.0f - (heatbeat_timestamp / freq); - int heart_size = window->width / 7; - color c = rgba(255,255,255,255*opacity); + float opacity = 1.0f - (heatbeat_timestamp / freq); + int heart_size = window->width / 7; + color c = rgba(255,255,255,255*opacity); - renderer->render_image_tint(img_heart, - _global_camera.x + (window->width/2)-(heart_size/2), - _global_camera.y + (window->height/2)-(heart_size/2), heart_size, heart_size, c); + renderer->render_image_tint(img_heart, + _global_camera.x + (window->width/2)-(heart_size/2), + _global_camera.y + (window->height/2)-(heart_size/2), heart_size, heart_size, c); - if (heatbeat_timestamp >= freq) { - heatbeat_timestamp = 0.0f; - play_sound(-1, wav_heartbeat); + if (heatbeat_timestamp >= freq) { + heatbeat_timestamp = 0.0f; + play_sound(-1, wav_heartbeat); + } } float border_opacity = 1.0f - (p->health/(float)p->max_health); @@ -314,6 +321,13 @@ static void draw_global_message(platform_window* window) { renderer->render_text(fnt_52, x + (window->width/2)-(text_w/2), y, text, rgb(255,255,255)); } +static void draw_fadein_overlay(platform_window* window) +{ + float percentage = _current_round.fade_in_timer / FADE_IN_DURATION; + if (percentage <= 0.0f) return; + renderer->render_rectangle(_global_camera.x, _global_camera.y, window->width, window->height, rgba(0,0,0,255*percentage)); +} + void draw_overlay(platform_window* window) { draw_hurt_borders(window); draw_gun_info(window); @@ -321,4 +335,5 @@ void draw_overlay(platform_window* window) { draw_leaderboard(window); draw_debug_stats(window); draw_global_message(window); + draw_fadein_overlay(window); }
\ No newline at end of file diff --git a/src/protocol.c b/src/protocol.c index cfcbd10..1070ff0 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -88,6 +88,7 @@ network_message create_protocol_round_data(zombie_round round) protocol_round *buf = alloc_network_message(protocol_round); buf->type = MESSAGE_ROUND_DATA; buf->round = round; + buf->game_is_paused = game_is_paused; return network_create_message((u8*)buf, sizeof(protocol_round), MAX_NETWORK_BUFFER_SIZE); } diff --git a/src/rounds.c b/src/rounds.c index 4d69aff..4c991af 100644 --- a/src/rounds.c +++ b/src/rounds.c @@ -21,6 +21,11 @@ void start_next_round() _current_round.state = ROUND_SWITCHING; _current_round.round_timer = 0.0f; + // Fade in at start of game. + if (_current_round.round_nr == 1) { + _current_round.fade_in_timer = FADE_IN_DURATION; + } + add_ui_audio_event_to_queue(EVENT_ROUND_CHANGE); log_infox("Next round: %d", _current_round.round_nr); @@ -85,10 +90,29 @@ void draw_round(platform_window* window) { } } +void restart_game() +{ + // TODO +} + void update_round_server() { static int visible_previously_count = 0; + if (!every_player_died()) { + _current_round.fade_in_timer -= SERVER_TICK_RATE; + if (_current_round.fade_in_timer <= 0.0f) + _current_round.fade_in_timer = 0.0f; + } + else { + _current_round.fade_in_timer += SERVER_TICK_RATE; + if (_current_round.fade_in_timer >= FADE_IN_DURATION) { + _current_round.fade_in_timer = FADE_IN_DURATION; + + restart_game(); + } + } + _current_round.round_timer += SERVER_TICK_RATE; if (_current_round.state == ROUND_SWITCHING) { if (_current_round.round_timer >= ROUND_SWITCH_TIME) { |
