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

script_enemy_main {
  #include_function ".\AnimationLib.dnh"
  #include_function ".\function_cutin.txt"
  let imgNue = GetCurrentScriptDirectory ~ "Nue.png";
  let Cut = GetCurrentScriptDirectory ~ "MurCut.png";
  let qwe = GetCurrentScriptDirectory ~ "ZUN's shotdata.txt";
 let cir = GetCurrentScriptDirectory ~ "circle.png";
 let cha = GetCurrentScriptDirectory ~ "ch.png";
 let spbg1 = GetCurrentScriptDirectory ~ "sp1.png";
 let spbg2 = GetCurrentScriptDirectory ~ "sp2.png";
  @Initialize {
  cutin("NAZRIN", "Anchor Sign ''Heavy Anchors''",Cut,0,0,224,464);
  
   LoadUserShotData(qwe);
   SetScore(30000);
    SetLife(8000);
	SetTimer(70);
    SetDurableSpellCard;
    LoadGraphic(imgNue);
    LoadGraphic(cir);
    LoadGraphic(cha);
    LoadGraphic(Cut);
    LoadGraphic(spbg1);
    LoadGraphic(spbg2);
    
    InitializeAnimationData;
	
 
  
  
    Animate("nue", "idle", true);
   mus;
    ShowOffNueAnimation;
    
  }
  
  @MainLoop {SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
    yield ;
  }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(180);
 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;
 task Fire{
 
 loop(4){
 bul;
 
 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon01.wav");
 angle+=360/4;
 }}
 
 task Fire2{
 
 loop(4){
 bul2;
 
 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon01.wav");
 angle+=360/4;
 }
 
 
 a+=rand(0,360);
 }
 
 task Fire3{
 
 
 bul3;
 
 
 }
 
 
 
 let anc=0;
 
 
 let angle2=0;
 task blast{
 loop(5656){
 //wait(1260);
 wait(180);
 if(sp>1){
 
 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon00.wav");
 loop(20){
	CreateShotA(122,GetX,GetY,10);
   SetShotDataA(122,0,2,angle2,0.2,0,0,192);
  
	FireShot(122);
	angle2+=360/20;
}}
 
 if(sp>2){
 wait(30);
 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon00.wav");
 loop(20){
	CreateShotA(122,GetX,GetY,10);
   SetShotDataA(122,0,2,angle2,-0.2,0,0,192);
  
	FireShot(122);
	angle2+=360/20;
}}
 
 if(sp>2){
 wait(30);
 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon00.wav");
 loop(20){
	CreateShotA(122,GetX,GetY,10);
   SetShotDataA(122,0,2,angle2,0.2,0,0,192);
  
	FireShot(122);
	angle2+=360/20;
}}

 if(sp>2){
 wait(60);
 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon00.wav");
 loop(20){
	CreateShotA(122,GetX,GetY,10);
   SetShotDataA(122,0,2,angle2,-0.4,0,0,192);
  
	FireShot(122);
	angle2+=360/20;
}}

 if(sp>2){
 wait(30);
 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon00.wav");
 loop(20){
	CreateShotA(122,GetX,GetY,10);
   SetShotDataA(122,0,2,angle2,0.4,0,0,192);
  
	FireShot(122);
	angle2+=360/20;
}}
if(sp>2){
 wait(30);
 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon00.wav");
 loop(20){
	CreateShotA(122,GetX,GetY,10);
   SetShotDataA(122,0,2,angle2,-0.4,0,0,192);
  
	FireShot(122);
	angle2+=360/20;
}}

 }
 
 
  
 }

 
 
 
 
  task ShowOffNueAnimation {
  
  
  
  
  
  blast;
    wait(20);sp=0;
    loop {
      SetMovePosition03(GetClipMinX+rand(50, 200), GetClipMinY+rand(80, 120), 20, 4);
      SetNueMoveAnimation("left");
      yield ;
      while(GetSpeed>0.1){yield;}
	  charge;
      wait(30);
     
	  wait(30);
	  
	
	   Animate("nue", "start cast", false);
	  wait(20);
	  sp+=1;
	  Fire;
	  wait(60);
	  charge;
	  wait(40);
     
	 y=0;
	  Animate("nue", "idle", true);
    wait(90);
	  Animate("nue", "start cast", false);
      wait(120);
	   Animate("nue", "idle", true);
	   wait(30);
	 
      
	  
	  
	   SetMovePosition03(GetClipMinX+rand(200, 400), GetClipMinY+rand(80, 120), 20, 4);
      SetNueMoveAnimation("right");
      yield ;
      while(GetSpeed>0.1){yield;}
	  charge;
      wait(30);
     
	  wait(30);
	  
	
	 
	  wait(20);
	  xx=80;
 yy=0;anc=1;
	  
	  Fire2;
	  wait(60);
	  charge;
	  wait(40);
     
	  y=0;
	  Animate("nue", "idle", true);
    wait(90);
	  Animate("nue", "start cast", false);
      wait(120);
	   Animate("nue", "idle", true);
	   wait(30);
     
	 
	 
	 
	 
	 /////
	 
	  SetMovePosition03(GetCenterX, GetClipMinY+rand(80, 120), 20, 4);
      SetNueMoveAnimation("left");
      yield ;
      while(GetSpeed>0.1){yield;}
	  charge;
      wait(30);
     
	  wait(30);
	  
	
	 
	  wait(20);
	  xx=80;
 yy=0;anc=1;
	  
	  Fire3;
	  Animate("nue", "start cast", false);
	
	  
      wait(180);
	   Animate("nue", "idle", true);
	   wait(60);
     
	 
    }
  }
  
  
  
  task bul{
 
	
	
	CreateShotA(12,GetX,GetY,10);
   SetShotDataA(12,0,2,angle+a,-2,0,0,252);
   SetShotDataA(12,60,2.2,NULL,-1.5,0,0,252);
   SetShotDataA(12,120,2.4,NULL,-1,0,0,252);
   SetShotDataA(12,180,2.6,NULL,-0.5,0,0,252);
   SetShotDataA(12,210,2.8,NULL,-0.4,0,0,252);
   SetShotDataA(12,240,3.8,NULL,-0.3,0,0,252);
   SetShotDataA(12,270,4.3,NULL,-0.2,0,0,252);
   SetShotDataA(12,300,4.8,NULL,-0.1,0,0,252);
   SetShotDataA(12,330,5,NULL,-0.1,0,0,252);
   SetShotDataA(12,360,5.2,NULL,-0.1,0,0,252);
   SetShotDataA(12,390,5.4,NULL,-0.1,0,0,252);
   
  
   ascent(i in 0..128){
    CreateShotA(212, 0, 0, 80);
    SetShotDataA(212, 0, 10, GetAngleToPlayer+180, 0, 0, 1,253);
   
    AddShot(i*10, 12, 212, i*12);
}
ascent(i in 0..128){
    CreateShotA(2, 0, 0, 0);
    SetShotDataA(2, 0, 0, rand(0,360), 0, 0, 1, 194);
    SetShotDataA(2, 120, 0.4, NULL, 0, 0, 0, 194);
    SetShotDataA(2, 140, 0.8, NULL, 0, 0, 0, 194);
    SetShotDataA(2, 160, 1.2, NULL, 0, 0, 0, 194);
    SetShotDataA(2, 180, 1.6, NULL, 0, 0, 0, 194);
    SetShotDataA(2, 200, 2, NULL, 0, 0, 0, 194);
    AddShot(i*10, 12, 2, i*12);
}









   
   
   FireShot(12);
   wait(180);
	PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon01.wav");
	}
  
  
  task bul2{
 
	
	
	CreateShotA(12,GetX,GetY,10);
   SetShotDataA(12,0,2,angle+a,2,0,0,252);
   SetShotDataA(12,60,2.2,NULL,1.5,0,0,252);
   SetShotDataA(12,120,2.4,NULL,1,0,0,252);
   SetShotDataA(12,180,2.6,NULL,0.5,0,0,252);
   SetShotDataA(12,210,2.8,NULL,0.4,0,0,252);
   SetShotDataA(12,240,3.8,NULL,0.3,0,0,252);
   SetShotDataA(12,270,4.3,NULL,0.2,0,0,252);
   SetShotDataA(12,300,4.8,NULL,0.1,0,0,252);
   SetShotDataA(12,330,5,NULL,0.1,0,0,252);
   SetShotDataA(12,360,5.2,NULL,0.1,0,0,252);
   SetShotDataA(12,390,5.4,NULL,0.1,0,0,252);
    ascent(i in 0..128){
    CreateShotA(212, 0, 0, 80);
    SetShotDataA(212, 0, 10, GetAngleToPlayer+180, 0, 0, 1,253);
   
    AddShot(i*10, 12, 212, i*12);
}
   ascent(i in 0..128){
    CreateShotA(2, 0, 0, 5);
    SetShotDataA(2, 0, 0, rand(0,360), 0, 0, 1, 194);
    SetShotDataA(2, 120, 0.4, NULL, 0, 0, 0, 194);
    SetShotDataA(2, 140, 0.8, NULL, 0, 0, 0, 194);
    SetShotDataA(2, 160, 1.2, NULL, 0, 0, 0, 194);
    SetShotDataA(2, 180, 1.6, NULL, 0, 0, 0, 194);
    SetShotDataA(2, 200, 2, NULL, 0, 0, 0, 194);
    AddShot(i*10, 12, 2, i*12);
}
 
   
   
   FireShot(12);
   wait(180);
	PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon01.wav");
	
	}
  
  
  task bb(id,id2,aa,id3){
  PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon01.wav");
	
	CreateShotA(id,GetX,GetY,10);
   SetShotDataA_XY(id, 0, 1, -3, 0.5, 0.09, aa, 58, 252);  
   ascent(i in 0..128){
    CreateShotA(id3, 0, 0, 80);
    SetShotDataA(id3, 0, 10, GetAngleToPlayer+180, 0, 0, 1,253);
   
    AddShot(i*10, id, id3, i*12);
}
   ascent(i in 0..128){
    CreateShotA(id2, 0, 0, 5);
    SetShotDataA(id2, 0, 0.2, rand(0,360), 0, 0, 1, 194);
    SetShotDataA(id2, 120, 0.4, NULL, 0, 0, 0, 194);
    SetShotDataA(id2, 140, 0.8, NULL, 0, 0, 0, 194);
    SetShotDataA(id2, 160, 1.2, NULL, 0, 0, 0, 194);
    SetShotDataA(id2, 180, 1.6, NULL, 0, 0, 0, 194);
    SetShotDataA(id2, 200, 2, NULL, 0, 0, 0, 194);
      AddShot(i*7, id, id2, i*12);}
	FireShot(id);
	
  
  }
  
  task bul3{
 
	bb(34,43,2,777777);
	bb(3432342234,433,-2,4444444);
	bb(34233,4336,-1,444444444);
	bb(3434553,4353,1,4444444444444);
	bb(342533,4333,0,44444444444444);

	
	
	
	
}
  
  
  
  
  
  
  
  
  
  
  
  
  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);
 
  }
}