#TouhouDanmakufu
#Title["Taboo 'Eaevateinn'"]
#Text[Spell4L]
#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 angle2 = 0;
let switch = 1;
let switch2 = 1;
let switchm = 1;
let gpx = 0;
let gpy = 0;
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;
}

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

@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 'Eaevateinn'", Cut, 0, 0, 325, 488);
	spellcardattack;
	wait(110);
	laserb;
}

task fire{
	PlayDelaySE(CSD~"sound\shot3.wav",0);
	ascent(i in 0..3){
	CreateShotA(0,GetX,GetY,10);
	SetShotDataA(0,0,5,GetAngleToPlayer-25+i*25,0,-0.1,0.7,229.5+switchm*-1/2);
	FireShot(0);
	}
	}

task laserb{
	loop{
	ConcentrationEx0(120,255,0,0,true);
	PlaySE(CSD~"sound\charge3.wav");
	wait(120);
	gpx = GetPlayerX+rand_int(-70,70);
	gpy = GetPlayerY;
	ascent(n in 0..2){
	PlayDelaySE(CSD~"sound\laser3.wav",0);
	ascent(a in 0..2){
	CreateLaserB(0,140, 30, 2, 40);
	SetLaserDataB(0, 0, 0, 40, 0, 90+30*switch+a*180, 0, 90+30*switch+a*180, 0);
	SetLaserDataB(0, 40, 0, 40, 0, 90+30*switch+a*180, 7.8*switch, 90+30*switch+a*180, 7.8*switch);
	SetShotKillTime(0,112);
	ascent(i in 0..24){
	PlayDelaySE(CSD~"sound\shot1.wav",40+i*3);
	ascent(a in 0..7){
	CreateShotA(1,0,0,12);
	SetShotDataA(1,0,0,270*switchm+rand(-1,1)+a*24,0,0.01,4,57+switchm*-1);
	SetShotDataA(1,60,0.5,NULL,0,0.006+switchm*-1/900,4,56+switchm*-1);
	AddShot(40+i*3,0,1,a*17+20);
	}
	}
	FireShot(0);
	}
	ascent(a in 0..2){
	lightlaser(gpx+70*cos(90+30*switch2+a*180), gpy+70*sin(90+30*switch2+a*180), 0, 90+30*switch2+a*180,140,30, 7, 40,a);
	}
	switch = -switch;
	switch2 = -switch2;
	if(n==0){
	wait(90);
	SetMovePositionRandom01(rand(20,50),0,2,GetClipMinX+100,rand(150,160),GetClipMaxX-100,rand(100,150));
	checkmove;
	wait(30);
	fire;
	wait(60);
	}
	else if(n==1){
	wait(60);
	SetMovePositionRandom01(rand(20,50),0,2,GetClipMinX+100,rand(150,160),GetClipMaxX-100,rand(100,150));
	checkmove;
	wait(30);
	fire;
	wait(30);
	fire;
	wait(60);
	}
	}
	switchm = -switchm;
	}
	}

	   task lightlaser(x, y, v, dir,l,w, graphic, delay,check) {
	   let obj = Obj_Create(OBJ_LASER);
 	   let c = 0;
	   //let gpx = GetPlayerX;
 	   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);
	 dir = 90+30*switch+check*180;
  	  while(! Obj_BeDeleted(obj)) {
		c++;
		if(c>=40){
		Obj_SetPosition   (obj, gpx+70*cos(90+30*switch2+check*180+c*7.8*switch2), gpy+70*sin(90+30*switch2+check*180+c*7.8*switch2));
		Obj_SetAngle      (obj, 90+30*switch2+check*180+c*7.8*switch2);
		if(c%2==0){
		ascent(i in 0..1){
		ascent(a in 0..6){
		CreateShotA(1,Obj_GetX(obj)+(a*17+20)*cos(90+30*switch2+check*180+c*7.8*switch2),Obj_GetY(obj)+(a*17+20)*sin(90+30*switch2+check*180+c*7.8*switch2),12);
		SetShotDataA(1,0,0,a*24+Obj_GetAngle(obj)+a*16,0,0.01,4,252);
		SetShotDataA(1,60,NULL,NULL,0,0.015,4,253);
		FireShot(1);
	}
	}
		}
		}
		if(c>112){ObjShot_FadeDelete(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);
	  }
}
