extends "res://src/Spell.gd"

var Ice = preload("res://src/Ice.gd")

var UTIL = preload("res://src/Utility.gd")

var sound_ice_1 = preload("res://sound/ice-0.wav")
var sound_ice_2 = preload("res://sound/ice-2.wav")

var asp # audio

func _ready():
  castingTime = 0.5
  asp = AudioStreamPlayer.new()
  self.add_child(asp)
  
func effect1():
  var player = $"/root/World/ys/player"
  var pos = player.position + player.spr.offset
  var dir = player.dir
  var ice = Ice.new()
  ice.initialize(pos + dir * Vector2(30, 30) - Vector2(0, 20), dir)
  $"/root/World/ys".add_child(ice)
  if not asp.is_playing():
    asp.set_volume_db(-5)
    asp.stream = sound_ice_1
    asp.play()

func effect2():
  var player = $"/root/World/ys/player"
  var pos = player.position
  for idx in [0, 1, 2, 3, 4, 5, 6, 7]:
    var dir = UTIL.rotatedDir(player.dir, idx)
    var ice = Ice.new()
    ice.initialize(pos + dir * Vector2(30, 30) - Vector2(0, 20), dir)
    ice.freezing = true
    $"/root/World/ys".add_child(ice)
    ice.spr.scale = Vector2(3.0, 3.0)
    if not asp.is_playing():
      asp.set_volume_db(-5)
      asp.stream = sound_ice_2
      asp.play()