#TouhouDanmakufu[Player]
#ScriptVersion[2]
#Menu[StB Aya]
#Text[Aya with her camera from Shoot the Bullet. Doesn't clear bullets or damage enemies. Taking snapshots may not work correctly with default or empty backgrounds.]
#Image[.\img\AyaSelect.png]
#ReplayName[Aya]

script_player_main {
  #include_function ".\AnimationHelpers.dnh"
  #include_function ".\EffectHelpers.dnh"
  
  let Images = [
    imgCrosshair,
    imgPercent,
    imgText,
    imgCircle1,
    imgCircle2,
    imgEdge,
    imgPhotoBG1,
    imgPhotoBG2,
    imgCharge,
    imgRecovery,
    imgWhite,
    imgPlaceholders,
    imgDeathWave,
    imgDeathParticle
  ];

  @Initialize {
    ascent(i in 0..length(Images)){
      LoadGraphic(Images[i]);
    }
    InitializeAyaAnimation;
    InitializeTempCommonData;
    SetSpeed(6, 2);
    
    CreateCamera;
    CreatePictures;
    ManageChargeParticles;
    ManageRecoveryParticles;
    ManagePlaceholders;
    ManageDeathEffect;
    
    SetRateScoreSystemEnable(false);
    SetDefaultStatusVisible(false);
    SetAutoEffect(false);
  }
  
  @MainLoop {
    SetIntersectionCircle(GetPlayerX, GetPlayerY, 1);
    ControlCharge;
    
    if(CameraReady && !CameraZoom && !CameraUsed && GetKeyState(VK_SHOT)==KEY_PUSH && GetKeyState(VK_SLOWMOVE)==KEY_FREE && !OnMissed){
      ZoomMode;
    }
    
    if(CameraZoom || GetGameSpeed < 0 || !GetPlayerEnabled){
      SetSpeed(0, 0);
    }
    else if(GetKeyState(VK_SHOT)==KEY_HOLD && GetKeyState(VK_SLOWMOVE)==KEY_HOLD){
      SetSpeed(0.5*(1/(GetGameSpeed+1)), 0.5*(1/(GetGameSpeed+1)));
    }
    else {
      SetSpeed(6*(1/(GetGameSpeed+1)), 2*(1/(GetGameSpeed+1)));
    }
    
    if(!GetPlayerEnabled){
      CameraCharge = 50;
      CameraChargeAccel = 0.08;
      Charging = false;
      CameraReady = false;
      CameraZoom = false;
      CameraUsed = false;
      CameraShow = true;
      CurrentPicture = 0;
      SceneBestPictureScore = -1;
      WasSuccessful = false;
      SetCurrentPicture(0);
      SetGameSpeed(0);
    }
    
    yield;
  }
  
  @Missed {
    MainLoop;
    ExtendPlayer(5-GetPlayerLife);
  }
  
  @SpellCard {
  }
  
  @DrawLoop {
    if(CameraZoom || GetGameSpeed < 0){
      let angle1 = AngleFromPlayer(CameraX, CameraY);
      ascent(i in 0..8){
        if(absolute(AngularDistance(angle1, i*45))<=22.5){
          SetTexture(imgAya);
          SetGraphicRect(i*32, 176, (i+1)*32, 224);
          DrawGraphic(GetPlayerX, GetPlayerY);
          break;
        }
      }
    }
    else {
      DrawAya;
    }
  }
  
  @Finalize {
  }
  
}