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

script_enemy_main {#include_function ".\Halo.txt"
  #include_function ".\AnimationLib.dnh"
  #include_function ".\function_cutin.txt"
  let imgNue = GetCurrentScriptDirectory ~ "KE.png";
  let Cut = GetCurrentScriptDirectory ~ "TW.png";
  let qwe = GetCurrentScriptDirectory ~ "supershot.txt";
 let cir = GetCurrentScriptDirectory ~ "circle.png";
 let cha = GetCurrentScriptDirectory ~ "ch.png";
 let spbg1 = GetCurrentScriptDirectory ~ "bg1.png";
 let spbg2 = GetCurrentScriptDirectory ~ "bg2.png";
 let name = GetCurrentScriptDirectory ~ "222.png";
 let name2 = GetCurrentScriptDirectory ~ "222.png";
  @Initialize {
  
  CreateAura01("AZURE",0,2);
   LoadUserShotData(qwe);
  
    SetLife(8000);
	SetTimer(50);
    SetDurableSpellCard;
    LoadGraphic(imgNue);
    LoadGraphic(name);
    LoadGraphic(name2);
    LoadGraphic(cir);
    LoadGraphic(cha);
    LoadGraphic(Cut);
    LoadGraphic(spbg1);
    LoadGraphic(spbg2);
    MagicCircle(false);
    InitializeAnimationData;
	
 
  
  
    Animate("nue", "idle", true);
   mus;
    ShowOffNueAnimation;
   //cutin("NAZRIN", "",Cut,0,0,229,485); 
  }
  let po=0;
  let qwer=0;
  task mm{ loop{yield;
	SetMovePosition03(GetX,GetY-10,14,1);
		wait(30);
		SetMovePosition03(GetX,GetY+10,14,1);
		wait(30);
		
		
	
  }}
  let wai=120;
let angleb=0;let aa=0;
  
  @MainLoop {SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
    yield ;
	if(po>1){
	if(GetPlayerY<GetY+150){SetPlayerY(GetY+150);}
		
	
		
		
	
  }
  
  
  
  
  
  
  if(po>30){po=29;
 mm;}
  
  
  
  
  
  
  
  }let wave=0;
  let x=0;let y=0;let z=0;let dir=60;let dor=60; let sa=0;let xxxx=0; let yyyy=0;
  @DrawLoop {
    
	  

	  
	 
	 
	  
	     SetTexture(cir);SetAlpha(150);
 
	SetGraphicRect(0,0,128,127);
	SetGraphicScale(2+sin(wave)*0.2,2+sin(wave)*0.2);

wave+=3;x+=3;
	SetGraphicAngle(0, 0, x);
	DrawGraphic(GetX,GetY);
	
	
	 SetTexture(cir);SetAlpha(90);
 
	SetGraphicRect(0,0,128,127);
	SetGraphicScale(2.3+sin(wave)*0.2,2.3+sin(wave)*0.2);


	SetGraphicAngle(0, 0, -x);
	DrawGraphic(GetX,GetY);
	
	 SetTexture(cir);SetAlpha(40);
 
	SetGraphicRect(0,0,128,127);
	SetGraphicScale(2.6+sin(wave)*0.2,2.6+sin(wave)*0.2);


	SetGraphicAngle(0, 0, x);
	DrawGraphic(GetX,GetY);
	
   //////
   //GetX + dir*cos(dor), GetY + dir*sin(dor);
   

	
  
  
   
    SetTexture(imgNue);SetAlpha(255);SetGraphicScale(1,1);SetRenderState(ALPHA);
	  SetGraphicAngle(y, 0, 0);
    
	
	    SetTexture(name);SetAlpha(250);
 
	SetGraphicRect(0,0,325,36);
	SetGraphicScale(1,1);


	SetGraphicAngle(0, 0, 0);
	DrawGraphic(xxxx-150,230+yyyy);
	
	
	 dor+=6;
    DrawAnimatedSprite("nue", GetX, GetY+5*sin(dor));
	
	
  }let yyt=0;
  @BackGround{
  
 
	
	
  
   
	
///	
	
	
	
	///
	
	  SetTexture(spbg2);SetAlpha(170);
 //SetRenderState(ADD);
	SetGraphicRect(0,0,512,512);
	SetGraphicScale(1+0.02*sin(dor),1+0.02*sin(dor));
//SetRenderState(ALPHA);

	SetGraphicAngle(0, 0, 0);
	DrawGraphic(GetCenterX,GetCenterY);
	
	
	
  
SetTexture(spbg1);SetAlpha(120);
	//SetRenderState(ADD);
 SetColor(210,210,230);
	SetGraphicRect(0,0,256,256);
	SetGraphicScale(1.7,1.8);
SetGraphicAngle(0, 0, 0);

	
	DrawGraphic(GetCenterX,GetCenterY);
	
  z=z+2;
  }let as=0;
 task charge{
 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_ch02.wav");
 Concentration02(30);
 Concentration02(40);
 Concentration02(30);
 Concentration02(40);
 Concentration02(30);
 Concentration02(40);
 wait(60);
 }
  task mus{}
  @Finalize {
    DeleteGraphic(imgNue);
   
  }
  let ab=0;let ang=0;

 
let angle2=0;let te=0;

  task ShowOffNueAnimation {
 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_fault.wav");
let xc=60;


	 SetMovePosition03(GetCenterX, GetCenterY-90, 20, 4);
	 if(GetEnemyX<GetCenterX){
      SetNueMoveAnimation("right");}
	   if(GetEnemyX>GetCenterX){
      SetNueMoveAnimation("left");}
      yield ;
      while(GetSpeed>0.1){yield;}
	wait(90);
	
	 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_ch02.wav");
 Concentration02(30);
 Concentration02(40);
 Concentration02(30);
 Concentration02(40);
 Concentration02(30);
 Concentration02(40);wait(90);
	Animate("nue", "start cast", false);
     wait(20);
	 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_cat00.wav");
	  cutin("NAZRIN", " '' Bogus Hourai Elixir '' ",Cut,0,0,519,521); 
	 // MotionBlurEx(ALL,180,50,ALPHA);
	   SetScore(30000);
	   
	  
	  
	wait(20);
	
	wait(30);
	   Animate("nue", "stop cast", false);
	   wait(20);
	   Animate("nue", "idle", true);
	 
	  wait(20);
	
	
	
	
	SetMovePosition03(GetCenterX, GetCenterY-40, 20, 4);
      SetNueMoveAnimation("right");
      
      yield ;
      while(GetSpeed>0.1){yield;}
	
	 wait(90);
	 Animate("nue", "start cast", false);te=rand(-40,40);
	 wait(20);
 PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_option.wav");
	CreateEnemyFromScript("fam2",GetX,GetY,0,0,0);
	CreateEnemyFromScript("fam22",GetX,GetY,0,0,0);
	
	
	 wait(60);
	   Animate("nue", "stop cast", false);
	   wait(30);
	   Animate("nue", "idle", false);
	
	wait(60);
	
	
	loop {yield ;  
	
	
	SetMovePosition03(GetCenterX-rand(50, 100), GetClipMinY+rand(100, 150), 20, 4);
       SetNueMoveAnimation("left");
      
      yield ;
      while(GetSpeed>0.1){yield;}
	  wait(30);
	 Animate("nue", "start cast", false);
	wait(20);ang+=34;
	te=rand(-40,40);
	 loop(10){wait(5);PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_kira00.wav");
	 arrow(angle2+ang,58+ab);
	 ab+=1;
	 angle2+=6;
	 }ab=0;
	wait(60);
	   Animate("nue", "stop cast", false);
	   wait(30);
	   Animate("nue", "idle", false);
	
	
	  wait(60);
	
	
	SetMovePosition03(GetCenterX+rand(50, 100), GetClipMinY+rand(100, 150), 20, 4);
      SetNueMoveAnimation("right");
      
      yield ;
      while(GetSpeed>0.1){yield;}
	
	 wait(30);
	 Animate("nue", "start cast", false);
te=rand(-40,40);
	 wait(20);ang+=23;
	 loop(10){wait(5);PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_kira00.wav");
	 arrow(angle2+ang,58+ab);
	 ab+=1;
	 angle2+=6;
	 }ab=0;
	 
	 wait(60);
	   Animate("nue", "stop cast", false);
	   wait(30);
	   Animate("nue", "idle", false);
	
	wait(60);
	
	
	
	
	}
	
	
	
  }
  
  
  let x2=0;let angleg=0;
  let ob=0;let angla=0;
  
  
  
  function wait(t){
    loop(t){yield;}
  }
  
sub InitializeAnimationData {
 CreateAnimation("nue", "idle", 1);
    SetAnimationFrame("nue", "idle", 0, imgNue,38, 10, 10, 55, 75);
  
   
    
    CreateAnimation("nue", "start move right", 4);
  SetAnimationFrame("nue", "start move right", 0, imgNue, 8, 13,86, 56, 158);
	SetAnimationFrame("nue", "start move right", 1, imgNue, 8, 77,86, 120, 154);
	
	SetAnimationFrame("nue", "start move right", 2, imgNue, 8, 138,82, 185, 154);
	SetAnimationFrame("nue", "start move right", 3, imgNue, 8, 200,82, 249, 151);
    
    CreateAnimation("nue", "stop move right", 4);
   SetAnimationFrame("nue", "stop move right", 0, imgNue, 8, 200,82, 249, 151);
   SetAnimationFrame("nue", "stop move right", 1, imgNue, 8, 138,82, 185, 154);
   SetAnimationFrame("nue", "stop move right", 2, imgNue, 8, 77,86, 120, 154);
   SetAnimationFrame("nue", "stop move right", 3, imgNue, 8, 13,86, 56, 158);
   
   
   
   
     
    CreateAnimation("nue", "start move left", 4);
  SetAnimationFrame("nue", "start move left", 0, imgNue, 8, 462,88, 506, 156);
	SetAnimationFrame("nue", "start move left", 1, imgNue, 8, 398,85, 441, 154);
	
	SetAnimationFrame("nue", "start move left", 2, imgNue, 8, 334,82, 382, 154);
	SetAnimationFrame("nue", "start move left", 3, imgNue, 8, 270,82, 318, 151);
    
   
    CreateAnimation("nue", "stop move left", 4);
   SetAnimationFrame("nue", "stop move left", 0, imgNue, 8, 270,82, 318, 151);
   SetAnimationFrame("nue", "stop move left", 1,imgNue, 8, 334,82, 382, 154);
   SetAnimationFrame("nue", "stop move left", 2, imgNue, 8, 398,85, 441, 154);
   SetAnimationFrame("nue", "stop move left", 3, imgNue, 8, 462,88, 506, 156);
   
   
   
   
    CreateAnimation("nue", "start cast", 4);
    SetAnimationFrame("nue", "start cast", 0, imgNue, 7   , 12, 165,55,235);
    SetAnimationFrame("nue", "start cast", 1, imgNue, 7    ,70, 165,120,235);
	
    SetAnimationFrame("nue", "start cast", 2, imgNue, 7    ,133, 165,184,234);
    SetAnimationFrame("nue", "start cast", 3, imgNue, 7    ,196, 165,247,235);
    
   

    
    CreateAnimation("nue", "stop cast", 4);
    SetAnimationFrame("nue", "stop cast", 0, imgNue, 7    ,196, 165,247,235);
  SetAnimationFrame("nue", "stop cast", 1,imgNue, 9    ,133, 165,184,234);
  SetAnimationFrame("nue", "stop cast", 2,imgNue, 9    ,70, 165,120,235);
  SetAnimationFrame("nue", "stop cast", 3, imgNue, 9   , 12, 165,55,235);
  
  }
   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);
  }
  
  
  
  
  task arrow(ang,gr){
  
  
  task lk{
  
   let obj2222 = Obj_Create(OBJ_LASER);

    // initial settings
    Obj_SetPosition   (obj2222, Obj_GetX(obj22), Obj_GetY(obj22));
    Obj_SetAngle      (obj2222, atan2(GetPlayerY - Obj_GetY(obj2222), GetPlayerX - Obj_GetX(obj2222)));
	
    ObjLaser_SetWidth (obj2222, -6);
    ObjLaser_SetLength (obj2222, 300);
    ObjShot_SetGraphic(obj2222, gr);
    ObjLaser_SetSource(obj2222, false);
  
  let anglel=0;
  while(!Obj_BeDeleted(obj2222)){yield;
	//Obj_SetAutoDelete(obj2222,true);
  //wait(60);
  //Obj_Delete(obj2222);
  
 
  
  
wait(60); 
 

PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_lazer01.wav");
  loop(10){yield;
 ObjLaser_SetWidth (obj2222, ObjLaser_GetWidth(obj2222)+3);
 //ObjLaser_SetLength (obj2222, ObjLaser_GetLength(obj2222)+0);
  
  }
  wait(60);
ObjShot_FadeDelete(obj2222);
  
  }}
  
  task lasar{
  
  
  
  
   let obj = Obj_Create(OBJ_LASER);

    // initial settings
    Obj_SetPosition   (obj, Obj_GetX(obj22), Obj_GetY(obj22));
    Obj_SetAngle      (obj,  atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj)));
	
    ObjLaser_SetWidth (obj, -6);
    ObjLaser_SetLength (obj, 900);
    ObjShot_SetGraphic(obj, gr);
    ObjLaser_SetSource(obj, false);
  
  let anglel=0;
  while(!Obj_BeDeleted(obj)){yield;
	//Obj_SetAutoDelete(obj,true);
  //wait(60);
  //Obj_Delete(obj);
  
 
  
  
wait(60); 
 

PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_lazer01.wav");
  loop(10){yield;
 ObjLaser_SetWidth (obj, ObjLaser_GetWidth(obj)+3);
 //ObjLaser_SetLength (obj, ObjLaser_GetLength(obj)+0);
  
  }
  wait(60);
ObjShot_FadeDelete(obj);
  
  }
  sa+=23;
  PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_tan00.wav");
  loop(5){
  
  CreateShot01(Obj_GetX(obj22),Obj_GetY(obj22),0.5,as+sa,157,10);
  as+=360/5;
  
  
  }
  
  Obj_Delete(obj22);
  
  
  
  
  
  }
  
  
  
  
  
  
  let obj22=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj22,GetX);
	Obj_SetY(obj22,GetY);
	Obj_SetSpeed(obj22,2);
	
	
	Obj_SetAngle(obj22,ang);
	
	
	ObjShot_SetBombResist(obj22,true);
	ObjShot_SetGraphic(obj22,gr);
	ObjShot_SetDelay(obj22,0);
	task glow{
	loop{
	wait(50);
	if(Obj_GetSpeed(obj22)!=0){
	CreateShot01(Obj_GetX(obj22),Obj_GetY(obj22),11.5,as+sa,rand_int(170,178),15);
	}
	
	}
	}

	while(!Obj_BeDeleted(obj22)){yield;
	Obj_SetAutoDelete(obj22,true);
	glow;
	if(Obj_GetX(obj22)>GetClipMaxX){Obj_SetSpeed(obj22,0);
	
  lasar; break;}
  if(Obj_GetX(obj22)<GetClipMinX){Obj_SetSpeed(obj22,0);
  lasar; break;}
  if(Obj_GetY(obj22)>GetClipMaxY){Obj_SetSpeed(obj22,0);
  lasar; break;}
  if(Obj_GetY(obj22)<GetClipMinY){Obj_SetSpeed(obj22,0);
  lasar; break;}wait(5);
 
  
  
  
  
  
  
  
  
  
  
  }}
  
  
  
  
  
  let asasa=rand(-40,40);
  let asasa2=rand(-60,60);
  let asasa3=rand(-80,80);
  
}





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

  }
  @Finalize{
   PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_enep01.wav");
   wait(60);
    PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_playerdead.wav");
  }
  let angle=0;
  task main{
  fire;
  f; 
  loop{yield;
  
  SetMovePosition03(GetCenterX-30*cos(dir),GetCenterY-40+30*sin(dir),5,3);
  
  dir+=2;
  
  }
   loop(180){yield; dir+=2;
  }}
  let angle2=0;
  task f{
  
  fi=1;
  
  }
  task fg{
  loop{yield;a++;}
  }
  let a=0;let s=0;let g=0;
  task fire{
  fg;
 
 

 wait(40);
  loop{a+=10;
  wait(10);angle2=rand(0,360);s=rand_int(1,3);PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_tan01.wav");
 
  CreateShot01(GetX,GetY,1.5,-a,35,0);
  CreateShot01(GetX,GetY,1.5,-a+180,35,0);
 
  
  // CreateShot01(GetX,GetY,3.5,90,41,5);
  //CreateShot01(GetX,GetY,3.5,90+90,41,5);
  //CreateShot01(GetX,GetY,3.5,90+90+90,41,5);
 // CreateShot01(GetX,GetY,3.5,0,41,5);
 
 //CreateShot01(GetX,GetY,2.5,90-a/1.3,41,5);
  
  
  
  
  
  
  
  }
  
  
  
  }
  
   function wait(t){
    loop(t){yield;}
  }
  }
  


  

  

script_enemy fam22{let fi=0;
    let gr = GetCurrentScriptDirectory ~ "circle2.png";
  let dir=0;
  let r=80;
  @Initialize{
  SetLife(2000);
  LoadGraphic(gr);
  main;
  }
  @MainLoop{yield;
  
  }
  @DrawLoop{
   SetTexture(gr);SetAlpha(190);
 SetGraphicAngle(0,0,-dir*2);
 
	SetGraphicRect(0,0,128,127);
	SetGraphicScale(0.5,0.5);
	DrawGraphic(GetX,GetY);
	
	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;
  f; 
  loop{yield;
  
  SetMovePosition03(GetCenterX+30*cos(dir),GetCenterY-40-30*sin(dir),5,13);
  
  dir+=2;
  
  }
   loop(180){yield; dir+=2;
  }}
  let angle2=0;
  task f{
  
  fi=1;
  
  }
  task fg{
  loop{yield;a++;}
  }
  let a=0;let s=0;let g=0;
  task fire{
  fg;
 
 

 wait(40);
  loop{a+=10;
  wait(10);angle2=rand(0,360);s=rand_int(1,3);PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_tan01.wav");
 
  CreateShot01(GetX,GetY,1.5,-a,35,0);
  CreateShot01(GetX,GetY,1.5,-a+180,35,0);
 
  
  // CreateShot01(GetX,GetY,3.5,90,41,5);
  //CreateShot01(GetX,GetY,3.5,90+90,41,5);
  //CreateShot01(GetX,GetY,3.5,90+90+90,41,5);
 // CreateShot01(GetX,GetY,3.5,0,41,5);
 
 //CreateShot01(GetX,GetY,2.5,90-a/1.3,41,5);
  
  
  
  
  
  
  
  }
  
  
  
  }
  
   function wait(t){
    loop(t){yield;}
  }
  }
  


  

  







