This commit is contained in:
2025-10-29 04:02:47 +01:00
parent 84f75cb2a7
commit 99c606ca5b
33 changed files with 1004 additions and 76 deletions

View File

@@ -20,6 +20,9 @@ func _ready() -> void:
navigation_agent_2d.avoidance_priority = randf_range(0.5, 1.0)
attack_cooldown_offset = randf_range(0.0, 0.5)
animated_sprite.speed_scale = randf_range(0.4, 1.2)
follow_update_timer.one_shot = false
follow_update_timer.autostart = false
func _process(delta: float) -> void:
if flicker_timer > 0.0:
@@ -28,10 +31,24 @@ func _process(delta: float) -> void:
if flicker_timer <= 0.0:
animated_sprite.modulate = Color(1, 1, 1)
func _physics_process(delta: float) -> void:
if !idle and target:
if navigation_agent_2d.is_navigation_finished():
velocity = Vector2.ZERO
else:
var next_pos: Vector2 = navigation_agent_2d.get_next_path_position()
var direction: Vector2 = (next_pos - global_position).normalized()
velocity = direction * speed * delta
else:
velocity = Vector2.ZERO
move_and_slide()
func _on_area_body_entered(body: Node2D) -> void:
if body is Player:
idle = false
target = body
navigation_agent_2d.target_position = target.global_position
follow_update_timer.start()
animated_sprite.play()
@@ -53,30 +70,12 @@ func _on_attack_area_body_exited(body: Node2D) -> void:
in_attack_range = false
attack_timer.stop()
func _physics_process(delta: float) -> void:
if !idle && target:
if !navigation_agent_2d.is_navigation_finished():
var next_path_pos: Vector2 = navigation_agent_2d.get_next_path_position()
var direction: Vector2 = (next_path_pos - global_position).normalized()
var desired_velocity: Vector2 = direction * speed * delta
navigation_agent_2d.set_velocity(desired_velocity)
else:
velocity = Vector2.ZERO
move_and_slide()
else:
velocity = Vector2.ZERO
move_and_slide()
func _on_follow_update_timer_timeout() -> void:
if target && !idle:
if target and !idle:
navigation_agent_2d.target_position = target.global_position
func _on_navigation_agent2d_velocity_computed(safe_velocity: Vector2) -> void:
velocity = safe_velocity
move_and_slide()
func _on_attack_timer_timeout() -> void:
if target && in_attack_range:
if target and in_attack_range:
target.health -= DAMAGE
func _on_fightable_fought(player: Player) -> void: