DariusGodotGame/dariusgodotproject/scripts/badguy.gd

28 lines
792 B
GDScript

class_name BadGuy extends Area2D
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
@onready var right_ray: RayCast2D = $RightRay
@onready var left_ray: RayCast2D = $LeftRay
@onready var right_floor_ray: RayCast2D = $RightFloorRay
@onready var left_floor_ray: RayCast2D = $LeftFloorRay
const speed = 60
var direction = 1
#signals
signal playerDamage
func _process(delta: float) -> void:
if not right_floor_ray.is_colliding():
#about to fall on the right...
direction = -1
sprite.flip_h = true
if not left_floor_ray.is_colliding():
#about to fall on the left...
direction = 1
sprite.flip_h = false
position.x += direction * speed * delta
func _on_body_entered(body: Node2D) -> void:
if body.is_in_group("player"):
print("Bad Guy Collided")
playerDamage.emit()