#include_function ".\lib\common.dnh"
#include_function ".\lib\shot.dnh"
#include_function ".\lib\move.dnh"

let Spawned = false;
let sfxShot1 = GCD ~ "lib\sfx\shot1.wav";
let sfxShot2 = GCD ~ "lib\sfx\shot2.wav";
  
sub InitializeEnemy {
  LoadUserShotData(GCD ~ "lib\supershot.dnh");
  ManagePosition;
  ManageShotData;
  ManageShots;
  ManageSpawning;
  ManageMovement;
  
  SetCommonDataEx("temp", "enemy num", GetCommonDataDefaultEx("temp", "enemy num", 0)+1);
  
  task ManageSpawning {
    Concentration01(60);
    Wait(55);
    Spawned = true;
  }

  task ManagePosition {
    SetX(GetPlayerX+GetX);
    SetY(GetPlayerY+GetY);
    loop {
      SetX(GetX-GetCommonDataEx("temp", "xDisplace"));
      SetY(GetY-GetCommonDataEx("temp", "yDisplace"));
      if(GetX > GetCenterX+320){
        SetX(GetX-640);
      }
      if(GetX < GetCenterX-320){
        SetX(GetX+640);
      }
      if(GetY > GetCenterY+320){
        SetY(GetY-640);
      }
      if(GetY < GetCenterY-320){
        SetY(GetY+640);
      }
      yield;
    }
  }
  
  sub ManageShots {
    CreateEnemyFromFile(GetCurrentScriptDirectory ~ "lib\bulletdummy.dnh", 0, 0, 0, 0, enemyID);
  }
}

sub FinalizeEnemy {
  SetCommonDataEx("temp", defeatedKey, true);
  SetCommonDataEx("temp", "enemy num", GetCommonDataDefaultEx("temp", "enemy num", 0)-1);
}