#TouhouDanmakufu
#Title[Spell02]
#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 ''Rapid Fall''",Cut,0,0,224,464);
  
   LoadUserShotData(qwe);
   SetScore(30000);
    SetLife(12000);
	SetTimer(70);
    SetDurableSpellCard;
    LoadGraphic(imgNue);
    LoadGraphic(cir);
    LoadGraphic(cha);
    LoadGraphic(Cut);
    LoadGraphic(spbg1);
    LoadGraphic(spbg2);
     MagicCircle(false);
    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=0;let sp=3;let a=0;let angle2=0;let xx=610;let yy=0;let an=0;let spd=1;
 
  task ShowOffNueAnimation {
  PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_cat00.wav");
  
  
  
  
 an=1;
    wait(20);sp=0;
   
   
      SetMovePosition03(GetCenterX, GetCenterY-50, 20, 4);
      SetNueMoveAnimation("left");
      yield ;
   
   while(GetSpeed>0.1){yield;}
 
   charge;
      wait(30);
     Fire;
	  wait(30);
	  
	
	   Animate("nue", "start cast", false);
	  
	  sp+=1;
	  
	  
	 
	  spd=1;
	  wait(60);
	   
	   
	 
    y=0;
		
	
	 
	loop {yield;
	 /////
	 
	
    }
  }
  let co=0;
  task Fire{
   
  anc(GetClipMinX+50,GetClipMinY);
  anc2(GetClipMaxX-50,GetClipMinY);
  
  
  }
  
  
  task anc(x,y){
 
	task up{wait(60);
	loop(40){wait(5);a+=12;PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon00.wav");
	loop(3){
	
	CreateShotA(12,Obj_GetX(obj),Obj_GetY(obj)-50,0);
   SetShotDataA(12,0,1,angle-a,0,0,-2,242);
   
   
   
   FireShot(12);
  
	angle+=360/3;
	
	}
	
	
	}}
	
	
	
	task qweqwe{
	Obj_SetAngle(obj,Obj_GetAngle(obj)+5);
		 
		   Obj_SetAngle(obj,Obj_GetAngle(obj)-5);
		  
		  
		   
		  
		 
	
	}
	let gx=0;let gy=0;
	task blab{
	PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_don00.wav");
	
	
	
	loop(60){
	CreateShotA(12,GetClipMinX+50,GetClipMaxY,10);
   SetShotDataA_XY(12, 0, 0,  rand(0,-10), 0.5, 0.09,rand(0.9,-5), 58, 192);  
  
   
   
   
   FireShot(12);
	
	
	}}
	let angle3=0;
	
	
	
  let obj=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	Obj_SetSpeed(obj,5);
	Obj_SetAngle(obj,90);
	ObjShot_SetBombResist(obj,true);
	ObjShot_SetGraphic(obj,252);
	ObjShot_SetDelay(obj,0);
	

	while(!Obj_BeDeleted(obj)){yield;
	Obj_SetAutoDelete(obj,true);
	
   Obj_SetSpeed(obj,Obj_GetSpeed(obj)+0.3);
                    

	 if(Obj_GetY(obj)>GetClipMaxY) 
         { blab;
                   qweqwe;                    
         
		 
		
		 wait(1);
		 Obj_SetSpeed(obj,0.1);
		 wait(30);
		
		Obj_SetSpeed(obj,Obj_GetSpeed(obj)-2);
		
		if(co>1){
		up;}
		
           wait(250);co+=2;
		  y=180;PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon01.wav");
		   Animate("nue", "start cast", false);
	
           
                    }
	}

 



  
  
  }
  let angle3=0;let a22=0;
  /////////////
  task anc2(x,y){
 
	
	task blast{
	
	task en{
	loop(999909090){
	a22+=10;
	wait(10);
	}
	}
	
	if(co>3){en;
	loop(3434){
	wait(180);
	loop(3){
	CreateShotA(12,GetX,GetY,10);
   SetShotDataA(12,0,2,angle3+a22,0.1,0,0,194);
   
   
   
   FireShot(12);
   
   
   
   
   
	angle3+=360/3;
	}
	}
	
	
	if(co>4){
	
	wait(180);PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_alert.wav");
	loop(3){
	CreateShotA(12,GetX,GetY,10);
   SetShotDataA(12,0,2,angle3+a22,-0.1,0,0,194);
   
   
   
   FireShot(12);
   
   
   
   
   
	angle3+=360/3;
	}
	
	}
	
	
	
	
	
	
	
	}}
	
	task qweqwe{
	Obj_SetAngle(obj1,Obj_GetAngle(obj1)+5);
		 
		   Obj_SetAngle(obj1,Obj_GetAngle(obj1)-5);
		  
		  
		   
		  
		 
	
	}
	let gx=0;let gy=0;
	task blab2{
	PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_don00.wav");
	
	
	
	loop(80){
	CreateShotA(12,GetClipMaxX-50,GetClipMaxY,10);
   SetShotDataA_XY(12, 0, 0,  rand(0,-10), 0.5, 0.09,rand(-0.9,5), 58, 192);  
  
   
   
   
   FireShot(12);
	
	
	}}
	
	task up2{wait(60);
	loop(40){wait(5);a+=12;PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon00.wav");
	loop(3){
	
	CreateShotA(122,Obj_GetX(obj1),Obj_GetY(obj1)-50,0);
   SetShotDataA(122,0,1,angle+a,0,0,-2,242);
   
   
   
   FireShot(122);
  
	angle+=360/3;
	
	}
	
	
	}}
	
	
  let obj1=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj1,x);
	Obj_SetY(obj1,y);
	Obj_SetSpeed(obj1,5);
	Obj_SetAngle(obj1,90);
	ObjShot_SetBombResist(obj1,true);
	ObjShot_SetGraphic(obj1,252);
	ObjShot_SetDelay(obj1,0);
	

	while(!Obj_BeDeleted(obj1)){yield;
	Obj_SetAutoDelete(obj1,true);
	
   Obj_SetSpeed(obj1,Obj_GetSpeed(obj1)+0.3);
                    

	 if(Obj_GetY(obj1)>GetClipMaxY) 
         { blab2;
                   qweqwe;                    
         
		 
		
		 wait(1);
		 Obj_SetSpeed(obj1,0.1);
		 wait(30);
		if(co>3){blast;
		up2;}
		Obj_SetSpeed(obj1,Obj_GetSpeed(obj1)-2);
           wait(250);
           
                    }
	}

 



  
  
  }
  
  ////////////
  task circ{
  
 
  
  

   let circle=Obj_Create(OBJ_SHOT);
	Obj_SetX(circle,GetX-180*cos(x));
	Obj_SetY(circle,GetY-40*sin(-x));
	Obj_SetSpeed(circle,-spd);
	Obj_SetAngle(circle,90);
	ObjShot_SetBombResist(circle,true);
	ObjShot_SetGraphic(circle,190);
	ObjShot_SetDelay(circle,10);
	
  
  
  let circle=Obj_Create(OBJ_SHOT);
	Obj_SetX(circle,GetX-180*cos(-x));
	Obj_SetY(circle,GetY-40*sin(x));
	Obj_SetSpeed(circle,spd+1);
	Obj_SetAngle(circle,90);
	ObjShot_SetBombResist(circle,true);
	ObjShot_SetGraphic(circle,190);
	ObjShot_SetDelay(circle,10);
	

	while(!Obj_BeDeleted(circle)){yield;
	Obj_SetAutoDelete(circle,true);
	
	
	spd+=0.0001;
        wait(10);
	

      

                

	
	
	}
	
	

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