Various bug fixes.

This commit is contained in:
Storm Dragon
2026-01-22 23:30:36 -05:00
parent 35e192cb21
commit 9ded17873d
14 changed files with 357 additions and 93 deletions

View File

@@ -10,9 +10,7 @@ class Undead {
string voice_sound;
int sound_handle;
timer move_timer;
timer groan_timer;
timer attack_timer;
int next_groan_delay;
Undead(int pos, string type = "zombie") {
position = pos;
@@ -22,9 +20,7 @@ class Undead {
voice_sound = undead_zombie_sounds[sound_index];
sound_handle = -1;
move_timer.restart();
groan_timer.restart();
attack_timer.restart();
next_groan_delay = random(ZOMBIE_GROAN_MIN_DELAY, ZOMBIE_GROAN_MAX_DELAY);
}
}
Undead@[] undeads;
@@ -65,7 +61,8 @@ void spawn_undead() {
Undead@ z = Undead(spawn_x, "zombie");
undeads.insert_last(z);
z.sound_handle = play_creature_voice(z.voice_sound, x, spawn_x, ZOMBIE_SOUND_VOLUME_STEP);
// Play looping sound that follows the zombie
z.sound_handle = play_1d_with_volume_step(z.voice_sound, x, spawn_x, true, ZOMBIE_SOUND_VOLUME_STEP);
}
void try_attack_barricade_undead(Undead@ undead) {
@@ -131,17 +128,15 @@ bool try_attack_player_undead(Undead@ undead) {
}
void update_undead(Undead@ undead) {
if (undead.groan_timer.elapsed > undead.next_groan_delay) {
undead.groan_timer.restart();
undead.next_groan_delay = random(ZOMBIE_GROAN_MIN_DELAY, ZOMBIE_GROAN_MAX_DELAY);
// Destroy old sound handle before playing new one to prevent overlapping
// Update looping sound position
if (undead.sound_handle != -1 && p.sound_is_active(undead.sound_handle)) {
p.update_sound_1d(undead.sound_handle, undead.position);
} else if (undead.sound_handle == -1 || !p.sound_is_active(undead.sound_handle)) {
// Restart looping sound if it stopped for some reason
if (undead.sound_handle != -1) {
p.destroy_sound(undead.sound_handle);
undead.sound_handle = -1;
}
undead.sound_handle = play_creature_voice(undead.voice_sound, x, undead.position, ZOMBIE_SOUND_VOLUME_STEP);
undead.sound_handle = play_1d_with_volume_step(undead.voice_sound, x, undead.position, true, ZOMBIE_SOUND_VOLUME_STEP);
}
if (try_attack_player_undead(undead)) {