#TouhouDanmakufu
#Title[Spell01]
#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 Cut = GetCurrentScriptDirectory ~ "NueCut.png";
 #include_function ".\function_cutin.txt"
  #include_function ".\Halo.txt"
  @Initialize { PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_cat00.wav");
  CreateAura01("RED",0,2);
   LoadUserShotData(qwe);
    SetLife(4500);
	SetTimer(40);
    //SetY(-120);
	yim;
    LoadGraphic(imgNue);
    LoadGraphic(cir);
    LoadGraphic(Cut);
    LoadGraphic(sp1);
    LoadGraphic(sp2);
    // SetDurableSpellCard;
	 SetScore(30000);
    InitializeAnimationData;
	  MagicCircle(false);
  cutin("NAZRIN", "Terror Sign | Black And White |",Cut,0,0,411,500);
    Animate("nue", "idle", true);
   mus;
    ShowOffNueAnimation;
    // CreateAura01;
  }
  
  task yim{loop{yield;
  
   if(GetTimer<11&&GetTimer>=0){PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_timeout.wav");wait(60);}
 
  }}
  @MainLoop {
   yield ;
  SetCollisionA(GetX,GetY,10);
  SetCollisionB(GetX,GetY,10);
   
    }
  let wave=0;
  let x=0;
  @DrawLoop {
  
  
  
  
  
     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);
  
  
  

   
  }
  task mus{PlayMusic(GetCurrentScriptDirectory ~ ".\Sounds\Nue1.mp3");}
  
  
  
   @BackGround{
  
 
	 
	
  
   
  
      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);
	
	
	
	
  }
  
  
  
  
  @Finalize {
    DeleteGraphic(imgNue);
   
  }
  
  
 
  
 
  
  
  let anglel=0;let al=0;
  task las{
  PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_lazer01.wav");al+=39;
  loop(15){
  CreateLaser01(GetX,GetY,3,anglel+al,300,15,1,5);
  CreateLaser01(GetX,GetY,3,anglel+al,110,-110,1,0);
  
  
  
 
  
  
  
  
  
  
  
  
  
  anglel+=360/15;
  }
  }
  
  
  task ShowOffNueAnimation {
  wait(60);
   if(GetX>GetCenterX){
	SetMovePosition03(GetCenterX, GetCenterY-50, 13, 4);
      SetNueMoveAnimation("left");}
	   if(GetX<GetCenterX){
	SetMovePosition03(GetCenterX, GetCenterY-50, 13, 4);
      SetNueMoveAnimation("right");}
	    if(GetX==GetCenterX){
	SetMovePosition03(GetCenterX, GetCenterY-50, 13, 4);
      SetNueMoveAnimation("right");}
      yield ;
      while(GetSpeed>0.1){yield;}

      wait(30);
	  Concentration02(60);
	  	  PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_ch02.wav");
      wait(120);SetCommonData("count",rand_int(1,5));
      Animate("nue", "start cast", false);
	  wait(20); PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon01.wav");
	     CreateEnemyFromScript("fam",GetX,GetY,0,0,0);
	     CreateEnemyFromScript("fam2",GetX,GetY,0,0,0);
		 wait(20); 
		  Animate("nue", "stop cast", false);
	  wait(20);
	   Animate("nue", "idle", true);
	   wait(320);
	   loop{
	   yield;
	   SetMovePosition03(GetCenterX-rand(90,10), GetCenterY-rand(100,10), 13, 4);
      SetNueMoveAnimation("left");
	    yield ;
      while(GetSpeed>0.1){yield;}
	    wait(30);
	  Concentration02(60);
	  	  PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_ch02.wav");
      wait(100);
      Animate("nue", "start cast", false);SetCommonData("count",rand_int(1,5));
	  wait(20); PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon01.wav");
	  las;
	     CreateEnemyFromScript("fam",GetX,GetY,0,0,0);
	     CreateEnemyFromScript("fam2",GetX,GetY,0,0,0);
		 wait(20); 
		  Animate("nue", "stop cast", false);
	  wait(20);
	   Animate("nue", "idle", true);
	   wait(320);
	   SetMovePosition03(GetCenterX+rand(90,10), GetCenterY-rand(100,10), 13, 4);
      SetNueMoveAnimation("right");
	    yield ;
      while(GetSpeed>0.1){yield;}
	    wait(30);
	  Concentration02(60);
	  	  PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_ch02.wav");
      wait(100);
      Animate("nue", "start cast", false);SetCommonData("count",rand_int(1,5));
	  wait(20); PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_boon01.wav");
	  las;
	     CreateEnemyFromScript("fam",GetX,GetY,0,0,0);
	     CreateEnemyFromScript("fam2",GetX,GetY,0,0,0);
		 wait(20); 
		  Animate("nue", "stop cast", false);
	  wait(20);
	   Animate("nue", "idle", true);
	   wait(320);
	   }
  }
  
  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", 5);
    SetAnimationFrame("nue", "start cast", 0, imgNue, 4, 0,336,96,448);
    SetAnimationFrame("nue", "start cast", 1, imgNue, 4, 96,336,192,448);
    SetAnimationFrame("nue", "start cast", 2, imgNue, 4, 192,336,288,448);
    SetAnimationFrame("nue", "start cast", 3, imgNue, 4, 288,336,384,448);
    SetAnimationFrame("nue", "start cast", 4, imgNue, 4, 384,336,480,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);
 
  }
}


















let obj=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj,GetX);
	Obj_SetY(obj,GetY);
	Obj_SetSpeed(obj,5);
	Obj_SetAngle(obj,rand(0,360));
	ObjShot_SetBombResist(obj,true);
	ObjShot_SetGraphic(obj,203);
	ObjShot_SetDelay(obj,10);
	

	while(!Obj_BeDeleted(obj)){yield;
	Obj_SetAutoDelete(obj,true);
	

  if(Obj_GetX(obj)<GetClipMinX) 
         {Obj_SetAngle(obj,180-Obj_GetAngle(obj));
                       
         
                    }

                    if(Obj_GetX(obj)>GetClipMaxX) 
         { Obj_SetAngle(obj,180-Obj_GetAngle(obj));
                        
           
                    }

      


	
	
	}}


	
	
	script_enemy fam{
	
	#include_function ".\AnimationLib.dnh"
	let fi=0;
    let imgNue = GetCurrentScriptDirectory ~ "ufo.png";
  let dir=0;
  let r=10;
  @Initialize{
  SetLife(2000);
  LoadGraphic(imgNue);
  main;
  }
  @MainLoop{yield;
  SetCollisionA(GetX,GetY,20);
  SetCollisionB(GetX,GetY,10);
  }
  @DrawLoop{
    DrawAnimatedSprite("nue", GetX, GetY);
  }
  let sped=3;let ran=0;let spp=1;
  @Finalize{
  ran=rand(0,360);
 
  angle2=0;
  spp+=rand(10,333);
  loop(30){
  
  
 
 CreateShotA(11,GetX,GetY,0);
   SetShotDataA(11,0,0.5,angle2+spp,0,0,0,149);
   SetShotDataA(11,10,0.7,NULL,0,0,0,149);
   SetShotDataA(11,20,0.9,NULL,0,0,0,149);
   SetShotDataA(11,30,1.1,NULL,0,0,0,149);
   SetShotDataA(11,40,1.3,NULL,0,0,0,149);
   SetShotDataA(11,50,1.5,NULL,0,0,0,149);
   SetShotDataA(11,60,1.7,NULL,0,0,0,149);
   
   FireShot(11);
   
   
  angle2+=360/30;
  
 
  }
  
  
    
  loop(30){
  
  
 
 CreateShotA(111,GetX,GetY,0);
   SetShotDataA(111,0,0.2,angle2+spp+90,0,0,0,149);
   SetShotDataA(111,10,0.4,NULL,0,0,0,149);
   SetShotDataA(111,20,0.6,NULL,0,0,0,149);
   SetShotDataA(111,30,0.8,NULL,0,0,0,149);
   SetShotDataA(111,40,1.0,NULL,0,0,0,149);
   SetShotDataA(111,50,1.2,NULL,0,0,0,149);
   SetShotDataA(111,60,1.4,NULL,0,0,0,149);
   
   FireShot(111);
   
   
  angle2+=360/30;
  
 
  }
  
  }
  let angle=0;
  task main{
    CreateAnimation("nue", "idle", 4);
    SetAnimationFrame("nue", "idle", 0, imgNue, 12, 0, 143, 65, 198);
    SetAnimationFrame("nue", "idle", 1, imgNue, 12, 65, 143, 130, 198);
    SetAnimationFrame("nue", "idle", 2, imgNue, 12, 130, 143, 195, 198);
    SetAnimationFrame("nue", "idle", 3, imgNue, 12, 195, 143, 255, 198);
    
  
  fire;
  f;
  Animate("nue", "idle", true);
  loop{yield;
  
 
  SetMovePosition03(GetEnemyX+r*cos(dir),GetEnemyY+r*sin(dir),1,10);
  dir+=3;
  r+=0.2;
  if(GetCommonData("count")==1)  {a+=r/20;}
  if(GetCommonData("count")==2)  {a+=r/25;}
  if(GetCommonData("count")==3)  {a+=r/30;}
  if(GetCommonData("count")==4)  {a+=r/35;}
  if(GetCommonData("count")==5)  {a+=r/40;}
  }
  
  }
  let angle2=0;
  task f{
  
  fi=1;
  
  }
  task fire2{PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_lazer01.wav");
  loop(10){
      CreateLaserC(1, GetX+rand(20,-20), GetY-20, 30, 40, 192, 0);
          SetLaserDataC(1, 0,rand(0.5,3), rand(0,180), rand(-0.05,0.05), 0.15, 10);
          
        
          FireShot(1); 
  
  }}let ae=0;
  task fg{
  loop{yield;a++;}
  }
  let a=0;let s=0;let angle=0;let sp=0.5;
  task fire{
 loop(60){
 yield;
 sp+=0.01;
 wait(5);
 //PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_tan00.wav");

  CreateShot01(GetX,GetY,2,GetAngle+90,69,30);
 
 loop(3){
    CreateShotA(12,GetX,GetY,0);
   SetShotDataA(12,0,0.5,-ae+a+180,0,0,0,54);
   SetShotDataA(12,30,0.7,NULL,0,0,0,54);
   SetShotDataA(12,4,0.9,NULL,0,0,0,54);
   SetShotDataA(12,50,1.1,NULL,0,0,0,54);
   SetShotDataA(12,60,1.3,NULL,0,0,0,54);
   SetShotDataA(12,70,1.5,NULL,0,0,0,54);
   FireShot(12);
  
  ae+=360/3;
  }
 }sp=0.5;SetLife(0);
 
  }
  
  
  
  
  
  
  
  
  
  
  
   function wait(t){
    loop(t){yield;}
  }
  }
  




script_enemy fam2{
	
	#include_function ".\AnimationLib.dnh"
	let fi=0;
    let imgNue = GetCurrentScriptDirectory ~ "ufo.png";
  let dir=0;
  let r=10;
  @Initialize{
  SetLife(2000);
  LoadGraphic(imgNue);
  main;
  }
  @MainLoop{yield;
  SetCollisionA(GetX,GetY,20);
  SetCollisionB(GetX,GetY,10);
  }
  @DrawLoop{
    DrawAnimatedSprite("nue", GetX, GetY);
  }
 let sped=3;let ran=0;let spp=1;
  @Finalize{
  ran=rand(0,360);
 
  angle2=0;
  spp=1;
    loop(20){
  loop(15){
  
 
 CreateShotA(11,GetX,GetY,0);
   SetShotDataA(11,0,spp,angle2,1.5,0,0,179);
   SetShotDataA(11,60,spp,NULL,0,0,0,179);
   FireShot(11);
   
   
  angle2+=360/15;
  }
  spp+=0.1;
  }
  
  
  spp=1;
   loop(10){
  loop(15){
  
 
 CreateShotA(11,GetX,GetY,0);
   SetShotDataA(11,0,spp,angle2,-1.5,0,0,179);
   SetShotDataA(11,60,spp,NULL,0,0,0,179);
   FireShot(11);
   
   
  angle2+=360/15;
  }
  spp+=0.07;
  }
  
  
  
  
  
  
  
  
  
  }
  let angle=0;
  task main{
    CreateAnimation("nue", "idle", 4);
    SetAnimationFrame("nue", "idle", 0, imgNue, 12, 0, 200, 65, 255);
    SetAnimationFrame("nue", "idle", 1, imgNue, 12, 65, 200, 130, 255);
    SetAnimationFrame("nue", "idle", 2, imgNue, 12, 130, 200, 195, 255);
    SetAnimationFrame("nue", "idle", 3, imgNue, 12, 195, 200, 255, 255);
    
  
  fire;
  f;
  Animate("nue", "idle", true);
   loop{yield;
  
 
  SetMovePosition03(GetEnemyX-r*cos(dir),GetEnemyY-r*sin(dir),1,10);
  dir+=3;
  
  
  r+=0.2;
   if(GetCommonData("count")==1)  {a+=r/20;}
  if(GetCommonData("count")==2)  {a+=r/25;}
  if(GetCommonData("count")==3)  {a+=r/30;}
  if(GetCommonData("count")==4)  {a+=r/35;}
  if(GetCommonData("count")==5)  {a+=r/40;}
  }
  
  }
  let angle2=0;
  task f{
  
  fi=1;
  
  }let ae=0;
  task fire2{PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_lazer01.wav");
  loop(10){
      CreateLaserC(1, GetX+rand(20,-20), GetY-20, 30, 40, 192, 0);
          SetLaserDataC(1, 0,rand(0.5,3), rand(0,180), rand(-0.05,0.05), 0.15, 10);
          
        
          FireShot(1); 
  
  }}
  task fg{
  loop{yield;a++;}
  }
  let a=0;let s=0;let angle=0;let sp=0.5;
  task fire{
 loop(60){
 yield;
 sp+=0.01;
 
 wait(5);PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_tan00.wav");

 CreateShot01(GetX,GetY,2,GetAngle+90,137,30);
 
  
  //CreateShot01(GetX,GetY,sp,a+270,67,0);
  //CreateShot01(GetX,GetY,sp,a,67,0);
  
  loop(3){
    CreateShotA(12,GetX,GetY,0);
   SetShotDataA(12,0,0.5,ae+a,0,0,0,120);
   SetShotDataA(12,30,0.7,NULL,0,0,0,120);
   SetShotDataA(12,4,0.9,NULL,0,0,0,120);
   SetShotDataA(12,50,1.1,NULL,0,0,0,120);
   SetShotDataA(12,60,1.3,NULL,0,0,0,120);
   SetShotDataA(12,70,1.5,NULL,0,0,0,120);
   FireShot(12);
  
  ae+=360/3;
  }

 
 }sp=0.5;SetLife(0);
 
  }
  
  
  
  
  
  
  
  
  
  
  
   function wait(t){
    loop(t){yield;}
  }
  }

	
	
	



	
	
	
