#TouhouDanmakufu
#Title[Spell03]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
  #include_function ".\AnimationLib.dnh"
  #include_function ".\function_cutin.txt"
  let imgNue = GetCurrentScriptDirectory ~ "Nue.png";
  let Cut = GetCurrentScriptDirectory ~ "MurBCut.png";
  let qwe = GetCurrentScriptDirectory ~ "ZUN's shotdata.txt";
 let cir = GetCurrentScriptDirectory ~ "circle.png";
 let cha = GetCurrentScriptDirectory ~ "ch.png";
 let spbg1 = GetCurrentScriptDirectory ~ "BBG.png";
 let spbg2 = GetCurrentScriptDirectory ~ "sp2.png";
  @Initialize {
  
  
   LoadUserShotData(qwe);
  
    SetLife(12000);
	SetTimer(70);
    
    LoadGraphic(imgNue);
    LoadGraphic(cir);
    LoadGraphic(cha);
    LoadGraphic(Cut);
    LoadGraphic(spbg1);
    LoadGraphic(spbg2);
    MagicCircle(false);
    InitializeAnimationData;
	SetEffectForZeroLife(90,255,1);
 
  
  
    Animate("nue", "idle", true);
   mus;
    ShowOffNueAnimation;
    
  }
  
  @MainLoop {SetCollisionA(GetX, GetY, 32);angle=0;
        SetCollisionB(GetX, GetY, 16);
    yield ;
	
	if(GetLife<10){
	SetLife(0);
	
	
	}
	
	
	
  }let wave=0;
  let x=0;let y=0;let z=0;let dir=60;let dor=60; let sa=0;
  @DrawLoop {
    
	  
	  
	 
	  
	  
	  
	   SetTexture(cir);SetAlpha(150);
 
	SetGraphicRect(0,0,128,127);
	SetGraphicScale(2+sin(wave)*0.2,2+sin(wave)*0.2);

wave+=3;x+=5;
	SetGraphicAngle(0, 0, x);
	DrawGraphic(GetX,GetY);
   
   //////
   //GetX + dir*cos(dor), GetY + dir*sin(dor);
   

	 
  
  
  
   
    SetTexture(imgNue);SetAlpha(255);SetGraphicScale(1,1);SetRenderState(ALPHA);
	  SetGraphicAngle(y, 0, 0);
    DrawAnimatedSprite("nue", GetX, GetY);
  }
  @BackGround{
  
  SetTexture(spbg1);SetAlpha(250);
 SetColor(210,210,230);
	SetGraphicRect(0,0,512,512);
	SetGraphicScale(1.3,1.3);


	SetGraphicAngle(0, 0, -x/8);
	DrawGraphic(GetCenterX,GetCenterY-50);
	
	
	SetTexture(spbg2);SetAlpha(150);
 
	SetGraphicRect(0,0,9129,9129);
	SetGraphicScale(1,1);


	SetGraphicAngle(0, 0, 0);
	DrawGraphic(GetCenterX-x/5,GetCenterY-x/10);
	
	
  
  }
 task charge{
 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_ch02.wav");
 Concentration02(30);
 Concentration02(40);
 Concentration02(30);
 Concentration02(40);
 Concentration02(30);
 Concentration02(40);
 wait(60);
 }
  task mus{}
  @Finalize {
    DeleteGraphic(imgNue);
   
  }
  let angle=270;let sp=3;let a=0;let angle2=0;let xx=610;let yy=0;let an=0;let spd=1;
 let spp=0;let angle3=0; let a33=0;
 task blast2{
 wait(2000);
 loop(7676){spp=rand(1,2);
 wait(120);a33+=90;
   loop(10){
  CreateShot01(GetEnemyX,GetEnemyY,spp,angle3+a33,153,5);
  angle3+=360/10;
  
  
  }
 
 
 }
 }
 
 
 task blast{blast2;
 wait(1400);
 loop(99090){
 wait(240);
 charge;
 wait(90);
  Animate("nue", "start cast", false);
      wait(20);
	  
 fifif;
 Explosion01(GetX,GetY,11,1,60);
 Explosion01(GetX,GetY,11,1,60);
 Explosion01(GetX,GetY,11,1,60);
 wait(120);
  Animate("nue", "idle", true);
	   wait(30);
 
 
 
 
 }
 
 
 
 
 
 
 
 }
 
 
 task fifif{
 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon00.wav");
 CreateShotA(21,GetX,GetY,10);
   SetShotDataA(21,0,0.5,GetAngleToPlayer,0,0,0,232);
   SetShotDataA(21,10,1,NULL,0,0,0,232);
   SetShotDataA(21,20,1.3,NULL,0,0,0,232);
   SetShotDataA(21,30,1.6,NULL,0,0,0,232);
   SetShotDataA(21,40,1.9,NULL,0,0,0,232);
   SetShotDataA(21,50,2.2,NULL,0,0,0,232);
   SetShotDataA(21,60,2.5,NULL,0,0,0,232);
   SetShotDataA(21,70,2.8,NULL,0,0,0,232);
   SetShotDataA(21,80,3.1,NULL,0,0,0,232);
   SetShotDataA(21,90,3.4,NULL,0,0,0,232);
   SetShotDataA(21,100,3.7,NULL,0,0,0,232);
   SetShotDataA(21,110,4,NULL,0,0,0,232);
   SetShotDataA(21,120,4.3,NULL,0,0,0,232);
   SetShotDataA(21,130,4.7,NULL,0,0,0,232);
   
    ascent(i in 0..128){
    CreateShotA(2, 0, 0, 5);
    SetShotDataA(2, 0, 0, rand(0,360), 0, 0, 1, 32);
    SetShotDataA(2, 120, 0.4, NULL, 0, 0, 0, 32);
    SetShotDataA(2, 140, 0.8, NULL, 0, 0, 0, 32);
    SetShotDataA(2, 160, 1.2, NULL, 0, 0, 0, 32);
    SetShotDataA(2, 180, 1.6, NULL, 0, 0, 0, 32);
    SetShotDataA(2, 200, 2, NULL, 0, 0, 0, 32);
    AddShot(i*4, 21, 2, i*12);
}
  
	FireShot(21);
 
 
 }
  task ShowOffNueAnimation {
   wait(90);blast;
   CreateEnemyFromFile(GetCurrentScriptDirectory~"ba.txt",GetCenterX,0,0,0,0); 
      SetMovePosition03(GetClipMinX+100, GetCenterY-100, 20, 4);charge;
      SetNueMoveAnimation("left");
      yield ;
      while(GetSpeed>0.1){yield;}
	  
      wait(30);
     
	  wait(30);
	

  cutin("NAZRIN", "''Byakuren's Force''",Cut,0,0,377,531);
   SetScore(30000);
   SetDurableSpellCard;
  PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_cat00.wav");
  
	 angle=0;
  
    
      wait(360);
	  SetMovePosition03(GetCenterX, GetCenterY-100, 20, 4);
      SetNueMoveAnimation("right");
  
  
   
  
  }
  
 
  task SetNueMoveAnimation(direction) {
    if(direction == "left"){
      Animate("nue", "start move left", false);
      yield ;
      while(GetSpeed>0.1){
        yield ;
      }
      Animate("nue", "stop move left", false);
    }
    if(direction == "right"){
      Animate("nue", "start move right", false);
      yield ;
      while(GetSpeed>0.1){
        yield ;
      }
      Animate("nue", "stop move right", false);
    }
    wait(12);
    Animate("nue", "idle", true);
  }
  
  
  
  
  
 
  
  
  
  
  
  
  
  function wait(t){
    loop(t){yield;}
  }
  
  sub InitializeAnimationData {
    CreateAnimation("nue", "idle", 4);
    SetAnimationFrame("nue", "idle", 0, imgNue, 12, 0, 0, 96, 112);
    SetAnimationFrame("nue", "idle", 1, imgNue, 12, 96, 0, 192, 112);
    SetAnimationFrame("nue", "idle", 2, imgNue, 12, 192, 0, 288, 112);
    SetAnimationFrame("nue", "idle", 3, imgNue, 12, 288, 0, 384, 112);
    
    CreateAnimation("nue", "start move right", 4);
    SetAnimationFrame("nue", "start move right", 0, imgNue, 8, 0, 112, 96, 224);
    SetAnimationFrame("nue", "start move right", 1, imgNue, 8, 96, 112, 192, 224);
    SetAnimationFrame("nue", "start move right", 2, imgNue, 8, 192, 112, 288, 224);
    SetAnimationFrame("nue", "start move right", 3, imgNue, 8, 288, 112, 384, 224);
    
    CreateAnimation("nue", "stop move right", 3);
    SetAnimationFrame("nue", "stop move right", 0, imgNue, 4, 288, 112, 384, 224);
    SetAnimationFrame("nue", "stop move right", 1, imgNue, 4, 192, 112, 288, 224);
    SetAnimationFrame("nue", "stop move right", 2, imgNue, 4, 96, 112, 192, 224);
    
    CreateAnimation("nue", "start move left", 4);
    SetAnimationFrame("nue", "start move left", 0, imgNue, 8, 0, 224, 96, 336);
    SetAnimationFrame("nue", "start move left", 1, imgNue, 8, 96, 224, 192, 336);
    SetAnimationFrame("nue", "start move left", 2, imgNue, 8, 192, 224, 288, 336);
    SetAnimationFrame("nue", "start move left", 3, imgNue, 8, 288, 224, 384, 336);
    
    CreateAnimation("nue", "stop move left", 3);
    SetAnimationFrame("nue", "stop move left", 0, imgNue, 4, 288, 224, 384, 336);
    SetAnimationFrame("nue", "stop move left", 1, imgNue, 4, 192, 224, 288, 336);
    SetAnimationFrame("nue", "stop move left", 2, imgNue, 4, 96, 224, 192, 336);
    
    CreateAnimation("nue", "start cast", 6);
    SetAnimationFrame("nue", "start cast", 0, imgNue, 6, 0,336,96,448);
    SetAnimationFrame("nue", "start cast", 1, imgNue, 6, 96,336,192,448);
    SetAnimationFrame("nue", "start cast", 2, imgNue, 6, 192,336,288,448);
    SetAnimationFrame("nue", "start cast", 3, imgNue, 6, 288,336,384,448);
    SetAnimationFrame("nue", "start cast", 4, imgNue, 6, 384,336,480,448);
    SetAnimationFrame("nue", "start cast", 5, imgNue, 6, 384+96,336,480+96,448);
    
    CreateAnimation("nue", "stop cast", 4);
    SetAnimationFrame("nue", "stop cast", 0, imgNue, 4, 384,336,480,448);
    SetAnimationFrame("nue", "stop cast", 1, imgNue, 4, 288,336,384,448);
    SetAnimationFrame("nue", "stop cast", 2, imgNue, 4, 192,336,288,448);
    SetAnimationFrame("nue", "stop cast", 3, imgNue, 4, 96,336,192,448);
 
  }
}