#TouhouDanmakufu
#Title[Spell04]
#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 {SetEffectForZeroLife(60,200,1);
  CreateAura01("RED",0,2);
   LoadUserShotData(qwe);
    SetLife(9000);
	SetTimer(52);
    //SetY(-120);
	yim;
    LoadGraphic(imgNue);
    LoadGraphic(cir);
    LoadGraphic(Cut);
    LoadGraphic(sp1);
    LoadGraphic(sp2);
    // SetDurableSpellCard;
	 
    InitializeAnimationData;
	  MagicCircle(false);
  
    Animate("nue", "idle", true);
   mus;
    ShowOffNueAnimation;
    // CreateAura01;let aa=0;
  }let aaaaa=0;let qa=0;
  task bul{
  
  
  let obj=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj,GetX);
	Obj_SetY(obj,GetY);
	Obj_SetSpeed(obj,0.5);
	
	
	Obj_SetAngle(obj,aaaaa+qa);

	
	
	ObjShot_SetBombResist(obj,true);
	ObjShot_SetGraphic(obj,152);
	ObjShot_SetDelay(obj,10);
	

	while(!Obj_BeDeleted(obj)){yield;
	Obj_SetAutoDelete(obj,true);
	
wait(60);
loop(60){
wait(3);
Obj_SetSpeed(obj,Obj_GetSpeed(obj)+0.1);
}



break;


  
  }}
  task rag{
  
  
  
  loop(50){yield;wait(2);PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_kira00.wav");
  qa+=20;
  loop(4){
  bul;
  aaaaa+=360/4;
  }
  
  }
 
  
  
  
  
  
  
  
  
  }
  task yim{loop{yield;
  
   if(GetTimer<11&&GetTimer>=0){PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_timeout.wav");wait(60);}
 
  }}let qeq=0;
  @MainLoop {
   yield ;
  SetCollisionA(GetX+qeq,GetY,10);
  SetCollisionB(GetX,GetY,10);
   
    }
  let wave=0;
  let x=0;
  @DrawLoop {
  
  
  
  
  
     SetTexture(imgNue);
	
	 SetAlpha(255);
 
 
 SetGraphicRect(0,0,0,0);
	SetColor(col,col,col);
	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);
   PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_enep01.wav");
  }
  
  
 
  
 
  
  
  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,4,5);
  CreateLaser01(GetX,GetY,3,anglel+al,110,-110,1,0);
  
  
  
 
  
  
  
  
  
  
  
  
  
  anglel+=360/15;
  }
  }let wawa=30;
  let ana=0;let anan=0;
 
  let blan=0;
  let blana=0;
  
  
 
  let soe=0.5;let ttt=0;let angle2=0;
  
  let wy=0;let wan=0;let waii=30;
  
  let col=255;
  
  
  
  let inva=0;
  let inva2=0;
  task invasion{
  
  loop{
  inva=rand_int(1,3);
  inva2=rand_int(1,2);
  if(inva==1){
    
   if(inva2==1){
   CreateEnemyFromScript("fam",GetClipMinX-20,rand(50,300),0,0,0);}
   
    if(inva2==2){
   CreateEnemyFromScript("fam",GetClipMaxX+20,rand(50,300),0,0,0);}
   
   
   }
  
   if(inva==2){
    
    if(inva2==1){
   CreateEnemyFromScript("fam2",GetClipMinX-20,rand(50,300),0,0,0);}
   
    if(inva2==2){
   CreateEnemyFromScript("fam2",GetClipMaxX+20,rand(50,300),0,0,0);}
   

   
   }
  
  if(inva==3){
    
    if(inva2==1){
   CreateEnemyFromScript("fam3",GetClipMinX-20,rand(50,300),0,0,0);}
   
    if(inva2==2){
   CreateEnemyFromScript("fam3",GetClipMaxX+20,rand(50,300),0,0,0);}
   

   
   }
  
  wait(180);
  }
  
  
  }
  
  
  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);
	  Concentration01(180);
	  Concentration02(120);
	  Concentration02(120);
	  	  PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\ch.wav");
      wait(180);
	  
Animate("nue", "start cast", false);
	  wait(5);
 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_cat00.wav");
	 col=0;
	   Explosion01(GetX,GetY,11,1,60);
 Explosion01(GetX,GetY,11,1,60);
 Explosion01(GetX,GetY,6,1,60);
 SetScore(30000);
 cutin("NAZRIN", "| The Last Invasion |",Cut,0,0,411,500);
  PlayMusic(GetCurrentScriptDirectory ~ ".\Sounds\lastw.mp3");
  LastSpell;
 
      wait(60);
      Animate("nue", "stop cast", false);
      wait(16);
      Animate("nue", "idle", true);
      wait(60);
 
	invasion;
	 
	 wait(360);
	   loop{
	   yield;
	   
	   wait(120);rag;
	  SetMovePosition03(GetCenterX+rand(10,80), GetClipMinY+rand(40, 80), 20, 1);
	  
	  
      SetNueMoveAnimation("right");
	    yield ;
      while(GetSpeed>0.1){yield;}
	    wait(120);
	
	

      
	  rag;
	   SetMovePosition03(GetCenterX-rand(10,80), GetClipMinY+rand(40, 80), 13, 1);
     
      SetNueMoveAnimation("left");
	 
	    yield ;
      while(GetSpeed>0.1){yield;}
	    wait(30);
	
	   }
  }
  
  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,0);
	Obj_SetAngle(obj,a);
	ObjShot_SetBombResist(obj,true);
	ObjShot_SetGraphic(obj,203);
	ObjShot_SetDelay(obj,0);
	

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

  
      


	
	
	}}


	
	
	script_enemy fam{
	SetCommonData("speed",0);
	#include_function ".\AnimationLib.dnh"
	let fi=0;
    let imgNue = GetCurrentScriptDirectory ~ "ufo3.png";
  let dir=0;
  let r=0;let asd=0;
  @Initialize{vg;main;
  SetLife(2000);
  LoadGraphic(imgNue);
 
  }let aa=0;
  task db{fi=rand_int(10,60);}
  task vg{
  dir=20;
if(GetX<GetCenterX){SetMovePosition03(GetX+450,GetY,1,1);}
if(GetX>GetCenterX){SetMovePosition03(GetX-450,GetY,1,1);}
   loop(40){
  yield;wait(10); PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_tan01.wav");
  CreateShot01(GetX,GetY,1.5,asd,65,5);
  CreateShot01(GetX,GetY,1.5,asd+180,65,5);
 
  CreateShot01(GetX,GetY,0.5,asd+90,65,5);
  CreateShot01(GetX,GetY,0.5,asd+270,65,5);
 
  asd+=13;
  }
  
  
  }
 
  @MainLoop{yield;
  
  if(GetX<GetEnemyX){aa+=dir;}else{r+=-dir;}
  SetCollisionA(GetX,GetY,20);
  SetCollisionB(GetX,GetY,10);
  }
  
  
 
  
  
  
  
  
  
  
  let tt=0;
  let tt2=0;
  
  @DrawLoop{re=20*cos(6*3);
  
  tt+=77;
  
  tt2=3;
    DrawAnimatedSprite("nue", GetX, GetY);
  }
  let sped=3;let ran=0;
  @Finalize{
  
  }
  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);
    
  
 
  Animate("nue", "idle", true);
  
  
 
 
 wait(450);VanishEnemy;
  
  
  }
  let angle2=0;let re=0;
  task f{
  
  fi=1;
  
  }
 let ae=0;
 
  
   function wait(t){
    loop(t){yield;}
  }
  }
  


	script_enemy fam2{
	SetCommonData("speed",0);
	#include_function ".\AnimationLib.dnh"
	let fi=0;
   
  
	
    let imgNue = GetCurrentScriptDirectory ~ "ufo4.png";
  let dir=0;
  let r=0;let asd=0;
  @Initialize{vg;main;
  SetLife(2000);
  LoadGraphic(imgNue);
 
  }let aa=0;let ass=0;
  task db{fi=rand_int(10,60);}
  task vg{
  dir=20;
if(GetX<GetCenterX){SetMovePosition03(GetX+450,GetY,1,1);}
if(GetX>GetCenterX){SetMovePosition03(GetX-450,GetY,1,1);}
  
loop(6){wait(60);ass+=12;PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_tan01.wav");
  loop(10){
   
 
  
  
  CreateShot01(GetX,GetY,2,asd+ass,101,5);
 
  asd+=360/10;
  }
  }
  
  }
 
  @MainLoop{yield;
  
  if(GetX<GetEnemyX){aa+=dir;}else{r+=-dir;}
  SetCollisionA(GetX,GetY,20);
  SetCollisionB(GetX,GetY,10);
  }
  
  
 
  
  
  
  
  
  
  
  let tt=0;
  let tt2=0;
  
  @DrawLoop{re=20*cos(6*3);
  
  tt+=77;
  
  tt2=3;
    DrawAnimatedSprite("nue", GetX, GetY);
  }
  let sped=3;let ran=0;
  @Finalize{
  
  }
  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);
    
  
 
  Animate("nue", "idle", true);
  
  
 
 
 wait(450);VanishEnemy;
  
  
  }
  let angle2=0;let re=0;
  task f{
  
  fi=1;
  
  }
 let ae=0;
 
  
   function wait(t){
    loop(t){yield;}
  }
  }
  
//////////////////
script_enemy fam3{
	SetCommonData("speed",0);
	#include_function ".\AnimationLib.dnh"
	let fi=0;
    let imgNue = GetCurrentScriptDirectory ~ "ufo5.png";
  let dir=0;
  let r=0;let asd=0;
  @Initialize{vg;main;
  SetLife(2000);
  LoadGraphic(imgNue);
 
  }let aa=0;let sp2=0.6;
  task db{fi=rand_int(10,60);}
  task vg{
  dir=20;
if(GetX<GetCenterX){SetMovePosition03(GetX+450,GetY,1,1);}
if(GetX>GetCenterX){SetMovePosition03(GetX-450,GetY,1,1);}
   loop(16){
   
  yield;wait(60); 
  loop(10){
  PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_tan01.wav");
  CreateShot01(GetX,GetY,sp2,270,11,5);
  CreateShot01(GetX,GetY,sp2,90,11,5);
 
  sp2+=0.4;
  }
  sp2=0.6;
  }
  
  
  }
 
  @MainLoop{yield;
  
  if(GetX<GetEnemyX){aa+=dir;}else{r+=-dir;}
  SetCollisionA(GetX,GetY,20);
  SetCollisionB(GetX,GetY,10);
  }
  
  
 
  
  
  
  
  
  
  
  let tt=0;
  let tt2=0;
  
  @DrawLoop{re=20*cos(6*3);
  
  tt+=77;
  
  tt2=3;
    DrawAnimatedSprite("nue", GetX, GetY);
  }
  let sped=3;let ran=0;
  @Finalize{
  
  }
  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);
    
  
 
  Animate("nue", "idle", true);
  
  
 
 
 wait(450);VanishEnemy;
  
  
  }
  let angle2=0;let re=0;
  task f{
  
  fi=1;
  
  }
 let ae=0;
 
  
   function wait(t){
    loop(t){yield;}
  }
  }
  


