Improvements
This commit is contained in:
@ -5,6 +5,7 @@ signal damaged(amount)
|
||||
signal healed(amount)
|
||||
signal death()
|
||||
|
||||
@export_category("Creature")
|
||||
@export
|
||||
var max_hp: int = 1
|
||||
|
||||
@ -33,6 +34,8 @@ var hp: int :
|
||||
func _ready() -> void:
|
||||
self.hp = self.max_hp
|
||||
self.death.connect(self._creature_on_death)
|
||||
if self.has_method("_on_ready"):
|
||||
self.call("_on_ready")
|
||||
|
||||
func take_damage(damage: int) -> void:
|
||||
self.hp -= damage
|
||||
|
@ -14,6 +14,12 @@ var state: State = State.IDLE
|
||||
@export
|
||||
var animation_player: AnimationPlayer
|
||||
|
||||
@export
|
||||
var sprite: Sprite2D
|
||||
|
||||
@export
|
||||
var detection_area: Area2D
|
||||
|
||||
var _chase_target: Node2D
|
||||
var _target_is_left: bool = false
|
||||
|
||||
@ -29,9 +35,13 @@ func _play_animation(animation: String) -> void:
|
||||
|
||||
animation_player.play(animation)
|
||||
|
||||
func _on_ready() -> void:
|
||||
self.detection_area.body_entered.connect(self._on_detection_area_entered)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var animation_name = str(State.keys()[self.state]).to_lower()
|
||||
self._play_animation(animation_name)
|
||||
sprite.flip_h = self._target_is_left
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
match self.state:
|
||||
@ -39,4 +49,11 @@ func _physics_process(delta: float) -> void:
|
||||
if not self._chase_target:
|
||||
self.state = State.IDLE
|
||||
|
||||
pass
|
||||
self._target_is_left = self._chase_target.position.x < self.position.x
|
||||
|
||||
func _on_detection_area_entered(body: CollisionObject2D) -> void:
|
||||
match state:
|
||||
State.IDLE:
|
||||
if body is Player:
|
||||
self._chase_target = body
|
||||
self.state = State.CHASE
|
||||
|
Reference in New Issue
Block a user