#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 sp22= GetCurrentScriptDirectory ~ "sp2.png";
  let spn= GetCurrentScriptDirectory ~ "sn1.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 { bl;
  
  CreateAura01("RED",0,2);
   LoadUserShotData(qwe);
    SetLife(4500);
	SetTimer(40);
    //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);}
 
  }}
  @MainLoop {
   yield ;
  SetCollisionA(GetX,GetY,10);
  SetCollisionB(GetX,GetY,10);
   
    }
  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);
  
  
  

   
  }
  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);
   
  }
  
  
 
  
 
  
  
  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 fur2{
  loop{
  fur;
  wait(wa);
  }}
  
  
  task fur{
  task aa3{
  
  
  wait(70);
  loop(300){
  yield;
  
  CreateShot01(GetX,GetY,rand(12,18),Obj_GetAngle(obj23)+rand(-5,5),205,0);
  CreateShot01(GetX,GetY,rand(12,18),Obj_GetAngle(obj23)+rand(-5,5),201,0);
  
  }
  
  
  
  }
  aa;
  aa2;
  
  
  
  
  aa22;
  task aa22{
 let qw222222 = Obj_Create(OBJ_LASER);
    // initial settings
    Obj_SetPosition   (qw222222, GetX, GetY);
    Obj_SetAngle      (qw222222,GetAngleToPlayer+90);
    ObjLaser_SetWidth (qw222222, -5);
    ObjLaser_SetLength (qw222222, 500);
    ObjShot_SetGraphic(qw222222, 56);
    ObjLaser_SetSource(qw222222, false);
  let anglel=0;
  while(!Obj_BeDeleted(qw222222)){yield;
	Obj_SetAutoDelete(qw222222,true);
wait(60); 
PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_nep00.wav");
  loop(15){yield;
 ObjLaser_SetWidth (qw222222, ObjLaser_GetWidth(qw222222)+1.4);
  }
  loop(300){
  Obj_SetAngle      (qw222222,Obj_GetAngle(qw222222)-0.1);
  yield;
  }
  
  ObjShot_FadeDelete(qw222222);
  }}
  aa222;
  task aa222{
 let qw22222 = Obj_Create(OBJ_LASER);
    // initial settings
    Obj_SetPosition   (qw22222, GetX, GetY);
    Obj_SetAngle      (qw22222,GetAngleToPlayer-90);
    ObjLaser_SetWidth (qw22222, -5);
    ObjLaser_SetLength (qw22222, 500);
    ObjShot_SetGraphic(qw22222, 56);
    ObjLaser_SetSource(qw22222, false);
  let anglel=0;
  while(!Obj_BeDeleted(qw22222)){yield;
	Obj_SetAutoDelete(qw22222,true);
wait(60); 
PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_nep00.wav");
  loop(15){yield;
 ObjLaser_SetWidth (qw22222, ObjLaser_GetWidth(qw22222)+1.4);
  }
  loop(300){
  Obj_SetAngle      (qw22222,Obj_GetAngle(qw22222)+0.1);
  yield;
  }
  
  ObjShot_FadeDelete(qw22222);
  }}
  task aa2{
 let qw2222 = Obj_Create(OBJ_LASER);
    // initial settings
    Obj_SetPosition   (qw2222, GetX, GetY);
    Obj_SetAngle      (qw2222,GetAngleToPlayer-3);
    ObjLaser_SetWidth (qw2222, -5);
    ObjLaser_SetLength (qw2222, 500);
    ObjShot_SetGraphic(qw2222, 46);
    ObjLaser_SetSource(qw2222, false);
  let anglel=0;
  while(!Obj_BeDeleted(qw2222)){yield;
	Obj_SetAutoDelete(qw2222,true);
wait(60); 
PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_nep00.wav");
  loop(15){yield;
 ObjLaser_SetWidth (qw2222, ObjLaser_GetWidth(qw2222)+3.4);
  }
  wait(300);
  ObjShot_FadeDelete(qw2222);
  }}
  aa3;
  task aa{
 let qw222 = Obj_Create(OBJ_LASER);
    // initial settings
    Obj_SetPosition   (qw222, GetX, GetY);
    Obj_SetAngle      (qw222,GetAngleToPlayer+3);
    ObjLaser_SetWidth (qw222, -5);
    ObjLaser_SetLength (qw222, 500);
    ObjShot_SetGraphic(qw222, 56);
    ObjLaser_SetSource(qw222, false);
  let anglel=0;
  while(!Obj_BeDeleted(qw222)){yield;
	Obj_SetAutoDelete(qw222,true);
wait(60); 

ty;
PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_nep00.wav");
  loop(15){yield;
 ObjLaser_SetWidth (qw222, ObjLaser_GetWidth(qw222)+6.4);
  }
  wait(300);
  ObjShot_FadeDelete(qw222);
  }}
  
 let obj23 = Obj_Create(OBJ_LASER);
    // initial settings
    Obj_SetPosition   (obj23, GetX, GetY);
    Obj_SetAngle      (obj23,GetAngleToPlayer);
    ObjLaser_SetWidth (obj23, -5);
    ObjLaser_SetLength (obj23, 500);
    ObjShot_SetGraphic(obj23, 45);
    ObjLaser_SetSource(obj23, true);
  let anglel=0;
  while(!Obj_BeDeleted(obj23)){yield;
	Obj_SetAutoDelete(obj23,true);
wait(60); 
PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_nep00.wav");
  loop(15){yield;
 ObjLaser_SetWidth (obj23, ObjLaser_GetWidth(obj23)+3.4);
  }
  wait(300);
  ObjShot_FadeDelete(obj23);
  }
  
  }
  let sp=0;
  let f=0;
  let as2=0;
  //let ty=0
  
  let rr=0;
  let r=0;
   
  task gh{
  loop{PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_tan01.wav");
  loop(30){
  

  
  CreateShot01(GetX, GetY,1.1,rr+r,41,5);
  rr+=360/30;
  }r+=14.523;
  wait(90);}}
  
  
  task bl{
 
  loop{
  yield;
  if(GetTimer<16){gh;break;}
  }
  
  }
  
  task ty{
  
  
  loop(60){PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_tan01.wav");
  
  loop(2){
  
  CreateShot01(GetX, GetY,0.4+sp,as2+f,250,5);
  CreateShot01(GetX, GetY,0.4+sp,as2-f,250,5);
  as2+=360/2;
  }f+=7.59;sp+=0.04;
  wait(5);
  }sp=0;
  
  
  }
  
  
  
  
  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;
	  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-150, 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;}
	  
	wait(90);
	  
	    Animate("nue", "start cast", false);
	  wait(20);
	   PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_option.wav");
	   SetCommonData("fa",1);
	  CreateEnemyFromScript("fam1",GetX,GetY,0,0,0);
	  
	   SetCommonData("fa",2);
	  CreateEnemyFromScript("fam1",GetX,GetY,0,0,0);
	   SetCommonData("fa",3);
	  CreateEnemyFromScript("fam1",GetX,GetY,0,0,0);
	   SetCommonData("fa",4);
	  CreateEnemyFromScript("fam1",GetX,GetY,0,0,0);
	wait(100);
	fur2;
	  
  }
  
  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;
}






////////////////////////////

script_enemy fam1{let fi=0;
    let gr = GetCurrentScriptDirectory ~ "circle.png";
  let dir=0;
  let r=80;
  @Initialize{
  SetLife(2000);
  LoadGraphic(gr);
  main;
  }
  @MainLoop{yield;
  
  }
  @DrawLoop{
   SetTexture(gr);SetAlpha(150);
 SetGraphicAngle(0,0,-dir*2);
 
	SetGraphicRect(0,0,128,127);
	SetGraphicScale(0.5,0.5);
	DrawGraphic(GetX,GetY);
	 dir+=3;
	SetTexture(gr);SetAlpha(130);
 SetGraphicAngle(0,0,dir);
	SetGraphicRect(0,0,128,127);
	SetGraphicScale(0.3,0.3);
	DrawGraphic(GetX,GetY);
	

  }
  @Finalize{
  
  }
  let angle=0;
  task main{
  fire;
  fire2;
 
  if(GetCommonData("fa")==1){
  SetMovePosition03(GetEnemyX-GetCenterX/3,GetEnemyY,15,2);}
  
  if(GetCommonData("fa")==2){
  SetMovePosition03(GetEnemyX-GetCenterX/3-GetCenterX/3,GetEnemyY,15,2);}
  
  
  if(GetCommonData("fa")==3){
  SetMovePosition03(GetEnemyX+GetCenterX/3,GetEnemyY,15,2);}
  
  if(GetCommonData("fa")==4){
  SetMovePosition03(GetEnemyX+GetCenterX/3+GetCenterX/3,GetEnemyY,15,2);}
  
  loop{
  wait(wa);
  
  fire;
  
  }}
  
  
 
  let angle2=0;
  task f{
  
  fi=1;
  
  }
  task fg{
  loop{yield;a++;}
  }
  let a=0;let s=0;let g=0;
  
  task fir2{
  wait(240);
  
  
  
  
  
  
  }
  //
  let s2=0;
  let a2=0;
  
   task fir22{
  wait(240);
 
  
  
  
  
  
  }
  
  let aq=0;
  //
  
  
 task fire2{
 wait(160);
 
 loop{
 
 aq+=11.7;
 wait(7);
 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_tan01.wav");
 
 if(GetX<GetCenterX){
  CreateShot01(GetX,GetY,1.6,90+aq,67,0);
  CreateShot01(GetX,GetY,1.6,90+aq+180,67,0);
}else{
 
 
 
 CreateShot01(GetX,GetY,1.6,90-aq,67,0);
  CreateShot01(GetX,GetY,1.6,90-aq+180,67,0);

 
 
 
 
 }
 }
 
 
 }
 let yu=0;let yu2=0; let wa=500;
  task fire{
  
  wait(100);
  
 let obj23 = Obj_Create(OBJ_LASER);
    // initial settings
    Obj_SetPosition   (obj23, GetX, GetY);
    Obj_SetAngle      (obj23,90);
    ObjLaser_SetWidth (obj23, -5);
    ObjLaser_SetLength (obj23, wa);
    ObjShot_SetGraphic(obj23, 23);
    ObjLaser_SetSource(obj23, true);
  let anglel=0;
  while(!Obj_BeDeleted(obj23)){yield;
	Obj_SetAutoDelete(obj23,true);
wait(60); 
PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_lazer01.wav");
  loop(15){yield;
 ObjLaser_SetWidth (obj23, ObjLaser_GetWidth(obj23)+1.4);
  }
  wait(300);
  ObjShot_FadeDelete(obj23);
  }}
  
   function wait(t){
    loop(t){yield;}
  }
  }
  



