33 lines
932 B
GDScript3
33 lines
932 B
GDScript3
|
|
class_name slime extends Area2D
|
||
|
|
|
||
|
|
@onready var slime_texture: AnimatedSprite2D = $"slime texture"
|
||
|
|
@onready var leftdowncast: RayCast2D = $leftdowncast
|
||
|
|
@onready var rightcast: RayCast2D = $rightcast
|
||
|
|
@onready var rightdowncast: RayCast2D = $rightdowncast
|
||
|
|
@onready var leftcast: RayCast2D = $leftcast
|
||
|
|
|
||
|
|
signal slimedamagesignal(body, slime)
|
||
|
|
|
||
|
|
var speed: int = 100
|
||
|
|
var direction = 1
|
||
|
|
|
||
|
|
func _process(delta: float) -> void:
|
||
|
|
position.x += direction*speed*delta
|
||
|
|
if rightcast.is_colliding() and not rightcast.get_collider() is Player:
|
||
|
|
direction=-1
|
||
|
|
if leftcast.is_colliding() and not leftcast.get_collider() is Player:
|
||
|
|
direction=1
|
||
|
|
slime_texture.flip_h = false
|
||
|
|
if not rightdowncast.is_colliding():
|
||
|
|
direction = -1
|
||
|
|
|
||
|
|
if not leftdowncast.is_colliding():
|
||
|
|
direction = 1
|
||
|
|
|
||
|
|
|
||
|
|
func _on_body_entered(body: Node2D) -> void:
|
||
|
|
print("player damage at slime")
|
||
|
|
if body is Player:
|
||
|
|
print("slime see player")
|
||
|
|
slimedamagesignal.emit(body, self)
|