extends Node2D

var enemy_type: String = "horse"

var bullet_scene = preload("res://scenes/boss_bullet.tscn")
var start_pos = Vector2.ZERO
var speed = 0
var tween_speed: float = 1.4
  
var exploding = false

var rotate_speed: int = 100
var shooter_timer_wait_time: float = 0.2
var spawn_point_count: int = 4
var spawn_radius = 100

@onready var shoot_timer = $ShootTimer
@onready var rotater = $Rotater
@onready var screensize  = get_viewport_rect().size

func _ready():
  var step = 2 * PI / spawn_point_count
  
  for i in range(spawn_point_count):
    var spawn_point = Node2D.new()
    var pos = Vector2(spawn_radius, 0).rotated(step * i)
    spawn_point.position = pos
    spawn_point.rotation = pos.angle()
    rotater.add_child(spawn_point)
    
  shoot_timer.wait_time = shooter_timer_wait_time
  shoot_timer.start()
  
func _process(delta: float) -> void:
  var new_rotation = rotater.rotation_degrees + rotate_speed * delta
  rotater.rotation_degrees - fmod(new_rotation, 360)

func _on_ShootTimer_timeout() -> void:
  for s in rotater.get_children():
    var b = bullet_scene.instantiate()
    get_tree().root.add_child(b)
    b.position = s.global_position
    b.rotation = s.global_rotation
    
