2024-08-12 19:19:54 +00:00
|
|
|
extends Area2D
|
|
|
|
|
|
|
|
const speed = 60
|
|
|
|
var direction = 1
|
|
|
|
@onready var cast_right = $CastRight
|
|
|
|
@onready var cast_left = $CastLeft
|
|
|
|
@onready var sprite = $AnimatedSprite2D
|
2024-08-12 19:32:24 +00:00
|
|
|
@onready var game = %GameManager
|
|
|
|
|
2024-08-12 19:19:54 +00:00
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
func _process(delta):
|
|
|
|
if cast_right.is_colliding():
|
|
|
|
direction = -1
|
|
|
|
sprite.flip_h = true
|
|
|
|
if cast_left.is_colliding():
|
|
|
|
direction = 1
|
|
|
|
sprite.flip_h = false
|
|
|
|
|
|
|
|
position.x += direction * speed * delta
|
|
|
|
|
|
|
|
|
|
|
|
func _on_body_entered(body):
|
|
|
|
if body.is_in_group("player"):
|
|
|
|
game.playerDeath()
|