extends CharacterBody2D @export var speed: int = 5 @export var min_radius: int = 5 @export var max_radius: int = 25 @export var mode_duration: float = 4.0 var follows_player: bool = false @onready var radius: float = float(min_radius) enum MovementMode { EXPAND, SHRINK, } var movement_mode: MovementMode = MovementMode.SHRINK var flowers: Array = [] func _ready(): $Timer.wait_time = mode_duration $CollisionShape2D.shape.radius = max_radius + 16*0.5 # + tile width * 0.5 var FlowerScene = preload("res://Scenes/Entities/Enemies/Flower.tscn") for number in range(3): var flower = FlowerScene.instantiate() flower.angle = deg_to_rad(120 * number) # if last flower is removed, remove self flower.get_node("Health").died.connect(func(): flowers.remove_at(flowers.find(flower)) if flowers.is_empty(): queue_free() ) get_parent().add_child(flower) flowers.push_front(flower) func _physics_process(delta): if follows_player: var player_direction = position.direction_to(Global.player.position) velocity = player_direction * float(speed) * delta move_and_collide(velocity) if movement_mode == MovementMode.SHRINK and radius > min_radius: radius = max( min_radius, radius - ((max_radius - min_radius) / mode_duration) * delta ) elif movement_mode == MovementMode.EXPAND and radius < max_radius: radius = min( max_radius, radius + ((max_radius - min_radius) / mode_duration) * delta ) for flower in flowers: flower.move_and_collide(velocity) flower.position = position + Vector2(cos(flower.angle) * radius, sin(flower.angle) * radius) flower.angle += float(speed) * delta func _on_detection_area_body_entered(body): if body is Player: follows_player = true func _on_detection_area_body_exited(body): if body is Player: follows_player = false func _on_timer_timeout(): if movement_mode == MovementMode.SHRINK: movement_mode = MovementMode.EXPAND for flower in flowers: flower.expand() elif movement_mode == MovementMode.EXPAND: movement_mode = MovementMode.SHRINK for flower in flowers: flower.shrink()