diff options
Diffstat (limited to 'Enemies/walking_enemy.gd')
-rw-r--r-- | Enemies/walking_enemy.gd | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Enemies/walking_enemy.gd b/Enemies/walking_enemy.gd new file mode 100644 index 0000000..be36e2d --- /dev/null +++ b/Enemies/walking_enemy.gd @@ -0,0 +1,40 @@ +extends Enemy + + +@export var acceleration: float = 10.0 + +enum MovementType { + BACK_FORTH, + FORWARD, +} +@export var movement_type: MovementType = MovementType.BACK_FORTH + +@export var back_forth_time: float = 1.0 + + +func _ready() -> void: + super._ready() + + if movement_type == MovementType.BACK_FORTH: + $BackForthTimer.wait_time = back_forth_time + $BackForthTimer.start() + + +func _physics_process(delta: float) -> void: + $AnimatedSprite2D.play() + + if not is_on_floor(): + velocity += get_gravity() * delta + + velocity.x = move_toward(velocity.x, direction * speed, acceleration) + + move_and_slide() + if get_last_slide_collision(): + if $RayLeft.is_colliding(): + direction = 1 + elif $RayRight.is_colliding(): + direction = -1 + + +func _on_back_forth_timer_timeout() -> void: + direction = -direction |