From b2ca9b477856cd8ea284389b91d718e8ea814d7b Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Thu, 16 May 2024 14:13:12 +0200 Subject: hurt feedback --- data/imgs/ui/heart.png | Bin 0 -> 376722 bytes data/imgs/ui/hurt_overlay_left.png | Bin 0 -> 920200 bytes data/imgs/ui/hurt_overlay_right.png | Bin 0 -> 921303 bytes data/sounds/heartbeat.wav | Bin 0 -> 85000 bytes include/asset_defs.h | 5 ++++- include/rounds.h | 2 +- src/asset_defs.c | 4 ++++ src/game.c | 10 +++++++-- src/overlay.c | 39 ++++++++++++++++++++++++++++++++---- src/zombies.c | 4 ++-- 10 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 data/imgs/ui/heart.png create mode 100644 data/imgs/ui/hurt_overlay_left.png create mode 100644 data/imgs/ui/hurt_overlay_right.png create mode 100644 data/sounds/heartbeat.wav diff --git a/data/imgs/ui/heart.png b/data/imgs/ui/heart.png new file mode 100644 index 0000000..d49a705 Binary files /dev/null and b/data/imgs/ui/heart.png differ diff --git a/data/imgs/ui/hurt_overlay_left.png b/data/imgs/ui/hurt_overlay_left.png new file mode 100644 index 0000000..d9e83f8 Binary files /dev/null and b/data/imgs/ui/hurt_overlay_left.png differ diff --git a/data/imgs/ui/hurt_overlay_right.png b/data/imgs/ui/hurt_overlay_right.png new file mode 100644 index 0000000..6e45078 Binary files /dev/null and b/data/imgs/ui/hurt_overlay_right.png differ diff --git a/data/sounds/heartbeat.wav b/data/sounds/heartbeat.wav new file mode 100644 index 0000000..fb7e4b5 Binary files /dev/null and b/data/sounds/heartbeat.wav differ diff --git a/include/asset_defs.h b/include/asset_defs.h index 5b26329..23610b4 100644 --- a/include/asset_defs.h +++ b/include/asset_defs.h @@ -32,6 +32,9 @@ font* fnt_4; // UI image* img_red_border; +image* img_heart; +image* img_hurt_overlay_left; +image* img_hurt_overlay_right; // Icons image* img_icon_bullets; @@ -177,7 +180,7 @@ image* img_tile_concrete; Mix_Chunk* wav_throwable_bounce; Mix_Chunk* wav_grenade_explode; Mix_Chunk* wav_molotov_explode; - +Mix_Chunk* wav_heartbeat; Mix_Chunk* wav_fire; Mix_Chunk* wav_shoot_mp5; diff --git a/include/rounds.h b/include/rounds.h index de787b4..e13f58d 100644 --- a/include/rounds.h +++ b/include/rounds.h @@ -17,7 +17,7 @@ typedef struct t_zombie_round { float round_timer; } zombie_round; -zombie_round _current_round = {.round_nr = 0, .zombies = 0, .state = ROUND_SWITCHING}; +zombie_round _current_round = {.round_nr = 12, .zombies = 0, .state = ROUND_SWITCHING}; bool current_round_is_done(); void start_next_round(); diff --git a/src/asset_defs.c b/src/asset_defs.c index 45a248f..1440e48 100644 --- a/src/asset_defs.c +++ b/src/asset_defs.c @@ -32,6 +32,9 @@ void load_menu_assets() { // Assets loaded at game start 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_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"); // Icons img_icon_bullets = assets_load_image_from_file("data/imgs/bullets.png"); @@ -195,6 +198,7 @@ void load_assets() { // Assets loaded at match start. wav_roar_enraged = Mix_LoadWAV("data/sounds/roar_enraged.wav"); wav_door_open = Mix_LoadWAV("data/sounds/door_open.wav"); wav_door_close = Mix_LoadWAV("data/sounds/door_close.wav"); + wav_heartbeat = Mix_LoadWAV("data/sounds/heartbeat.wav"); for (int i = 1; i <= NUM_SCREECHES; i++) { char path[100]; diff --git a/src/game.c b/src/game.c index 6081df1..de62746 100644 --- a/src/game.c +++ b/src/game.c @@ -107,8 +107,13 @@ void load_map() { pathfinding_init(); - thread t = thread_start(pathfinding_thread, 0); - thread_detach(&t); + // TODO: only need this on server? + thread t1 = thread_start(pathfinding_thread, 0); + thread_detach(&t1); + thread t2 = thread_start(pathfinding_thread, 0); + thread_detach(&t2); + thread t3 = thread_start(pathfinding_thread, 0); + thread_detach(&t3); log_info("STATE: GAMESTATE_LOADING_ASSETS"); global_state.state = GAMESTATE_LOADING_ASSETS; @@ -148,6 +153,7 @@ static void rotate_user(platform_window* window, protocol_user_look *message) { log_info("Unknown user rotated"); return; } + if (p->interact_state == INTERACT_DEAD) return; p->gunx = p->playerx + message->gunx; p->guny = p->playery - 0.5f + message->guny; diff --git a/src/overlay.c b/src/overlay.c index 2dfbb9c..75c465a 100644 --- a/src/overlay.c +++ b/src/overlay.c @@ -111,11 +111,11 @@ void draw_debug_stats(platform_window* window) { count++; } - char fps_text[50]; - snprintf(fps_text, 50, "FPS: %d, MS: %.4f, USAGE: %.0f%%", (int)fps, update_delta*1000.0f, usage); + char fps_text[100]; + snprintf(fps_text, 100, "FPS: %d, MS: %.4f, USAGE: %.0f%%", (int)fps, update_delta*1000.0f, usage); - char update_text[50]; - snprintf(update_text, 50, "update: %.2fms, queue: %d", logic_update_time/1000000.0f, count); + char update_text[100]; + snprintf(update_text, 100, "update: %.2fms, tcp queue: %d, pathfinding queue: %d", logic_update_time/1000000.0f, count, global_pathfinding_queue.length); renderer->render_text(fnt_20, _global_camera.x, _global_camera.y + fnt_20->px_h*0, fps_text, rgb(0,0,0)); renderer->render_text(fnt_20, _global_camera.x, _global_camera.y + fnt_20->px_h*1, update_text, rgb(0,0,0)); @@ -160,6 +160,36 @@ static void draw_hurt_borders(platform_window* window) { player* p = get_player_by_id(player_id); 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; + + 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); + + if (heatbeat_timestamp >= freq) { + heatbeat_timestamp = 0.0f; + play_sound(-1, wav_heartbeat); + } + + float border_opacity = 1.0f - (p->health/(float)p->max_health); + int hurt_border_width = window->width / (6 - (border_opacity*3)); + color border_color = rgba(255,255,255,255*border_opacity); + + renderer->render_image_tint(img_hurt_overlay_left, _global_camera.x, + _global_camera.y, hurt_border_width, window->height, border_color); + renderer->render_image_tint(img_hurt_overlay_right, _global_camera.x + window->width - hurt_border_width, + _global_camera.y, hurt_border_width, window->height, border_color); + + /* int width = window->width * 0.1f; float opacity = 1.0f - (p->health/(float)p->max_health); if (opacity < 0.0f) opacity = 0.0f; @@ -196,6 +226,7 @@ static void draw_hurt_borders(platform_window* window) { _global_camera.x + window->width, _global_camera.y + window->height, _global_camera.x + window->width, _global_camera.y + window->height - width, top.tl, top.tr, top.bl, top.br, c); + */ } void draw_overlay(platform_window* window) { diff --git a/src/zombies.c b/src/zombies.c index 3bad715..9826ec2 100644 --- a/src/zombies.c +++ b/src/zombies.c @@ -191,7 +191,7 @@ static void despawn_far_zombies_server() float dist = 0.0f; player p = get_closest_player_to_tile_x(o.position.x, o.position.y, &dist); - if (dist >= MAX_DISTANCE_BETWEEN_ZOMBIE_AND_PLAYER) + if (dist >= MAX_DISTANCE_BETWEEN_ZOMBIE_AND_PLAYER && p.id != -1) { zombies[i].alive = 0; _current_round.zombies++; @@ -213,7 +213,7 @@ void update_spawners_server() { float dist = 0.0f; player p = get_closest_player_to_tile_x(spawner.position.x, spawner.position.y, &dist); - if (dist >= MAX_DISTANCE_BETWEEN_ZOMBIE_AND_PLAYER) { + if (dist >= MAX_DISTANCE_BETWEEN_ZOMBIE_AND_PLAYER && p.id != -1) { continue; } -- cgit v1.2.3-70-g09d2