started working on fog darkness
This commit is contained in:
@@ -12,6 +12,11 @@ var detection_range: float = 80.0 # Range to detect players (much smaller)
|
||||
|
||||
var fly_height: float = 8.0 # Z position when flying
|
||||
|
||||
# Audio
|
||||
@onready var bat_flap_sfx: AudioStreamPlayer2D = $BatFlapSfx
|
||||
@onready var bat_chirp_sfx: AudioStreamPlayer2D = $BatChirpSfx
|
||||
var has_played_chase_sound: bool = false # Track if we've played sound when starting to chase
|
||||
|
||||
func _ready():
|
||||
super._ready()
|
||||
|
||||
@@ -80,9 +85,15 @@ func _idle_behavior(_delta):
|
||||
if target_player:
|
||||
var dist = global_position.distance_to(target_player.global_position)
|
||||
if dist < detection_range:
|
||||
# Start flying
|
||||
# Start flying (chasing player)
|
||||
var was_idle = (state == BatState.IDLE)
|
||||
state = BatState.FLYING
|
||||
state_timer = fly_duration
|
||||
|
||||
# Play sound very seldom when starting to chase (only once per bat, with low chance)
|
||||
if was_idle and not has_played_chase_sound and randf() < 0.15: # 15% chance
|
||||
_play_chase_sound()
|
||||
has_played_chase_sound = true
|
||||
return
|
||||
|
||||
# Switch to flying after idle duration
|
||||
@@ -177,3 +188,16 @@ func _play_death_animation():
|
||||
|
||||
await fade_tween.finished
|
||||
queue_free()
|
||||
|
||||
func _play_chase_sound():
|
||||
# Play a random bat sound when starting to chase (very seldom)
|
||||
if not bat_flap_sfx and not bat_chirp_sfx:
|
||||
return
|
||||
|
||||
# Randomly choose between flap or chirp
|
||||
if randf() < 0.5:
|
||||
if bat_flap_sfx and bat_flap_sfx.stream:
|
||||
bat_flap_sfx.play()
|
||||
else:
|
||||
if bat_chirp_sfx and bat_chirp_sfx.stream:
|
||||
bat_chirp_sfx.play()
|
||||
|
||||
Reference in New Issue
Block a user