SeptemberGame/scripts/slime.gd

43 lines
1.1 KiB
GDScript

class_name Slime extends Area2D
@onready var right_cast = $RightCast
@onready var left_cast = $LeftCast
@onready var right_down_cast = $RightDownCast
@onready var left_down_cast = $LeftDownCast
@onready var slime_graphic = $SlimeGraphic
var speed:int = 100
var direction = 1
signal slimeDamageSignal(body, slime)
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
#raycast detection
if not right_down_cast.is_colliding():
direction = -1
slime_graphic.flip_h = true
if not left_down_cast.is_colliding():
direction = 1
slime_graphic.flip_h = false
if right_cast.is_colliding() && not right_cast.get_collider() is Player:
direction = -1
slime_graphic.flip_h = true
if left_cast.is_colliding() && not left_cast.get_collider() is Player:
direction = 1
slime_graphic.flip_h = false
position.x += direction * speed * delta
func _on_body_entered(body):
print("slime detects body")
if body is Player:
slimeDamageSignal.emit(body, self)