This commit is contained in:
Marek Lenczewski
2026-04-02 16:02:24 +02:00
parent e76c66eda6
commit 47f4fe3d90
106 changed files with 434 additions and 204 deletions

36
enemy/enemy.gd Normal file
View File

@@ -0,0 +1,36 @@
extends CharacterBody3D
enum State { IDLE, CHASE, ATTACK, RETURN }
@export var stats: BaseStats
var state: int = State.IDLE
var target: Node3D = null
var spawn_position: Vector3
var portal: Node3D = null
var gravity: float = ProjectSettings.get_setting("physics/3d/default_gravity")
func _ready() -> void:
spawn_position = global_position
add_to_group("enemies")
Stats.register(self, stats)
EventBus.entity_died.connect(_on_entity_died)
func _exit_tree() -> void:
Stats.deregister(self)
func _on_entity_died(entity: Node) -> void:
if entity == self:
queue_free()
func _physics_process(delta: float) -> void:
if not is_on_floor():
velocity.y -= gravity * delta
move_and_slide()
func _on_detection_area_body_entered(body: Node3D) -> void:
if body is CharacterBody3D and body.name == "Player":
EventBus.enemy_detected.emit(self, body)
func _on_detection_area_body_exited(_body: Node3D) -> void:
pass