2023-11-11 19:03:01 +11:00
|
|
|
extends CharacterBody3D
|
2023-11-08 14:28:55 +11:00
|
|
|
class_name EnemyController
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
signal reached_goal(enemy: Enemy, penalty: int)
|
|
|
|
signal died(enemy: Enemy)
|
2023-11-08 14:28:55 +11:00
|
|
|
|
2023-12-10 12:05:41 +11:00
|
|
|
@export var stats: Enemy
|
|
|
|
@export var status_manager: StatusEffector
|
|
|
|
@export var movement_controller: EnemyMovement
|
|
|
|
@export var health: Health
|
|
|
|
@export var sprite: Sprite3D
|
|
|
|
@export var corpse_scene: PackedScene
|
|
|
|
|
|
|
|
var movement_speed: float
|
2024-02-22 06:22:22 +11:00
|
|
|
var movement_speed_penalty: float = 1.0
|
|
|
|
var alive: bool = true
|
2023-11-11 19:03:01 +11:00
|
|
|
|
2023-11-08 14:28:55 +11:00
|
|
|
|
|
|
|
func _ready() -> void:
|
2023-11-11 19:03:01 +11:00
|
|
|
health.max_health = stats.health
|
|
|
|
health.current_health = stats.health
|
2023-12-10 12:05:41 +11:00
|
|
|
$SubViewport/HealthBar.setup(stats.health)
|
2023-11-15 15:19:40 +11:00
|
|
|
sprite.texture = stats.sprite.duplicate()
|
2023-11-08 14:28:55 +11:00
|
|
|
movement_speed = stats.movement_speed
|
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func damage(amount: float) -> void:
|
2023-11-11 19:03:01 +11:00
|
|
|
$Hitbox.damage(amount)
|
2023-11-08 14:28:55 +11:00
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func goal_entered() -> void:
|
2023-11-11 19:03:01 +11:00
|
|
|
if alive:
|
|
|
|
alive = false
|
2023-11-09 17:56:08 +11:00
|
|
|
reached_goal.emit(stats, stats.penalty)
|
2023-11-08 14:28:55 +11:00
|
|
|
queue_free()
|
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func die() -> void:
|
2023-11-08 14:28:55 +11:00
|
|
|
if alive:
|
|
|
|
alive = false
|
2023-11-11 19:03:01 +11:00
|
|
|
died.emit(stats)
|
2024-02-22 06:22:22 +11:00
|
|
|
var corpse: RigidBody3D = corpse_scene.instantiate()
|
2023-12-10 12:05:41 +11:00
|
|
|
corpse.set_sprite(stats.death_sprite)
|
|
|
|
corpse.position = global_position
|
|
|
|
Game.level.corpses.add_child(corpse)
|
2023-11-11 19:03:01 +11:00
|
|
|
queue_free()
|