#TouhouDanmakufu
#Title["Taboo 'Kagome Kagome 3'"]
#Text[Try to timeout this]
#Image[.\img\spellcard0103.jpg]
#PlayLevel[Lunatic]
#ScriptVersion[2]

script_enemy_main
{
#include_function ".\draweverything.txt";
#include_function ".\system\Effects.txt";
#include_function ".\cutin.txt";
let ImgBoss = GetCurrentScriptDirectory~"img\Flandre_Main.png";
let imgExRumiaBack=GetCurrentScriptDirectory~"img\ExRumiaBack.png";
let CSD = GetCurrentScriptDirectory;
let ci = CSD ~ "system\NMM.png";
let bg1 = CSD ~ "system\bg8.png";
let bg2 = CSD ~ "system\bg3.png";
let cx=GetCenterX();
let frame = 0;
let framedelay = 0;
let angle = 0;
let switch = 1;
let count = 0;
let Cut = GetCurrentScriptDirectory~"img\cut5.png";
let ThisShot = GetCurrentScriptDirectory~"system\supershot.txt";

@Initialize
{
drawcc(GetX,GetY+120,0,0);
SetLife(800);
SetDamageRate(20,10);
SetTimer(60);
mainTask;

SetInvincibility(300);
SetMovePosition02(GetCenterX, GetClipMinY + 120, 60);
LoadGraphic(ImgBoss);
LoadUserShotData(ThisShot);
LoadGraphic(Cut);
LoadGraphic(ci);
LoadGraphic(bg1);
LoadGraphic(bg2);
SetTexture(ImgBoss);
SetGraphicRect(0, 0, 64, 64);
MagicCircle(true);
Aura;
//Border2(255,0,0);
}

//---------------------------------------------------------------

@MainLoop 
{

SetCollisionA(GetX, GetY, 32);
SetCollisionB(GetX, GetY, 16);

yield;

}

//---------------------------------------------------------------

@DrawLoop
{
drawall;
}
//---------------------------------------------------------------

@BackGround
{
draw2;
}	

//---------------------------------------------------------------

@Finalize
{
DeleteGraphic(ImgBoss);
}

// main task
task mainTask{
	checkmove;
	wait(90);
	PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
	SetScore(500000);
	cutin("NAZRIN", "Taboo 'Kagome Kagome 3'", Cut, 0, 0, 325, 488);
	spellcardattack;
	wait(110);
	ConcentrationEx0(60,255,0,0,true);
	wait(36);
	attack;
	wait(24);
	fire;
	stopattack;
	bossmove;
}

task fire{
		PlaySE(CSD~"sound\shot2.wav");
		ascent(i in 0..24){
		if(count==0)
		{Bullet(GetX,GetY,3,i*15,154,10);}
		else
		{Bullet(GetX,GetY,4.5,i*15+GetAngleToPlayer,154,10);}
		}
		if(count==0){
		wait(270);
		fire2;
		}
	   }

task fire2{
	loop{
		if(count%2!=0){wait(60);}
		SetColor(0,255,0);
		Concentration01(60-count*10);
		SetColor(255,255,255);
		wait(60-count*10);
		ascent(i in 0..20){
		PlaySE(CSD~"sound\shot2.wav");
		ascent(j in 0..9){
		CreateShot01(GetX,GetY,2,GetAngleToPlayer+j*40,64,5);
		CreateShot01(GetX,GetY,3.5,GetAngleToPlayer+j*40,64,5);
		}
		ascent(a in 0..3){
		Bullet(GetX,GetY,4,i*23*switch+a*120+GetAngleToPlayer,154,10);
		}
		wait(6-count/4);
		}
		switch = -switch;
		count++;
		if(count%1==0){fire;}
		wait(140-count*10);
		yield;
	     }
	   }
		
task bossmove{
		wait(120);
		loop{
		 SetMovePositionRandom01(rand(50,100),0,10,GetClipMinX+100,rand(100,150),GetClipMaxX-100,rand(100,150));
		checkmove;
		 wait(240);
		 yield;
		    }
	     }
task Bullet(x, y, v, dir, graphic, delay) 
	{
    	 let obj = Obj_Create(OBJ_SHOT);
	 let acc = 0;
    	 Obj_SetPosition   (obj, x, y);
    	 Obj_SetSpeed      (obj, v);
    	 Obj_SetAngle      (obj, dir);
    	 ObjShot_SetGraphic(obj, graphic);
    	 ObjShot_SetDelay  (obj, delay);
	 //////////////////////////////////////////////
	   task lightlaser(x, y, v, dir,l,w, graphic, delay,check) {
	   let obj = Obj_Create(OBJ_LASER);
 	   let c = 0;
 	   Obj_SetPosition   (obj, x, y);
  	  Obj_SetSpeed      (obj, v);
 	   ObjShot_SetGraphic(obj, graphic);
  	  ObjShot_SetDelay  (obj, delay);
 	   Obj_SetAngle      (obj, dir);
 	   ObjLaser_SetLength(obj,l);
    	ObjLaser_SetWidth (obj,w);
    	ObjLaser_SetSource(obj,false);
  	  while(! Obj_BeDeleted(obj)) {
		c++;
		ObjLaser_SetWidth (obj,rand_int(14,16));
		ObjLaser_SetLength(obj,c*20);
		if(c>230-acc){ObjShot_FadeDelete(obj);}
   	     yield;
	    }
	}
	///////////////////////////////////////////////////////////////////////////
		 while(! Obj_BeDeleted(obj)) 
		{
		acc++;
		 if((Obj_GetX(obj)>=GetClipMaxX)||(Obj_GetX(obj)<=GetClipMinX))
		 {
			PlaySE(CSD~"sound\shot5.wav");
			PlayDelaySE(CSD~"sound\Laser1.wav",150-acc);
			if(Obj_GetX(obj)>=GetClipMaxX)
			{lightlaser(Obj_GetX(obj)+20, Obj_GetY(obj), 0, -Obj_GetAngle(obj)+180,550,20, 6, 150-acc,1);}
			else if(Obj_GetX(obj)<=GetClipMinX)
			{lightlaser(Obj_GetX(obj)-20, Obj_GetY(obj), 0, -Obj_GetAngle(obj)+180,550,20, 6, 150-acc,1);}
			Obj_Delete(obj);
		 }
		 if((Obj_GetY(obj)>=GetClipMaxY)||(Obj_GetY(obj)<=GetClipMinY))
		 {
			PlaySE(CSD~"sound\shot5.wav");
			PlayDelaySE(CSD~"sound\Laser1.wav",150-acc);
			 if(Obj_GetY(obj)>=GetClipMaxY)
			{lightlaser(Obj_GetX(obj), Obj_GetY(obj)+20, 0, -Obj_GetAngle(obj),550,20, 6, 150-acc,1);}
			else  if(Obj_GetY(obj)<=GetClipMinY)
			{lightlaser(Obj_GetX(obj), Obj_GetY(obj)-20, 0, -Obj_GetAngle(obj),550,20, 6, 150-acc,1);}
			Obj_Delete(obj);
		 }
		 yield;
		}
	}

	function wait(w){
		loop(w){yield;}
			}

	task PlayDelaySE(se,delay){
	        loop(delay){yield;}
  	      PlaySE(se);
	}

sub spawn{
	PlaySE(CSD~"sound\fam.wav");
	//CreateEnemyFromScript("starFam",GetX,GetY,0,0,0);
	//CreateEnemyFromScript("starFam",GetX,GetY,0,0,180);
	  }
}
