#TouhouDanmakufu
#Title["Taboo 'Lunatic Girl'"]
#Text[spell1L]
#Image[.\img\spellcard0103.jpg]
#PlayLevel[Lunatic]
#ScriptVersion[2]

script_enemy_main
{
#include_function ".\system\Effects.txt";
#include_function ".\cutin.txt";
#include_function ".\draweverything.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 angle2 = 0;
let switch = 1;
let Cut = GetCurrentScriptDirectory~"img\cut5.png";
let ThisShot = GetCurrentScriptDirectory~"system\supershot.txt";

@Initialize
{
drawcc(GetX,GetY+120,0,0);
SetLife(880);
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 'Lunatic Girl'", Cut, 0, 0, 325, 488);
	spellcardattack;
	wait(120);
	ConcentrationEx0(60,255,0,0,true);
	wait(48);
	shoot;
	wait(12);
	spawn;
	movement;
	wait(30);
	stopshoot;
}

task bossfire{
	loop(2){
	CreateShotA(0,GetEnemyX,GetEnemyY,20);
	SetShotDataA(0,0,1.2,GetAngleToPlayer,0,0.00,5,204);
	FireShot(0);
	wait(120);
	}
	}

task movement{
	wait(180);
	loop{
	SetMovePositionRandom01(rand(20,50),0,2,GetClipMinX+100,rand(150,160),GetClipMaxX-100,rand(100,150));
	checkmove;
	bossfire;
	wait(240);
	}
	}

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

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

	function Obj_GetAngleToPlayer(obj) {
	return atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj));
	}

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

script_enemy starFam{
	
	let ThisShot = GetCurrentScriptDirectory~"system\supershot.txt";
	let CSD = GetCurrentScriptDirectory;
	let imgFam = CSD ~ "system\familiar.png";
	let s = 0;
	let switch = 1;
	let r = 3;
	let speed = 1;
	let famangle = GetArgument;
	let spin = 0;
	let count = 0;
@Initialize{
	LoadUserShotData(ThisShot);
	SetLife(1000);
	LoadGraphic(imgFam);
	maintask;
}

@MainLoop{

//SetCollisionA(GetX, GetY, 24);
SetCollisionB(GetX, GetY, 18);

yield;


}
	
@DrawLoop{
	SetTexture(imgFam);
	SetRenderState(ALPHA);
	if(s<=1){s+= 0.025;}	
	SetGraphicScale(s,s);
	SetGraphicAngle(0,0,spin);
	SetGraphicRect(0,0,64,66);
	SetColor(255, 0, 0); 
	DrawGraphic(GetX,GetY);
	spin -= 1;

}

@Finalize{

	//DeleteGraphic(imgFam);

}

task maintask{
	movement;
	yield;
	}

task movement{
	if(famangle==0){
	SetMovePosition03(GetCenterX-120, 150, 10, r);
	}
	else if(famangle==1){
	SetMovePosition03(GetCenterX+120, 150, 10, r);
	}
	else if(famangle==2){
	SetMovePosition03(GetCenterX, 50, 10, r);
	}
	wait(60);
	Concentration01(30);
	wait(30);
	fire;
	}

task fire{
	ascent(m in 0..2){
	ascent(n in 0..12){
	PlaySE(CSD~"sound\shot1.wav");
	ascent(i in 0..15){
	CreateShotA(0,GetX,GetY,10);
	if(famangle!=2){
	SetShotDataA(0,0,1,i*30+n*switch*1,0,0,0,11);
	}
	else{
	SetShotDataA(0,0,1,i*30+7.5*m,0,0,0,11);
	}
	SetShotDataA(0,40,1,NULL,0,0.02,3,11);
	FireShot(0);
	}
	wait(5);
	}
	ascent(n in 0..15){
	PlaySE(CSD~"sound\shot1.wav");
	ascent(i in 0..7){
	CreateShotA(0,GetX,GetY,10);
	SetShotDataA(0,0,1,i*360/7+360*sin(n*28)*switch,0,0,0,11);
	SetShotDataA(0,40,1,NULL,0,0.02,2.5,11);
	FireShot(0);
	}
	wait(5);
	}
	switch = -switch;
	wait(10);
	}
	wait(30);
	Concentration01(60);
	wait(60);
	ascent(n in 0..8){
	PlaySE(CSD~"sound\shot4.wav");
	ascent(i in 0..4){
	ascent(a in 0..10){
	CreateShotA(0,GetX,GetY,5);
	SetShotDataA(0,0,1+a/3,i*90+n*17*switch,0,0,0,11);
	FireShot(0);
	}
	}
	wait(15);
	}
	wait(60);
	switch = -switch;
	r=6;
	if(count%2==0){
	movement2;
	}
	else{
	movement;
	}
	}

task movement2{
	if(famangle==0){
	SetMovePosition03(GetCenterX+100, 140, 10, r);
	}
	else if(famangle==1){
	SetMovePosition03(GetCenterX-100, 140, 10, r);
	}
	wait(40);
	Concentration01(30);
	wait(30);
	count++;
	fire;
	}

 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++;
		if(c<30){
		ObjLaser_SetLength(obj,c*15);
		}
		if(c>60){
		ObjShot_FadeDelete(obj);
		}
   	     yield;
	    }
	   }

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

}