42 lines
1007 B
GDScript3
42 lines
1007 B
GDScript3
|
|
class_name Slime extends Area2D
|
||
|
|
|
||
|
|
@onready var animated_sprite_2d = $AnimatedSprite2D
|
||
|
|
@onready var left_cast = $LeftCast
|
||
|
|
@onready var right_cast = $RightCast
|
||
|
|
@onready var left_down_cast = $LeftDownCast
|
||
|
|
@onready var right_down_cast = $RightDownCast
|
||
|
|
|
||
|
|
signal slime_damage(body, slime)
|
||
|
|
signal slime_struck(body, slime)
|
||
|
|
|
||
|
|
var speed:int = 100
|
||
|
|
var direction = 1
|
||
|
|
|
||
|
|
func _ready():
|
||
|
|
pass
|
||
|
|
|
||
|
|
func turn_right():
|
||
|
|
direction = 1
|
||
|
|
animated_sprite_2d.flip_h = false
|
||
|
|
|
||
|
|
func turn_left():
|
||
|
|
direction = -1
|
||
|
|
animated_sprite_2d.flip_h = true
|
||
|
|
|
||
|
|
func _process(delta: float):
|
||
|
|
if right_cast.is_colliding() and not right_cast.get_collider() is Player:
|
||
|
|
turn_left()
|
||
|
|
elif left_cast.is_colliding() and not left_cast.get_collider() is Player:
|
||
|
|
turn_right()
|
||
|
|
if not right_down_cast.is_colliding():
|
||
|
|
turn_left()
|
||
|
|
elif not left_down_cast.is_colliding():
|
||
|
|
turn_right()
|
||
|
|
position.x += direction*speed*delta
|
||
|
|
|
||
|
|
func _on_body_entered(body):
|
||
|
|
if body is Player:
|
||
|
|
slime_damage.emit(body, self)
|
||
|
|
if body is Grenade:
|
||
|
|
slime_struck.emit(body, self)
|