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

script_enemy_main {
  #include_function ".\AnimationLib.dnh"
 let g=0;
  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 ~ "sn4.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(4500);
	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;
  @MainLoop {
   yield ;
  SetCollisionA(GetX,GetY,10);
  SetCollisionB(GetX,GetY,10);
  if(g==1){
   SetDamageRate(60,40);}else{
   SetDamageRate(60,22);}
    }
  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;
	  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);
	  set;
	     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);
	tp;
	
	task tp{
	
	loop{
	yield;
	 if(GetPlayerX<GetX){
	  Animate("nue", "start move left", false);
	  wait(70);
	   Animate("nue", "stop move left", false);
	    wait(70);}
	   
	   if(GetPlayerX>GetX){
	    Animate("nue", "start move right", false);
	  wait(70);
	   Animate("nue", "stop move right", false);
	    wait(70);}
	
	}
	
	}
	 let fg=0;
	ggg;
	task ggg{
	wait(660);
	  PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_ch02.wav");

	 Concentration02(30);
 Concentration02(40);
 Concentration02(30);let fg=0;
 Concentration02(40);
 Concentration02(30);let anga=0;
 Concentration02(40);
 wait(90);
 st=1;
	}
	loop{
	yield;
	//wait(60);
	
	   SetMovePosition03(GetPlayerX, GetPlayerY, 13, 0.5);
	   
	  
	
	}
	  
	  }
 let st=0;
let ff=0;
let ff2=0;
let gg=0;

let fg=0;
task set{
k;
task k{
bul;
task bul{

loop{wait(60);
ff=rand(100,400);
PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_kira00.wav");
loop(20){
wait(1);


bu(GetClipMinX,ff,2,0);
if(st==1){bu(ff,GetClipMaxY,2,270);}

}

}
}
task bu(x,y,s,an){


let obj2222=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj2222,x);
	Obj_SetY(obj2222,y);
	Obj_SetSpeed(obj2222,s);
	
	
	Obj_SetAngle(obj2222,an);
	
	
	ObjShot_SetBombResist(obj2222,true);
	ObjShot_SetGraphic(obj2222,15);
	ObjShot_SetDelay(obj2222,11);
	Obj_SetAutoDelete(obj2222,true);

	while(!Obj_BeDeleted(obj2222)){yield;
	Obj_SetAutoDelete(obj2222,true);
if(Collision_Obj_Obj(obj2222,qw1)==true){
//PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_kira00.wav");

Obj_SetAngle(obj2222,Obj_GetAngle(obj2222)+rand(-20,20));
Obj_SetSpeed(obj2222,rand(0.5,1));break;
}
}}


 let qw1 = Obj_Create(OBJ_LASER);
    // initial settings
    Obj_SetPosition   (qw1, GetX, GetY);
    Obj_SetAngle      (qw1,45+180);
    ObjLaser_SetWidth (qw1, -5);
	Obj_SetCollisionToPlayer(qw1,false);
    ObjLaser_SetLength (qw1, 130);
    ObjShot_SetGraphic(qw1, 5);
    ObjLaser_SetSource(qw1, false);
  let anglel=0;
  while(!Obj_BeDeleted(qw1)){yield;
	Obj_SetAutoDelete(qw1,true);
wait(60); so2;
PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_lazer00.wav"); ObjShot_SetGraphic(qw1, 4);
  loop(15){yield;
 ObjLaser_SetWidth (qw1, ObjLaser_GetWidth(qw1)+0.9);
  }
  break;
  }
   task so2{

loop{
yield;
Obj_SetPosition   (qw1, GetX, GetY);
Obj_SetAngle      (qw1,Obj_GetAngle      (qw1)+2);
}
}
  
}



let ff2=0;
bul1;
task bul1{

loop{wait(60);
ff2=rand(100,400);
PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_kira00.wav");
loop(20){
wait(1);


bu1(GetClipMaxX,ff2,1.5,180);
if(st==1){bu1(ff2,GetClipMinY,1.5,90);}

}

}
}
task bu1(x,y,s,an){


let obj2222=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj2222,x);
	Obj_SetY(obj2222,y);
	Obj_SetSpeed(obj2222,s);
	
	
	Obj_SetAngle(obj2222,an);
	
	
	ObjShot_SetBombResist(obj2222,true);
	ObjShot_SetGraphic(obj2222,11);
	ObjShot_SetDelay(obj2222,11);
	Obj_SetAutoDelete(obj2222,true);

	while(!Obj_BeDeleted(obj2222)){yield;
	Obj_SetAutoDelete(obj2222,true);
if(Collision_Obj_Obj(obj2222,qw)==true){
//PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_kira00.wav");

Obj_SetAngle(obj2222,atan2(GetPlayerY-Obj_GetY(obj2222),GetPlayerX-Obj_GetX(obj2222)));
Obj_SetSpeed(obj2222,1);
break;}
}}





 let qw = Obj_Create(OBJ_LASER);
    // initial settings
    Obj_SetPosition   (qw, GetX, GetY);
    Obj_SetAngle      (qw,45);
    ObjLaser_SetWidth (qw, -5);
    ObjLaser_SetLength (qw, 130);
    ObjShot_SetGraphic(qw, 5);
    ObjLaser_SetSource(qw, false);
  let anglel=0;
  Obj_SetCollisionToPlayer(qw,false);
  while(!Obj_BeDeleted(qw)){yield;
	Obj_SetAutoDelete(qw,true);
wait(60); so;
PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_lazer00.wav"); ObjShot_SetGraphic(qw, 2);
  loop(15){yield;
 ObjLaser_SetWidth (qw, ObjLaser_GetWidth(qw)+0.9);
  }
  break;
  }
  task so{

loop{
yield;
Obj_SetPosition   (qw, GetX, GetY);
Obj_SetAngle      (qw,Obj_GetAngle      (qw)+2);
}
}}
  
  











  


 
  let i=rand(30,150);
  let sa=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;
}




