2025-10-28 01:02:15 +00:00
|
|
|
class_name Slimer
|
|
|
|
|
extends Area2D
|
|
|
|
|
|
2025-11-04 01:56:43 +00:00
|
|
|
@onready var right_cast: RayCast2D = $RightCast
|
|
|
|
|
@onready var left_cast: RayCast2D = $LeftCast
|
|
|
|
|
@onready var right_down_cast: RayCast2D = $RightDownCast
|
|
|
|
|
@onready var left_down_cast: RayCast2D = $LeftDownCast
|
2025-11-11 02:17:55 +00:00
|
|
|
@onready var slime_sprite: AnimatedSprite2D = $SlimeSprite
|
2025-11-04 01:56:43 +00:00
|
|
|
|
2025-11-11 02:17:55 +00:00
|
|
|
var speed : int = 25
|
2025-11-04 01:56:43 +00:00
|
|
|
var direction : int = 1
|
|
|
|
|
|
2025-10-28 01:02:15 +00:00
|
|
|
signal player_slimed(body, slime)
|
|
|
|
|
|
2025-11-04 01:56:43 +00:00
|
|
|
func _process(delta: float) -> void:
|
2025-11-11 02:17:55 +00:00
|
|
|
if not right_down_cast.is_colliding():
|
|
|
|
|
direction = -1
|
|
|
|
|
slime_sprite.flip_h = true
|
|
|
|
|
#if not left_down_cast.is_colliding():
|
|
|
|
|
#direction = 1
|
|
|
|
|
#slime_sprite.flip_h = false
|
|
|
|
|
#if not right_cast.is_colliding():
|
|
|
|
|
#direction = -1
|
|
|
|
|
#slime_sprite.flip_h = true
|
|
|
|
|
#if not left_cast.is_colliding():
|
|
|
|
|
#direction = 1
|
|
|
|
|
#slime_sprite.flip_h = false
|
2025-11-04 01:56:43 +00:00
|
|
|
position.x += direction * speed * delta
|
|
|
|
|
|
2025-10-28 01:02:15 +00:00
|
|
|
func _on_body_entered(body: Node2D) -> void:
|
|
|
|
|
if body is Player:
|
|
|
|
|
print_debug("Player hit Slimer")
|
|
|
|
|
player_slimed.emit(body, self)
|