Mag gen & work towards AI
This commit is contained in:
42
scripts/v2/enemy.gd
Normal file
42
scripts/v2/enemy.gd
Normal file
@@ -0,0 +1,42 @@
|
||||
class_name Enemy
|
||||
extends Creature
|
||||
|
||||
enum State {
|
||||
IDLE,
|
||||
CHASE,
|
||||
ATTACK
|
||||
}
|
||||
|
||||
@export
|
||||
var state: State = State.IDLE
|
||||
|
||||
@export_category("Parts")
|
||||
@export
|
||||
var animation_player: AnimationPlayer
|
||||
|
||||
var _chase_target: Node2D
|
||||
var _target_is_left: bool = false
|
||||
|
||||
func _play_animation(animation: String) -> void:
|
||||
if not animation_player:
|
||||
return
|
||||
|
||||
if not animation_player.has_animation(animation):
|
||||
return
|
||||
|
||||
if animation_player.is_playing() and animation_player.current_animation == animation:
|
||||
return
|
||||
|
||||
animation_player.play(animation)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var animation_name = str(State.keys()[self.state]).to_lower()
|
||||
self._play_animation(animation_name)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
match self.state:
|
||||
State.CHASE:
|
||||
if not self._chase_target:
|
||||
self.state = State.IDLE
|
||||
|
||||
pass
|
||||
Reference in New Issue
Block a user