Various bug fixes.
This commit is contained in:
+8
-14
@@ -10,9 +10,7 @@ class Bandit {
|
||||
string weapon_type; // "spear" or "axe"
|
||||
int sound_handle;
|
||||
timer move_timer;
|
||||
timer alert_timer;
|
||||
timer attack_timer;
|
||||
int next_alert_delay;
|
||||
int move_interval;
|
||||
|
||||
// Wandering behavior properties
|
||||
@@ -38,9 +36,7 @@ class Bandit {
|
||||
move_interval = random(BANDIT_MOVE_INTERVAL_MIN, BANDIT_MOVE_INTERVAL_MAX);
|
||||
|
||||
move_timer.restart();
|
||||
alert_timer.restart();
|
||||
attack_timer.restart();
|
||||
next_alert_delay = random(BANDIT_ALERT_MIN_DELAY, BANDIT_ALERT_MAX_DELAY);
|
||||
|
||||
// Initialize wandering behavior (start aggressive during invasion)
|
||||
behavior_state = "aggressive";
|
||||
@@ -87,7 +83,8 @@ void spawn_bandit(int expansion_start, int expansion_end) {
|
||||
|
||||
Bandit@ b = Bandit(spawn_x, expansion_start, expansion_end);
|
||||
bandits.insert_last(b);
|
||||
b.sound_handle = play_creature_voice(b.alert_sound, x, spawn_x, BANDIT_SOUND_VOLUME_STEP);
|
||||
// Play looping sound that follows the bandit
|
||||
b.sound_handle = play_1d_with_volume_step(b.alert_sound, x, spawn_x, true, BANDIT_SOUND_VOLUME_STEP);
|
||||
}
|
||||
|
||||
bool can_bandit_attack_player(Bandit@ bandit) {
|
||||
@@ -177,18 +174,15 @@ void try_attack_barricade_bandit(Bandit@ bandit) {
|
||||
}
|
||||
|
||||
void update_bandit(Bandit@ bandit) {
|
||||
// Play alert sound at intervals
|
||||
if (bandit.alert_timer.elapsed > bandit.next_alert_delay) {
|
||||
bandit.alert_timer.restart();
|
||||
bandit.next_alert_delay = random(BANDIT_ALERT_MIN_DELAY, BANDIT_ALERT_MAX_DELAY);
|
||||
|
||||
// Destroy old sound handle before playing new one to prevent overlapping
|
||||
// Update looping sound position
|
||||
if (bandit.sound_handle != -1 && p.sound_is_active(bandit.sound_handle)) {
|
||||
p.update_sound_1d(bandit.sound_handle, bandit.position);
|
||||
} else if (bandit.sound_handle == -1 || !p.sound_is_active(bandit.sound_handle)) {
|
||||
// Restart looping sound if it stopped
|
||||
if (bandit.sound_handle != -1) {
|
||||
p.destroy_sound(bandit.sound_handle);
|
||||
bandit.sound_handle = -1;
|
||||
}
|
||||
|
||||
bandit.sound_handle = play_creature_voice(bandit.alert_sound, x, bandit.position, BANDIT_SOUND_VOLUME_STEP);
|
||||
bandit.sound_handle = play_1d_with_volume_step(bandit.alert_sound, x, bandit.position, true, BANDIT_SOUND_VOLUME_STEP);
|
||||
}
|
||||
|
||||
if (try_attack_player_bandit(bandit)) {
|
||||
|
||||
@@ -38,10 +38,8 @@ class FlyingCreature {
|
||||
int sound_handle;
|
||||
int fall_sound_handle;
|
||||
timer move_timer;
|
||||
timer sound_timer;
|
||||
timer fall_timer;
|
||||
int next_move_delay;
|
||||
int next_sound_delay;
|
||||
string voice_sound;
|
||||
bool fading_out;
|
||||
bool ready_to_remove;
|
||||
@@ -63,10 +61,8 @@ class FlyingCreature {
|
||||
}
|
||||
|
||||
move_timer.restart();
|
||||
sound_timer.restart();
|
||||
|
||||
next_move_delay = random(cfg.move_interval_min, cfg.move_interval_max);
|
||||
next_sound_delay = random(cfg.sound_delay_min, cfg.sound_delay_max);
|
||||
fading_out = false;
|
||||
ready_to_remove = false;
|
||||
}
|
||||
@@ -229,7 +225,8 @@ bool spawn_flying_creature(string creature_type) {
|
||||
|
||||
FlyingCreature@ c = FlyingCreature(creature_type, spawn_x, area_start, area_end, cfg);
|
||||
flying_creatures.insert_last(c);
|
||||
c.sound_handle = play_creature_voice(c.voice_sound, x, spawn_x, cfg.sound_volume_step);
|
||||
// Play looping sound that follows the flying creature
|
||||
c.sound_handle = play_1d_with_volume_step(c.voice_sound, x, spawn_x, true, cfg.sound_volume_step);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -267,10 +264,15 @@ void update_flying_creature(FlyingCreature@ creature) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (creature.sound_timer.elapsed > creature.next_sound_delay) {
|
||||
creature.sound_timer.restart();
|
||||
creature.next_sound_delay = random(cfg.sound_delay_min, cfg.sound_delay_max);
|
||||
creature.sound_handle = play_creature_voice(creature.voice_sound, x, creature.position, cfg.sound_volume_step);
|
||||
// Update looping sound position
|
||||
if (creature.sound_handle != -1 && p.sound_is_active(creature.sound_handle)) {
|
||||
p.update_sound_1d(creature.sound_handle, creature.position);
|
||||
} else if (creature.sound_handle == -1 || !p.sound_is_active(creature.sound_handle)) {
|
||||
// Restart looping sound if it stopped
|
||||
if (creature.sound_handle != -1) {
|
||||
p.destroy_sound(creature.sound_handle);
|
||||
}
|
||||
creature.sound_handle = play_1d_with_volume_step(creature.voice_sound, x, creature.position, true, cfg.sound_volume_step);
|
||||
}
|
||||
|
||||
if (cfg.fly_away_chance > 0 && random(1, 1000) <= cfg.fly_away_chance) {
|
||||
|
||||
@@ -8,10 +8,8 @@ class GroundGame {
|
||||
int health;
|
||||
int sound_handle;
|
||||
timer move_timer;
|
||||
timer sound_timer;
|
||||
timer attack_timer;
|
||||
int next_move_delay;
|
||||
int next_sound_delay;
|
||||
string voice_sound;
|
||||
string state; // "wandering" or "charging"
|
||||
int area_start;
|
||||
@@ -32,11 +30,9 @@ class GroundGame {
|
||||
voice_sound = ground_game_boar_sounds[random(0, ground_game_boar_sounds.length() - 1)];
|
||||
|
||||
move_timer.restart();
|
||||
sound_timer.restart();
|
||||
attack_timer.restart();
|
||||
|
||||
next_move_delay = random(BOAR_MOVE_INTERVAL_MIN, BOAR_MOVE_INTERVAL_MAX);
|
||||
next_sound_delay = random(BOAR_SOUND_MIN_DELAY, BOAR_SOUND_MAX_DELAY);
|
||||
}
|
||||
}
|
||||
GroundGame@[] ground_games;
|
||||
@@ -80,7 +76,8 @@ void spawn_ground_game(int expansion_start, int expansion_end) {
|
||||
|
||||
GroundGame@ b = GroundGame(spawn_x, expansion_start, expansion_end, "boar");
|
||||
ground_games.insert_last(b);
|
||||
b.sound_handle = play_creature_voice(b.voice_sound, x, spawn_x, BOAR_SOUND_VOLUME_STEP);
|
||||
// Play looping sound that follows the boar
|
||||
b.sound_handle = play_1d_with_volume_step(b.voice_sound, x, spawn_x, true, BOAR_SOUND_VOLUME_STEP);
|
||||
}
|
||||
|
||||
bool can_ground_game_attack_player(GroundGame@ game) {
|
||||
@@ -113,12 +110,15 @@ bool try_attack_player_ground_game(GroundGame@ game) {
|
||||
}
|
||||
|
||||
void update_ground_game(GroundGame@ game) {
|
||||
// Sound logic
|
||||
if (game.sound_timer.elapsed > game.next_sound_delay) {
|
||||
game.sound_timer.restart();
|
||||
game.next_sound_delay = random(BOAR_SOUND_MIN_DELAY, BOAR_SOUND_MAX_DELAY);
|
||||
// Only play if wandering or occasionally while charging
|
||||
game.sound_handle = play_creature_voice(game.voice_sound, x, game.position, BOAR_SOUND_VOLUME_STEP);
|
||||
// Update looping sound position
|
||||
if (game.sound_handle != -1 && p.sound_is_active(game.sound_handle)) {
|
||||
p.update_sound_1d(game.sound_handle, game.position);
|
||||
} else if (game.sound_handle == -1 || !p.sound_is_active(game.sound_handle)) {
|
||||
// Restart looping sound if it stopped for some reason
|
||||
if (game.sound_handle != -1) {
|
||||
p.destroy_sound(game.sound_handle);
|
||||
}
|
||||
game.sound_handle = play_1d_with_volume_step(game.voice_sound, x, game.position, true, BOAR_SOUND_VOLUME_STEP);
|
||||
}
|
||||
|
||||
// Combat logic
|
||||
|
||||
+8
-13
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user