add enemy slime

This commit is contained in:
2025-10-21 11:31:32 +01:00
parent 79bd77220f
commit deec0fb581
4 changed files with 109 additions and 16 deletions

21
scripts/slime.gd Normal file
View File

@@ -0,0 +1,21 @@
extends Node2D
@export var speed = 60
var direction = 1
@onready var ray_cast_right: RayCast2D = $RayCastRight
@onready var ray_cast_left: RayCast2D = $RayCastLeft
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if ray_cast_right.is_colliding():
direction = -1
animated_sprite.flip_h = true
if ray_cast_left.is_colliding():
direction = 1
animated_sprite.flip_h = false
position.x += direction * speed * delta