#TouhouDanmakufu[Player]
#ScriptVersion[2]
#Menu[IkaReimu]
#Text[Press 'c' to change your color!]
#Image[.\RumiaSelect.png]
#ReplayName[IkaReimu]

script_player_main {
  #include_function "lib\Ikareimu\Player.dnh"

  let imgSprite = GetCurrentScriptDirectory~"Ikareimu.png";
  let shotCount = -1;
  let bNextShot = true;
  @Initialize {
    IkareimuPlayer_Initialize;
    LoadGraphic(imgSprite);
    
    SetPlayerLifeImage(imgSprite, 1, 131, 28, 172);
    SetSpeed(4, 1.6);
  }
  
  @MainLoop {
    if(GetKeyState(VK_SHOT)==KEY_HOLD) {
      shotCount++;
    }
    if(GetKeyState(VK_SHOT)==KEY_PULL) {
      shotCount = -1;
    }
    if(shotCount%5==0 && GetCommonData("gamestate")!="mainMenu") {
      IkareimuPlayer_CreateShot(GetPlayerX-10, GetPlayerY, 15, 270, RED56, BLUE56);
      IkareimuPlayer_CreateShot(GetPlayerX+10, GetPlayerY, 15, 270, RED56, BLUE56);
    }
    
    if(GetCommonDataDefault("optionsControls", 0)==0){
      IkareimuPlayer_SetPolaritySwitchTrigger("c");
    }
    if(GetCommonDataDefault("optionsControls", 0)==1){
      IkareimuPlayer_SetPolaritySwitchTrigger("ctrl");
    }
    if(GetCommonDataDefault("optionsControls", 0)==2){
      IkareimuPlayer_SetPolaritySwitchTrigger("shotslow");
    }
    
    if(GetCommonDataDefault("chaining", "active")=="reset"){
      Chain_Reset;
      SetCommonData("chaining", "active");
    }
    
    SetIntersectionCircle(GetPlayerX, GetPlayerY, 1);
    yield;
    IkareimuPlayer_Run;
  }
  
  @Missed {
    yield;
  }
  
  @SpellCard {
  }
  
  @DrawLoop
  {		
    Shield_Draw;
    SetColor(255, 255, 255);
    SetRenderState(ALPHA);
    SetTexture(imgSprite);
    if(GetPolarity == RED){
      if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_LEFT)==KEY_HOLD){
        SetGraphicRect(1, 45, 28, 86);
      }
      else if(GetKeyState(VK_RIGHT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_HOLD) {
        SetGraphicRect(1, 89, 28, 130);
      }
      else {
        SetGraphicRect(1, 1, 28, 42);
      }
    }
    if(GetPolarity == BLUE){
      if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_LEFT)==KEY_HOLD){
        SetGraphicRect(31, 45, 58, 86);
      }
      else if(GetKeyState(VK_RIGHT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_HOLD) {
        SetGraphicRect(31, 89, 58, 130);
      }
      else {
        SetGraphicRect(31, 1, 58, 42);
      }
    }
    DrawGraphic(GetPlayerX, GetPlayerY);
  }
  
  @Finalize
  {
    DeleteGraphic(imgSprite);
    IkareimuPlayer_Finalize;
  }
}