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

script_enemy_main {
  #include_function ".\AnimationLib.dnh"
  #include_function ".\function_cutin.txt"
  let imgNue = GetCurrentScriptDirectory ~ "KE.png";
  let Cut = GetCurrentScriptDirectory ~ "KeCut.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";
  @Initialize {
  cutin("NAZRIN", "Defense Sign ''Great Wall Of China''",Cut,0,0,292,512);
  
   LoadUserShotData(qwe);
   SetScore(30000);
    SetLife(8000);
	SetTimer(50);
    SetDurableSpellCard;
    LoadGraphic(imgNue);
    LoadGraphic(cir);
    LoadGraphic(cha);
    LoadGraphic(Cut);
    LoadGraphic(spbg1);
    LoadGraphic(spbg2);
    MagicCircle(false);
    InitializeAnimationData;
	
 
  
  
    Animate("nue", "idle", true);
   mus;
    ShowOffNueAnimation;
    
  }
  let po=0;
  
  task mm{ loop{yield;
	SetMovePosition03(GetX,GetY-10,14,1);
		wait(30);
		SetMovePosition03(GetX,GetY+10,14,1);
		wait(30);
		
		
	
  }}
  @MainLoop {SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
    yield ;
	if(po>1){
	if(GetPlayerY<GetY+150){SetPlayerY(GetY+150);}
		
		ae-=0.004;
		
		
	
  }
  
  
  
  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;
  @DrawLoop {
    
	  
	  
	 
	 
	  
	  
	  
	   SetTexture(cir);SetAlpha(150);
 
	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);
   
   //////
   //GetX + dir*cos(dor), GetY + dir*sin(dor);
   

	 
   
  
  
   
    SetTexture(imgNue);SetAlpha(255);SetGraphicScale(1,1);SetRenderState(ALPHA);
	  SetGraphicAngle(y, 0, 0);
    DrawAnimatedSprite("nue", GetX, GetY);
  }
  @BackGround{
  
 
	
	
  
  
  
  SetTexture(spbg1);SetAlpha(255);
 SetColor(210,210,230);
	SetGraphicRect(0,0,256,256);
	SetGraphicScale(2,2);


	
	DrawGraphic(GetCenterX,GetCenterY);
	
	 SetTexture(spbg2);SetAlpha(150);
 
	SetGraphicRect(0,0,16000,16000);
	SetGraphicScale(1,1);


	SetGraphicAngle(0, 0, 0);
	DrawGraphic(GetCenterX-z/2,GetCenterY-z);
	 SetTexture(spbg2);SetAlpha(150);
 
	SetGraphicRect(0,0,16000,16000);
	SetGraphicScale(1,1);


	SetGraphicAngle(0, 0, 0);
	DrawGraphic(GetCenterX-z/2,GetCenterY-z);
  z=z+2;
  }
 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);
   
  }
  
  
  task FI{
  if(GetPlayerY<GetY+150){
  PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_lazer01.wav");
  
	loop(30){
	
	 
	
   CreateShotA(122,GetPlayerX+1*cos(dor),GetPlayerY+1*sin(dor),10);
   SetShotDataA(122,0,1,angle+90,0.1,0,-2,11);
   
   dor+=12;
   
   FireShot(122);
  
	angle+=360/30;
	
	
	}
  
  loop(30){
	
	 
	
   CreateShotA(1122,GetPlayerX+1*cos(dor),GetPlayerY+1*sin(dor),10);
   SetShotDataA(1122,0,0.5,angle+90,-0.1,0,-2,11);
   
   dor+=12;
   
   FireShot(1122);
  
	angle+=360/30;
	
	
	}
  loop(30){
	
	 
	
   CreateShotA(11222,GetPlayerX+1*cos(dor),GetPlayerY+1*sin(dor),10);
   SetShotDataA(11222,0,0.8,angle,-0.1,0,-2,15);
   
   dor+=12;
   
   FireShot(11222);
  
	angle+=360/30;
	
	
	}
  
  }
  
  }let ang=0;let ab=0;let ang2=0;let ab2=0;
  task blast2{
 
wait(1260);charge;

 wait(90);
 loop{yield;
 ab2+=90;PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_kira00.wav");
 
 loop(3){
 
 CreateShot01(GetX-150,GetY+90,0.5,ang2+ab2,152,0);
 CreateShot01(GetX-150,GetY+90,0.8,ang2+ab2+20,152,0);
 CreateShot01(GetX-150,GetY+90,1,ang2+ab2+40,152,0);
 CreateShot01(GetX-150,GetY+90,1.3,ang2+ab2+60,152,0);
 CreateShot01(GetX-150,GetY+90,1.3,ang2+ab2-60,152,0);
 CreateShot01(GetX-150,GetY+90,1,ang2+ab2-40,152,0);
 CreateShot01(GetX-150,GetY+90,0.8,ang2+ab2-20,152,0);
 ang2+=360/3;

 }
 
 
 loop(3){
 
 CreateShot01(GetX+150,GetY+90,0.5,ang2-ab2+180,152,0);
 CreateShot01(GetX+150,GetY+90,0.8,ang2-ab2-20+180,152,0);
 CreateShot01(GetX+150,GetY+90,1,ang2-ab2-40+180,152,0);
 CreateShot01(GetX+150,GetY+90,1.3,ang2-ab2-60+180,152,0);
 CreateShot01(GetX+150,GetY+90,1.3,ang2-ab2+60+180,152,0);
 CreateShot01(GetX+150,GetY+90,1,ang2-ab2+40+180,152,0);
 CreateShot01(GetX+150,GetY+90,0.8,ang2-ab2+20+180,152,0);
 ang2+=-360/3;

 }
 
 
 
 wait(240);}}
  ////
  task blast{
  blast2;
  wait(840);charge;
 wait(90);
 loop{yield;
 ab+=30;PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_kira00.wav");
 loop(6){
 
 CreateShot01(GetX,GetY,0.8,ang+ab,150,0);
 CreateShot01(GetX,GetY,0.9,ang+ab+5,150,0);
 CreateShot01(GetX,GetY,1,ang+ab+10,150,0);
 CreateShot01(GetX,GetY,1.1,ang+ab+15,150,0);
 CreateShot01(GetX,GetY,1.2,ang+ab+20,150,0);
 CreateShot01(GetX,GetY,1.3,ang+ab+25,150,0);
 CreateShot01(GetX,GetY,1.4,ang+ab+30,150,0);
 
 
  CreateShot01(GetX,GetY,0.8,ang+ab,150,0);
 CreateShot01(GetX,GetY,0.9,ang+ab-5,150,0);
 CreateShot01(GetX,GetY,1,ang+ab-10,150,0);
 CreateShot01(GetX,GetY,1.1,ang+ab-15,150,0);
 CreateShot01(GetX,GetY,1.2,ang+ab-20,150,0);
 CreateShot01(GetX,GetY,1.3,ang+ab-25,150,0);
 CreateShot01(GetX,GetY,1.4,ang+ab-30,150,0);
 
 ang+=360/6;
 }
  
 wait(240); }}
  let ae=20;
  task fifi{
  blast;
  loop{yield;
  
  
  loop(30){a+=56;
  wait(5);PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_tan01.wav");
  
  CreateShot01(GetX,GetY,16,GetAngleToPlayer+ae,225,5);
 CreateShot01(GetX,GetY,16,GetAngleToPlayer-ae,225,5);
  
  
  
  
  
  }}}
  
  let angle=270;let sp=3;let a=0;let angle2=0;let xx=610;let yy=0;let an=0;let spd=1;
 let sp2=0;
 
 task flo{
 
 
 /*wait(560);
 loop{yield;
 wait(240);
 loop(60){wait(1);
 CreateShotA(121212,GetX,GetY,10);
   SetShotDataA(121212,0,1,90,0,0,-2,155);
   SetShotDataA_XY(121212, 60,1, rand(-5,5), rand(-5,5), 0.09, rand(-5,5), 58, 252);
 FireShot(121212);
 
 }
 
 
 }*/
 
 
 }
 task ch{wait(660);
 
 charge;
	wait(90);
 }
 
  task ShowOffNueAnimation {
  ch;
  //SetDamageRate(0,0);
  flo;
  
  
  
    wait(20);sp=0;
    
	
	
	 SetMovePosition03(GetCenterX, GetCenterY-150, 20, 4);
	 if(GetEnemyX<GetCenterX){
      SetNueMoveAnimation("right");}
	   if(GetEnemyX>GetCenterX){
      SetNueMoveAnimation("left");}
      yield ;
      while(GetSpeed>0.1){yield;}
	 charge;
      wait(30);
     
	  wait(30);
	  Animate("nue", "start cast", false);
	loop {yield ;  
	
	  // Animate("nue", "start cast", false);
	 
	 sp2+=10;
	  loop(34){
	  wait(1);PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_tan01.wav");
	 CreateEnemyFromScript("fam",GetClipMinX+sp,GetY+100-sp2,0,0,0);
	 CreateEnemyFromScript("fam",GetClipMinX+0+sp,GetY+90-sp2,0,0,0);
	 CreateEnemyFromScript("fam",GetClipMinX+0+sp,GetY+80-sp2,0,0,0);
	 CreateEnemyFromScript("fam",GetClipMinX+0+sp,GetY+70-sp2,0,0,0);
	 CreateEnemyFromScript("fam",GetClipMinX+0+sp,GetY+60-sp2,0,0,0);
	 CreateEnemyFromScript("fam",GetClipMinX+0+sp,GetY+50-sp2,0,0,0);
	 CreateEnemyFromScript("fam",GetClipMinX+0+sp,GetY+110-sp2,0,0,0);
	 CreateEnemyFromScript("fam",GetClipMinX+0+sp,GetY+120-sp2,0,0,0);
	 CreateEnemyFromScript("fam",GetClipMinX+0+sp,GetY+130-sp2,0,0,0);
	 CreateEnemyFromScript("fam",GetClipMinX+0+sp,GetY+140-sp2,0,0,0);
	 CreateEnemyFromScript("fam",GetClipMinX+0+sp,GetY+150-sp2,0,0,0);
	//if(sp>GetClipMaxX+222){sp=0;}
	sp+=17.5;
	SetDamageRate(0,0);
	
	
	
	}
	
	
	break;
	
	  
	  
	
    }
	
	
	wait(30);
	
	if(GetPlayerY<GetY+150){charge;
	wait(90);FI;po=11;}
	
	
	
	
	wait(30);
	
	charge;
	wait(90);
	if(GetPlayerY<GetY+150){FI;po=11;}
	
	fifi;
	po=41;
	loop {yield ;  
	wait(180);
	if(GetPlayerX<GetClipMinX+150||GetPlayerX>GetClipMaxX-150){
	PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_tan02.wav");
	CreateShot01(GetX,GetY,1,GetAngleToPlayer,76,5);
	CreateShot01(GetX,GetY,1.2,GetAngleToPlayer,76,5);
	CreateShot01(GetX,GetY,1.4,GetAngleToPlayer,76,5);
	CreateShot01(GetX,GetY,1.6,GetAngleToPlayer,76,5);
	CreateShot01(GetX,GetY,1.8,GetAngleToPlayer,76,5);
	CreateShot01(GetX,GetY,2,GetAngleToPlayer,76,5);
	
	
	
	
	
	}
	
	
	
	
	}
	
	
	
	
	
	
	
	
  }
  
  
  
  
  
  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, 61, 80);
    SetAnimationFrame("nue", "idle", 1, imgNue,12, 68, 0, 61+61, 80);
    SetAnimationFrame("nue", "idle", 2, imgNue, 12, 68+68, 0, 61+61+61, 80);
    SetAnimationFrame("nue", "idle", 3, imgNue, 12, 68+68+66, 0, 61+61+61+61, 80);
   
    
    CreateAnimation("nue", "start move right", 4);
    SetAnimationFrame("nue", "start move right", 0, imgNue, 8, 0, 80, 63, 159);
    SetAnimationFrame("nue", "start move right", 1, imgNue, 8, 63, 79, 128, 158);
    SetAnimationFrame("nue", "start move right", 2, imgNue, 8, 131, 82, 196, 157);
    SetAnimationFrame("nue", "start move right", 3, imgNue, 8, 194, 85, 253, 152);
    
    CreateAnimation("nue", "stop move right", 3);
    SetAnimationFrame("nue", "stop move right", 0, imgNue, 4, 131, 82, 196, 157);
    SetAnimationFrame("nue", "stop move right", 1, imgNue, 4, 63, 79, 128, 158);
    SetAnimationFrame("nue", "stop move right", 2, imgNue, 4, 0, 80, 63, 159);
    
    CreateAnimation("nue", "start move left", 4);
    SetAnimationFrame("nue", "start move left", 0, imgNue, 8, 195, 240, 255, 316);
    SetAnimationFrame("nue", "start move left", 1, imgNue, 8, 129, 240, 194, 314);
    SetAnimationFrame("nue", "start move left", 2, imgNue, 8, 65, 240, 130, 315);
    SetAnimationFrame("nue", "start move left", 3, imgNue, 8, 0, 240, 66, 313);
    
    CreateAnimation("nue", "stop move left", 3);
    SetAnimationFrame("nue", "stop move left", 0, imgNue, 4, 65, 240, 130, 315);
    SetAnimationFrame("nue", "stop move left", 1, imgNue, 4, 129, 240, 194, 314);
    SetAnimationFrame("nue", "stop move left", 2, imgNue, 4, 195, 240, 255, 316);
    
    CreateAnimation("nue", "start cast", 4);
    SetAnimationFrame("nue", "start cast", 0, imgNue, 6, 0,160,64,240);
    SetAnimationFrame("nue", "start cast", 1, imgNue, 6, 67,159,132,237);
    SetAnimationFrame("nue", "start cast", 2, imgNue, 6, 129,160,194,237);
    SetAnimationFrame("nue", "start cast", 3, imgNue, 6, 195,158,255,234);
  
    
    CreateAnimation("nue", "stop cast", 3);
    SetAnimationFrame("nue", "stop cast", 0, imgNue, 4, 129,160,194,237);
    SetAnimationFrame("nue", "stop cast", 1, imgNue, 4, 67,159,132,237);
  
    SetAnimationFrame("nue", "stop cast", 2, imgNue, 4, 0,160,64,240);
 
 
  }
}










script_enemy fam{let fi=0;
    let gr = GetCurrentScriptDirectory ~ "circle3.png";
  let dir=0;
  let r=80;
  @Initialize{
  SetLife(2000);
  LoadGraphic(gr);
  main;
  }
  @MainLoop{yield;
  SetCollisionA(GetX, GetY, 17);
        //SetCollisionB(GetX, GetY, 16);
  }
  @DrawLoop{
   SetTexture(gr);SetAlpha(255);
 SetGraphicAngle(0,0,-dir*2);
 
	SetGraphicRect(0,0,12,14);
	SetGraphicScale(1.5,1.5);
	DrawGraphic(GetX,GetY);


  }
  @Finalize{
  PlaySE(GetCurrentScriptDirectory ~ ".\Sounds\se_tan0.wav");
  
   
	
  }
  let angle=0;let sps=0;
  task main{wait(360);
 loop{yield;
 wait(rand(300,5220));sps=rand(1,3);
  CreateShot01(GetX,GetY,sps,90,125,5);
  CreateShot01(GetX+40,GetY,sps,90,125,5);
  CreateShot01(GetX+80,GetY,sps,90,125,5);
  CreateShot01(GetX-40,GetY,sps,90,125,5);
  CreateShot01(GetX-80,GetY,sps,90,125,5);
  
//CreateShotA(112222,GetX,GetY,10);
   //SetShotDataA(112222,0,0.5,90,0,0,-2,87);
  
   
   //FireShot(112222);
 
 }
  }
  
  
  let angle2=0;
 
  let a=0;let s=0;let g=0;
  
  
  
  
   function wait(t){
    loop(t){yield;}
  }
  }
  





