extends Area2D

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

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

var tex = preload("res://images/spark.png")
var spr
var dir
var dRot = PI
var radius = 50
var dRad = 60
var centerPos

func _ready():
  # APPEARANCE
  spr = Sprite.new()
  spr.set_texture(tex)
  spr.scale = Vector2(1.0, 1.0)
  add_child(spr)
  # COLLISION
  var my_shape = RectangleShape2D.new()
  my_shape.set_extents(Vector2(spr.texture.get_size().x / 2, spr.texture.get_size().y / 2))
  var collision = CollisionShape2D.new()
  collision.set_shape(my_shape)
  add_child(collision)
#  for i in range(100):
#    print ("i = " + str(i))
#    print(get_collision_mask_bit(i))
#    print(get_collision_layer_bit(i))
  set_collision_layer_bit(COLL.PLAYER, false)
  set_collision_mask_bit(COLL.PLAYER, false)
  set_collision_mask_bit(COLL.ENEMIES, true)
  set_collision_mask_bit(COLL.POWERUP, true)

func initialize(pos, dir):
  centerPos = pos
  rotation = UTIL.dir2rot(dir)
  position = centerPos + radius * Vector2(-sin(rotation), cos(rotation))

func _process(delta):
  rotation += dRot * delta
  radius += dRad * delta
  position = centerPos + radius * Vector2(-sin(rotation), cos(rotation))
  if (position - centerPos).length() > centerPos.length() + 40:
    queue_free()