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

script_enemy_main {
  #include_function ".\AnimationLib.dnh"
 
  let imgNue = GetCurrentScriptDirectory ~ "Nue.png";
  let cir = GetCurrentScriptDirectory ~ "circle.png";
  let qwe = GetCurrentScriptDirectory ~ "supershot.txt";
  let co=rand_int(1,5);
  let sp1= GetCurrentScriptDirectory ~ "spbg1.png";
  let sp2= GetCurrentScriptDirectory ~ "spbg2.png";
  let sp22= GetCurrentScriptDirectory ~ "sp2.png";
  let spn= GetCurrentScriptDirectory ~ "sn5.png";
  
   let Cut = GetCurrentScriptDirectory ~ "NueCut.png";
 #include_function ".\function_cutin.txt"
 //#include_function ".\fam1.txt"
  #include_function ".\Halo.txt"
   let imagefile4 = GetCurrentScriptDirectory ~ "1q.png";
  @Initialize {
  
  CreateAura01("RED",0,2);
   LoadUserShotData(qwe);
    SetLife(8500);
	SetTimer(50);
    //SetY(-120);
	yim;
    LoadGraphic(imgNue);
    LoadGraphic(cir);
    LoadGraphic(Cut);
    LoadGraphic(imagefile4);
    LoadGraphic(sp1);
    LoadGraphic(spn);
    LoadGraphic(sp2);
    LoadGraphic(sp22);
    // SetDurableSpellCard;
	 
    InitializeAnimationData;
	  MagicCircle(false);
  
    Animate("nue", "idle", true);
   mus;
    ShowOffNueAnimation;
    // CreateAura01;
  }
  
  task yim{loop{yield;
  
   if(GetTimer<11&&GetTimer>=0){PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_timeout.wav");wait(60);}
 
  }}let sh=0;
  
  let xc=0;
  let yc=0;
  task br{wait(240);
  loop{
  //PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_lazer01.wav");
  CreateShot01(GetPlayerX-80, GetClipMinY-5,2,90,99,10);
  CreateShot01(GetPlayerX+80, GetClipMinY-5,2,90,99,10);
  wait(5);
  }
  }
  
  @MainLoop {
   yield ;
  SetCollisionA(GetX,GetY,10);
  SetCollisionB(GetX,GetY,10);
 sh=0;
   
   SetDamageRate(100,100);}
    
  let wave=0;
  let x=0;
  
  let xx=0;
  let aa=0;
  let yy=0;
  
  task u{
  b;
  c;
  
  
  task c{
  wait(70);
  loop(13){
  yield;
  yy+=8;
  }
  
  loop(10){
  yield;
  yy+=4;
  }
  loop(10){
  yield;
  yy+=3;
  }
  
  loop(10){
  yield;
  yy+=2;
  }
  
  
  loop(10){
  yield;
  yy+=1;
  }
  
  
  
  
  
  
  }
  
  
  
  task b{
  
  loop(60){
  yield;
  xx+=6;
  }
  }
  task a{
  loop(60){yield;
  ss+=0.033333;
  }
  }
  
  a;
  loop(90){
  yield;
  aa+=2.8;
  }
  
  
  
  }let ss=0;
  @DrawLoop {
  
  
  
	 
	 
     SetTexture(spn);SetAlpha(aa);
 SetGraphicRect(0,0,366,80);
	
	SetGraphicScale(3-ss,3-ss);


	SetGraphicAngle(0,-xx, 0);
	DrawGraphic(GetCenterX,GetCenterY-yy);
	 
	 
  
     SetTexture(imgNue);SetAlpha(255);
 SetGraphicRect(0,0,0,0);
	
	SetGraphicScale(1,1);


	SetGraphicAngle(0, 0, 0);
	DrawGraphic(GetX,GetY);
      DrawAnimatedSprite("nue", GetX, GetY+sin(wave*2)*2.2);
   
	    SetTexture(cir);SetAlpha(210);
 
	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);
  
  
  
if(sh==1){
   SetTexture(cir);SetAlpha(110);
 
	SetGraphicRect(0,0,128,127);
	SetGraphicScale(1.2+sin(wave)*0.1,1.2+sin(wave)*0.1);


	SetGraphicAngle(0, 0, x);
	DrawGraphic(GetX,GetY);
  SetTexture(cir);SetAlpha(110);
 
	SetGraphicRect(0,0,128,127);
	SetGraphicScale(1.2+sin(wave)*0.1,1.2+sin(wave)*0.1);


	SetGraphicAngle(0, 0, -x);
	DrawGraphic(GetX,GetY);}
  
  
   
  }
  task mus{PlayMusic(GetCurrentScriptDirectory ~ ".\Sounds\Nue1.mp3");}
  
  
  
   @BackGround{
  
 
	 
	
  
   SetAlpha(255);
   SetTexture(imagefile4);SetColor(255,255,255);
      SetGraphicRect(0, 0, 1111, 1111);
SetGraphicScale(1,1);
      SetGraphicAngle(0, 0,180);
      DrawGraphic(GetCenterX,GetCenterY);
  
      SetTexture(sp1);SetAlpha(255);
 
	SetGraphicRect(0,0,384,448);
	SetGraphicScale(1,1);


	SetGraphicAngle(0, 0, 0);
	DrawGraphic(GetCenterX,GetCenterY);
	
	
	  SetTexture(sp2);SetAlpha(125);
 
	SetGraphicRect(0,0,384+x/3,448+x/3);
	SetGraphicScale(1,1);


	SetGraphicAngle(0, 0, 0);
	DrawGraphic(GetCenterX,GetCenterY);
	
	
	 SetTexture(sp2);SetAlpha(125);
 
	SetGraphicRect(0,0,-384-x/3,448+x/3.2);
	SetGraphicScale(1,1);


	SetGraphicAngle(0, 0, 0);
	DrawGraphic(GetCenterX,GetCenterY);
	
	
	
  
   SetAlpha(115);
   SetTexture(sp22);SetColor(255,255,255);
      SetGraphicRect(0, 0, 1111, 1111);
SetGraphicScale(2,2);
      SetGraphicAngle(0, 0,x/8);
      DrawGraphic(GetCenterX,GetCenterY);
	
  }
  
  
  
  
  @Finalize {
    DeleteGraphic(imgNue);
   
  }
  
  
 
  
 
  
  
  
  
  task ShowOffNueAnimation {
  PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_fault.wav");
  
  
  
  
  
  
  
  
  
  
  
  //wait(60);
   if(GetX>GetCenterX){
	SetMovePosition03(GetCenterX, GetCenterY-50, 13, 3);
      SetNueMoveAnimation("left");}
	   if(GetX<GetCenterX){
	SetMovePosition03(GetCenterX, GetCenterY-50, 13, 3);
      SetNueMoveAnimation("right");}
	    if(GetX==GetCenterX){
	SetMovePosition03(GetCenterX, GetCenterY-50, 13, 3);
      SetNueMoveAnimation("right");}
      yield ;
      while(GetSpeed>0.1){yield;}
wait(90);
      Animate("nue", "start cast", false);
	  wait(20);
	  
	  SetScore(30000);
	  u;sh=1;
	  cutin("NAZRIN", "",Cut,0,0,253,430);
	  //PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon01.wav");
	    
  PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_cat00.wav");
		
		 wait(20); 
		  Animate("nue", "stop cast", false);
	  wait(20);
	   Animate("nue", "idle", true);
	   
	   wait(60);
	   
	    
	   SetMovePosition03(GetCenterX, GetCenterY-120, 13, 4);
	   SetNueMoveAnimation("right");
	   
	  
	   PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_ch02.wav");

	 Concentration02(30);
 Concentration02(40);
 Concentration02(30);let fg=0;
 Concentration02(40);
 Concentration02(30);let anga=0;
 Concentration02(40);
 while(GetSpeed>0.1){yield;}
	  let z=0;
	wait(90);
	  
	    Animate("nue", "start cast", false);
	  wait(20);
	  her;br;
	  wait(20);
	   
	    Animate("nue", "stop cast", false);
		wait(20);
		Animate("nue", "idle", true);
		wait(120);
		loop{
		
		
		
   
  // fire2;
  // SetMovePosition03(GetX-rand(20,40), GetY+rand(-10,10), 20, 4);
     // SetNueMoveAnimation("left");
      yield ;
      while(GetSpeed>0.1){yield;}
   wait(80);
     // Animate("nue", "start cast", false);
	  wait(10);her;
	// fire;
      wait(120);
     // Animate("nue", "stop cast", false);
      wait(16);
     // Animate("nue", "idle", true);
      wait(20);
   
   
   
    //fire2;
   //SetMovePosition03(GetX+rand(20,40), GetY+rand(-10,10), 20, 4);
     // SetNueMoveAnimation("right");
      yield ;
      while(GetSpeed>0.1){yield;}
   wait(80);
     // Animate("nue", "start cast", false);
	  wait(10);her;
	  //fire;
      wait(120);
     // Animate("nue", "stop cast", false);
      wait(16);
     // Animate("nue", "idle", true);
      wait(20);
   
   
   
   
   
		
		
		
		
		
		}
}
	   
	   
	    let raa=30;
	    let b=0;
	   
	   task her{
	   
	   task ll(x,ang,na){
	   
	   
	   
	   task spe3{xc=rand(10,30);
	wait(5);
	loop(17){
	PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_tan00.wav");
	if(Obj_GetX(qw12)>GetCenterX){
		CreateShotA(1,Obj_GetX(qw12), Obj_GetY(qw12),5);
		SetShotDataA(1,0,0,Obj_GetAngle(qw12)+180+b,0,0,0,250);
			SetShotDataA(1,120,0.2,NULL,0,0,0,250);
			SetShotDataA(1,160,0.4,NULL,0,0,0,250);
			SetShotDataA(1,180,0.6,NULL,0,0,0,250);
			SetShotDataA(1,200,0.8,NULL,0,0,0,250);
			SetShotDataA(1,220,1,NULL,0,0,0,250);
			SetShotDataA(1,240,1.2,NULL,0,0,0,250);
			SetShotDataA(1,260,1.4,NULL,0,0,0,250);
			SetShotDataA(1,280,1.6,NULL,0,0,0,250);
			SetShotDataA(1,300,1.8,NULL,0,0,0,250);
			SetShotDataA(1,320,2,NULL,0,0,0,250);
			SetShotDataA(1,340,2.2,NULL,0,0,0,250);
				
				FireShot(1);
				
				CreateShotA(1,Obj_GetX(qw12), Obj_GetY(qw12),5);
		SetShotDataA(1,0,0,Obj_GetAngle(qw12)+180-b,0,0,0,250);
			SetShotDataA(1,120,0.2,NULL,0,0,0,250);
			SetShotDataA(1,160,0.4,NULL,0,0,0,250);
			SetShotDataA(1,180,0.6,NULL,0,0,0,250);
			SetShotDataA(1,200,0.8,NULL,0,0,0,250);
			SetShotDataA(1,220,1,NULL,0,0,0,250);
			SetShotDataA(1,240,1.2,NULL,0,0,0,250);
			SetShotDataA(1,260,1.4,NULL,0,0,0,250);
			SetShotDataA(1,280,1.6,NULL,0,0,0,250);
			SetShotDataA(1,300,1.8,NULL,0,0,0,250);
			SetShotDataA(1,320,2,NULL,0,0,0,250);
			SetShotDataA(1,340,2.2,NULL,0,0,0,250);
				
				FireShot(1);
				
				b+=xc}
				if(Obj_GetX(qw12)<GetCenterX){
				
				CreateShotA(1,Obj_GetX(qw12), Obj_GetY(qw12),5);
		SetShotDataA(1,0,0,Obj_GetAngle(qw12)+180-b,0,0,0,250);
			SetShotDataA(1,120,0.2,NULL,0,0,0,250);
			SetShotDataA(1,160,0.4,NULL,0,0,0,250);
			SetShotDataA(1,180,0.6,NULL,0,0,0,250);
			SetShotDataA(1,200,0.8,NULL,0,0,0,250);
			SetShotDataA(1,220,1,NULL,0,0,0,250);
			SetShotDataA(1,240,1.2,NULL,0,0,0,250);
			SetShotDataA(1,260,1.4,NULL,0,0,0,250);
			SetShotDataA(1,280,1.6,NULL,0,0,0,250);
			SetShotDataA(1,300,1.8,NULL,0,0,0,250);
			SetShotDataA(1,320,2,NULL,0,0,0,250);
			SetShotDataA(1,340,2.2,NULL,0,0,0,250);
				
				FireShot(1);
		CreateShotA(1,Obj_GetX(qw12), Obj_GetY(qw12),5);
		SetShotDataA(1,0,0,Obj_GetAngle(qw12)+180+b,0,0,0,250);
			SetShotDataA(1,120,0.2,NULL,0,0,0,250);
			SetShotDataA(1,160,0.4,NULL,0,0,0,250);
			SetShotDataA(1,180,0.6,NULL,0,0,0,250);
			SetShotDataA(1,200,0.8,NULL,0,0,0,250);
			SetShotDataA(1,220,1,NULL,0,0,0,250);
			SetShotDataA(1,240,1.2,NULL,0,0,0,250);
			SetShotDataA(1,260,1.4,NULL,0,0,0,250);
			SetShotDataA(1,280,1.6,NULL,0,0,0,250);
			SetShotDataA(1,300,1.8,NULL,0,0,0,250);
			SetShotDataA(1,320,2,NULL,0,0,0,250);
			SetShotDataA(1,340,2.2,NULL,0,0,0,250);
				
				FireShot(1);
				b+=-xc}
				wait(8);
	
	
	}
	
	
	}
	   
	   
	   
	   
	   
	   let qw12=Obj_Create(OBJ_SHOT);
	Obj_SetX(qw12,x);
	Obj_SetY(qw12,Obj_GetY(obj));
	Obj_SetSpeed(qw12,2);
	Obj_SetAngle(qw12,ang);
	ObjShot_SetBombResist(qw12,true);
	ObjShot_SetGraphic(qw12,253);
	ObjShot_SetDelay(qw12,10);
	let b=0;
	
	
	
task spe2{



loop(40){
wait(3);

if(Obj_GetX(qw12)<GetCenterX){
Obj_SetAngle(qw12,Obj_GetAngle(qw12)-na);
}

if(Obj_GetX(qw12)>GetCenterX){
Obj_SetAngle(qw12,Obj_GetAngle(qw12)+na);
}


}
wait(120);
yield;

Obj_Delete(qw12);


}
	while(!Obj_BeDeleted(qw12)){yield;
	Obj_SetAutoDelete(qw12,true);
	spe3;
spe2;
 break;
  }}
	  
	   
let obj=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj,GetX);
	Obj_SetY(obj,GetY);
	Obj_SetSpeed(obj,2);
	Obj_SetAngle(obj,90);
	ObjShot_SetBombResist(obj,true);
	ObjShot_SetGraphic(obj,253);
	ObjShot_SetDelay(obj,10);
	
	task spe1{
	raa=30;PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_kira00.wav");
	loop(60){
	wait(2);raa+=-0.5;
	x+=3;bb+=7.345636;
	CreateShotA(1,Obj_GetX(obj)-raa*cos(x), Obj_GetY(obj),10);
		SetShotDataA(1,0,0,90-bb,0,0,0,57);
			SetShotDataA(1,120,0.2,NULL,0,0,0,57);
			SetShotDataA(1,160,0.4,NULL,0,0,0,57);
			SetShotDataA(1,180,0.6,NULL,0,0,0,57);
			SetShotDataA(1,200,0.8,NULL,0,0,0,57);
			SetShotDataA(1,220,1,NULL,0,0,0,57);
			SetShotDataA(1,240,1.2,NULL,0,0,0,57);
			SetShotDataA(1,260,1.4,NULL,0,0,0,57);
			SetShotDataA(1,280,1.6,NULL,0,0,0,57);
			SetShotDataA(1,300,1.8,NULL,0,0,0,57);
			SetShotDataA(1,320,2,NULL,0,0,0,57);
			SetShotDataA(1,340,2.2,NULL,0,0,0,57);
				
				FireShot(1);
				
				CreateShotA(1,Obj_GetX(obj)+raa*cos(x), Obj_GetY(obj),10);
		SetShotDataA(1,0,0,90+bb,0,0,0,57);
			SetShotDataA(1,120,0.2,NULL,0,0,0,57);
			SetShotDataA(1,160,0.4,NULL,0,0,0,57);
			SetShotDataA(1,180,0.6,NULL,0,0,0,57);
			SetShotDataA(1,200,0.8,NULL,0,0,0,57);
			SetShotDataA(1,220,1,NULL,0,0,0,57);
			SetShotDataA(1,240,1.2,NULL,0,0,0,57);
			SetShotDataA(1,260,1.4,NULL,0,0,0,57);
			SetShotDataA(1,280,1.6,NULL,0,0,0,57);
			SetShotDataA(1,300,1.8,NULL,0,0,0,57);
			SetShotDataA(1,320,2,NULL,0,0,0,57);
			SetShotDataA(1,340,2.2,NULL,0,0,0,57);
				
				FireShot(1);
	
	}}
	
task spe{
loop(40){
wait(3);
Obj_SetSpeed(obj,Obj_GetSpeed(obj)-0.05);
}

ll(Obj_GetX(obj)+10,0,1);
ll(Obj_GetX(obj)-10,180,1);

ll(Obj_GetX(obj)+10,340,1.3);
ll(Obj_GetX(obj)-10,200,1.3);

ll(Obj_GetX(obj)+10,320,1.6);
ll(Obj_GetX(obj)-10,220,1.6);

ll(Obj_GetX(obj)+10,300,1.9);
ll(Obj_GetX(obj)-10,240,1.9);

PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon01.wav");
yield;

Obj_Delete(obj);


}
	while(!Obj_BeDeleted(obj)){yield;
	Obj_SetAutoDelete(obj,true);
	
spe1;
spe;
 break;
  }}
  
  
  
  
  
  
  let bb=0;
  
  
  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", 8);
    SetAnimationFrame("nue", "idle", 0, imgNue, 8, 14, 0, 51, 63);
    SetAnimationFrame("nue", "idle", 1, imgNue, 8, 77, 0, 114, 64);
    SetAnimationFrame("nue", "idle", 2, imgNue, 8, 141, 0, 177, 64);
    SetAnimationFrame("nue", "idle", 3, imgNue, 8, 205, 0, 241, 65);
	
    SetAnimationFrame("nue", "idle", 4, imgNue, 8, 205, 0, 241, 65);
    SetAnimationFrame("nue", "idle", 5, imgNue, 8, 141, 0, 177, 64);
	 SetAnimationFrame("nue", "idle", 6, imgNue, 8, 77, 0, 114, 64);
	 SetAnimationFrame("nue", "idle", 7, imgNue, 8, 14, 0, 51, 63);
	
	
    CreateAnimation("nue", "start move right", 4);
    SetAnimationFrame("nue", "start move right", 0, imgNue, 8, 12, 65, 54, 125);
    SetAnimationFrame("nue", "start move right", 1, imgNue, 8, 75, 65, 118, 125);
    SetAnimationFrame("nue", "start move right", 2, imgNue, 8, 139, 65, 182, 122);
    SetAnimationFrame("nue", "start move right", 3, imgNue, 8, 203, 65, 246, 122);
    
    CreateAnimation("nue", "stop move right", 4);
    SetAnimationFrame("nue", "stop move right", 0, imgNue, 4, 203, 65, 246, 122);
    SetAnimationFrame("nue", "stop move right", 1, imgNue, 4, 139, 65, 182, 122);
    SetAnimationFrame("nue", "stop move right", 2, imgNue, 4, 75, 65, 118, 125);
    SetAnimationFrame("nue", "stop move right", 3, imgNue, 4, 12, 65, 54, 125);
    
	
	
	
    CreateAnimation("nue", "start move left", 4);
    SetAnimationFrame("nue", "start move left", 0, imgNue, 8, 203, 195, 245, 255);
    SetAnimationFrame("nue", "start move left", 1, imgNue, 8, 139, 195, 182, 255);
    SetAnimationFrame("nue", "start move left", 2, imgNue, 8, 75, 195, 118, 253);
    SetAnimationFrame("nue", "start move left", 3, imgNue, 8, 11, 195, 54, 252);
    
    CreateAnimation("nue", "stop move left", 4);
    SetAnimationFrame("nue", "stop move left", 0, imgNue, 4, 11, 195, 54, 252);
    SetAnimationFrame("nue", "stop move left", 1, imgNue, 4,75, 195, 118, 253);
    SetAnimationFrame("nue", "stop move left", 2, imgNue, 4, 139, 195, 182, 255);
    SetAnimationFrame("nue", "stop move left", 3, imgNue, 4,  203, 195, 245, 255);
    
    CreateAnimation("nue", "start cast", 4);
    SetAnimationFrame("nue", "start cast", 0, imgNue, 4, 14,127,55,191);
    SetAnimationFrame("nue", "start cast", 1, imgNue, 4, 77,127,121,191);
    SetAnimationFrame("nue", "start cast", 2, imgNue, 4, 141,128,182,192);
    SetAnimationFrame("nue", "start cast", 3, imgNue, 4, 204,128,242,192);
    
    
    CreateAnimation("nue", "stop cast", 4);
    SetAnimationFrame("nue", "stop cast", 0, imgNue, 4,204,128,242,192);
    SetAnimationFrame("nue", "stop cast", 1, imgNue, 4,141,128,182,192);
    SetAnimationFrame("nue", "stop cast", 2, imgNue, 4, 77,127,121,191);
    SetAnimationFrame("nue", "stop cast", 3, imgNue, 4, 14,127,55,191);
  } let wa=500;
}




