extends Area2D
class_name Bot

const SKINS: Array[String] = ["blue", "green", "red", "yellow"]

@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
@onready var base: Area2D = null

@export var speed: float = 42.0

func _ready() -> void:
	base = get_tree().get_first_node_in_group("base")
	if base != null:
		var base_center = get_base_center()
		global_rotation = global_position.angle_to_point(base_center)
	sprite.play(SKINS.pick_random())
	
func get_base_center() -> Vector2:
	return base.get_child(0).global_position

func _physics_process(delta) -> void:
	if base != null:
		global_position = global_position.move_toward(get_base_center(), speed * delta)
