From 1f3e6604cf2df6ae11944f99f939b8b697ebd4d9 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sat, 6 Jan 2024 18:05:03 +0100 Subject: enraged zombie footseps --- data/sounds/step_enraged.wav | Bin 0 -> 133136 bytes include/asset_defs.h | 1 + include/zombies.h | 1 + notes | 3 +-- src/asset_defs.c | 1 + src/audio.c | 12 +++++++++++- src/zombies.c | 41 ++++++++++++++++++++++++++--------------- 7 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 data/sounds/step_enraged.wav diff --git a/data/sounds/step_enraged.wav b/data/sounds/step_enraged.wav new file mode 100644 index 0000000..48e2ef5 Binary files /dev/null and b/data/sounds/step_enraged.wav differ diff --git a/include/asset_defs.h b/include/asset_defs.h index a71df08..467837e 100644 --- a/include/asset_defs.h +++ b/include/asset_defs.h @@ -98,6 +98,7 @@ Mix_Chunk* wav_character; Mix_Chunk* wav_roar_enraged; Mix_Chunk* wav_round_change; Mix_Chunk* wav_step; +Mix_Chunk* wav_step_enraged; #define NUM_SCREECHES 11 Mix_Chunk* wav_screech[NUM_SCREECHES]; diff --git a/include/zombies.h b/include/zombies.h index e5f8753..b7c7889 100644 --- a/include/zombies.h +++ b/include/zombies.h @@ -22,6 +22,7 @@ typedef struct t_zombie { vec3f size; array path; float speed; + float sec_since_last_step; array next_path; float time_since_last_path; pathfinding_request request; diff --git a/notes b/notes index cc8f4be..3b8d95d 100644 --- a/notes +++ b/notes @@ -1,3 +1,2 @@ - monster aanval -> screen flash (rode randen) -- voetsteppen voor grote monster -- spawn geluid voor grote monster \ No newline at end of file +- voetsteppen voor grote monster \ No newline at end of file diff --git a/src/asset_defs.c b/src/asset_defs.c index ac1a5bc..33e6d37 100644 --- a/src/asset_defs.c +++ b/src/asset_defs.c @@ -95,6 +95,7 @@ void load_assets() { wav_round_change = Mix_LoadWAV("data/sounds/round_change.wav"); wav_character = Mix_LoadWAV("data/sounds/character.wav"); wav_step = Mix_LoadWAV("data/sounds/step.wav"); + wav_step_enraged = Mix_LoadWAV("data/sounds/step_enraged.wav"); wav_roar_enraged = Mix_LoadWAV("data/sounds/roar_enraged.wav"); for (int i = 1; i <= NUM_SCREECHES; i++) { diff --git a/src/audio.c b/src/audio.c index 2e9b122..1f88d17 100644 --- a/src/audio.c +++ b/src/audio.c @@ -51,7 +51,17 @@ static Mix_Chunk* get_sample_from_audio_event(audio_event event, u32 playerid) { switch (event.type) { - case EVENT_FOOTSTEP: return wav_step; + case EVENT_FOOTSTEP: { + if (event.zombie != ZOMBIE_TYPE_NONE) { + switch(event.zombie) { + case ZOMBIE_TYPE_ENRAGED: return wav_step_enraged; + default: return wav_error; + } + } + else { + return wav_step; + } + } case EVENT_CHARACTER_TYPE: return wav_character; case EVENT_ROUND_CHANGE: return wav_round_change; case EVENT_COLLECT: return wav_collect; diff --git a/src/zombies.c b/src/zombies.c index 60b2c52..8178f4f 100644 --- a/src/zombies.c +++ b/src/zombies.c @@ -114,6 +114,7 @@ void spawn_zombie(int x, int y) { zombies[i].alive = true; zombies[i].type = (normal_zombie_spawn_counter % 5 == 0) ? ZOMBIE_TYPE_ENRAGED : ZOMBIE_TYPE_NORMAL; zombies[i].position = (vec3f){x,y, 0}; + zombies[i].sec_since_last_step = 0.0f; switch(zombies[i].type) { case ZOMBIE_TYPE_NORMAL: set_normal_zombie_stats(&zombies[i]); break; case ZOMBIE_TYPE_ENRAGED: set_enraged_zombie_stats(&zombies[i]); break; @@ -280,6 +281,13 @@ void update_zombies_server(platform_window* window) { update_sprite(&zombies[i].sprite_run); + if (zombies[i].type == ZOMBIE_TYPE_ENRAGED && zombies[i].sec_since_last_step > 0.2f) { + add_zombie_audio_event_to_queue(EVENT_FOOTSTEP, o.type, o.position); + zombies[i].sec_since_last_step = 0.0f; + } + zombies[i].sec_since_last_step += SERVER_TICK_RATE; + + // Update pathfinding zombies[i].time_since_last_path += SERVER_TICK_RATE; if (zombies[i].time_since_last_path > SERVER_PATHFINDING_INTERVAL) { player closest_player = get_closest_player_to_tile((int)o.position.x, (int)o.position.y); @@ -313,21 +321,24 @@ void update_zombies_server(platform_window* window) { array_remove_at(&zombies[i].path, zombies[i].path.length-1); } - float speed = zombies[i].speed * SERVER_TICK_RATE; - vec2f dir = get_direction_to_next_tile(o); - float height = get_height_of_tile_under_coords(zombies[i].position.x, zombies[i].position.y); - zombies[i].position.x += dir.x*speed; - zombies[i].position.y += dir.y*speed; - zombies[i].position.z = height; - zombies[i].dir = dir; - - zombies[i].next2tiles[0] = (vec2f){-1,-1}; - zombies[i].next2tiles[1] = (vec2f){-1,-1}; - if (o.path.length > 0) { - zombies[i].next2tiles[0] = *(vec2f*)array_at(&o.path, o.path.length-1); - zombies[i].next2tiles[1] = zombies[i].next2tiles[0]; - if (o.path.length > 1) { - zombies[i].next2tiles[1] = *(vec2f*)array_at(&o.path, o.path.length-2); + // Update position + { + float speed = zombies[i].speed * SERVER_TICK_RATE; + vec2f dir = get_direction_to_next_tile(o); + float height = get_height_of_tile_under_coords(zombies[i].position.x, zombies[i].position.y); + zombies[i].position.x += dir.x*speed; + zombies[i].position.y += dir.y*speed; + zombies[i].position.z = height; + zombies[i].dir = dir; + + zombies[i].next2tiles[0] = (vec2f){-1,-1}; + zombies[i].next2tiles[1] = (vec2f){-1,-1}; + if (o.path.length > 0) { + zombies[i].next2tiles[0] = *(vec2f*)array_at(&o.path, o.path.length-1); + zombies[i].next2tiles[1] = zombies[i].next2tiles[0]; + if (o.path.length > 1) { + zombies[i].next2tiles[1] = *(vec2f*)array_at(&o.path, o.path.length-2); + } } } } -- cgit v1.2.3-70-g09d2