testytest/scripts/badguy.gd

41 lines
1.0 KiB
GDScript3
Raw Normal View History

2024-08-13 01:10:22 +00:00
extends Area2D
const speed = 60
var direction = 1
@onready var right_cast = $RightCast
@onready var left_cast = $LeftCast
@onready var right_floor_cast = $rightFloorCast
@onready var left_floor_cast = $leftFloorCast
@onready var sprite = $AnimatedSprite2D
@onready var game = %GameController
# 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
sprite.flip_h = true
if left_cast.is_colliding():
if not left_cast.get_collider().is_in_group("player"):
direction = 1
sprite.flip_h = false
if not right_floor_cast.is_colliding():
direction = -1
sprite.flip_h = true
if not left_floor_cast.is_colliding():
direction = 1
sprite.flip_h = false
#move the dude
position.x += direction * speed * delta
func _on_body_entered(body):
if body.is_in_group("player"):
game.playerDeath()