Make slime killable

This commit is contained in:
ItsDrike 2025-03-03 22:57:23 +01:00
parent 0f056ccfd7
commit 1945726bd1
Signed by: ItsDrike
GPG key ID: FA2745890B7048C0
3 changed files with 92 additions and 50 deletions

View file

@ -4,12 +4,27 @@ extends Node2D
@onready var ray_cast_right: RayCast2D = $RayCastRight
@onready var ray_cast_left: RayCast2D = $RayCastLeft
@onready var ray_cast_top_left: RayCast2D = $RayCastTopLeft
@onready var ray_cast_top_right: RayCast2D = $RayCastTopRight
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
var direction = 1
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if direction == 1 and animated_sprite.flip_h == false:
animated_sprite.flip_h = true
if direction == -1 and animated_sprite.flip_h == true:
animated_sprite.flip_h = false
func _physics_process(delta: float) -> void:
move(delta)
if ray_cast_top_left.is_colliding() or ray_cast_top_right.is_colliding():
queue_free()
func move(delta: float) -> void:
"""Keep moving from left to right, changing direction when near something."""
if direction == 1 and ray_cast_right.is_colliding():
direction = -1
animated_sprite.flip_h = true