GodotGame/scripts/badguy.gd

41 lines
1.0 KiB
GDScript3
Raw Permalink Normal View History

2024-08-20 01:07:42 +00:00
class_name BadGuy extends Area2D
2024-08-13 01:01:40 +00:00
@export var speed = 60.0
var direction = 1
2024-08-20 01:07:42 +00:00
@onready var sprite = $AnimatedSprite2D
2024-08-13 01:01:40 +00:00
@onready var right_cast = $RightCast
@onready var left_cast = $LeftCast
@onready var right_floor_cast = $RightFloorCast
@onready var left_floor_cast = $LeftFloorCast
2024-08-20 01:07:42 +00:00
signal playerDamage
2024-08-13 01:01:40 +00:00
# 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):
if right_cast.is_colliding():
if not right_cast.get_collider().is_in_group("player"):
direction = -1
if left_cast.is_colliding():
if not left_cast.get_collider().is_in_group("player"):
direction = 1
if not right_floor_cast.is_colliding():
direction = -1
if not left_floor_cast.is_colliding():
direction = 1
if direction == -1:
sprite.flip_h = true
else:
sprite.flip_h = false
#movement
position.x += direction * speed * delta
func _on_body_entered(body):
if body.is_in_group("player"):
2024-08-20 01:07:42 +00:00
playerDamage.emit()