summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/asset_defs.c1
-rw-r--r--src/audio.c12
-rw-r--r--src/zombies.c41
3 files changed, 38 insertions, 16 deletions
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);
+ }
}
}
}