#TouhouDanmakufu
#Title["Forbidden Power"]
#Text[spell5H]
#Image[.\img\spellcard0103.jpg]
#PlayLevel[Hard]
#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.2,0.4,0.6,0.8,1];
let switch = 1;
let Cut = GetCurrentScriptDirectory~"img\cut5.png";
let ThisShot = GetCurrentScriptDirectory~"system\supershot.txt";

@Initialize
{
drawcc(GetX,GetY+120,0,0);
SetLife(1850);
SetDamageRate(20,10);
SetTimer(100);
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{
	SetShotAutoDeleteClip(22,22,22,22);
	checkmove;
	wait(120);
	PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
	SetScore(500000);
	cutin("NAZRIN", "Forbidden Power", Cut, 0, 0, 325, 488);
	spellcardattack;
	wait(120);
	fire;
}

task fire{
	let randa = 0;
	let count = 0;
	loop{
	framedelay++;
	if(framedelay<5){
	angle = rand_int(0,3);
	randa = rand_int(0,59);
	PlaySE(CSD~"sound\bright.wav");
	ascent(i in 0..12+count){
	Bullet(GetX,GetY,2.5,i*360/(12+count)+randa,229+frame%7,30,0,angle2[angle]*switch);
	}
	}
	else{
	angle = rand_int(2,4);
	count+=2;
	randa = rand_int(0,59);
	PlaySE(CSD~"sound\charge2.wav");
	Concentration01(60);
	wait(60);
	PlaySE(CSD~"sound\bulletwave.wav");
	ascent(i in 0..6+count){
	Bullet(GetX,GetY,3.25,i*360/(6+count)+30+randa,229+frame%7,60,1,0);
	Bullet(GetX,GetY,3.25,i*360/(6+count)+randa,229+frame%7,60,1,0);
	}
	framedelay = 0;
	}
	frame++;
	switch = -switch;
	wait(120-count*2);
	SetMovePositionRandom01(rand(30,50),0,5,GetClipMinX+80,rand(120,130),GetClipMaxX-80,rand(100,150));
	checkmove;
	wait(90-count*2);
	}
	}

task Bullet(x, y, v, dir, graphic, delay,check,omega) 
	{
    	 let obj = Obj_Create(OBJ_SHOT);
	 let c = 0;
	 let colorA = 0;
	 let maxtime = 180+check*100;
    	 Obj_SetPosition   (obj, x, y);
    	 Obj_SetSpeed      (obj, v);
    	 Obj_SetAngle      (obj, dir);
    	 ObjShot_SetGraphic(obj, graphic);
    	 ObjShot_SetDelay  (obj, delay);
	 ObjShot_SetBombResist(obj, true);
	 alternative(graphic)
	 case(229){colorA = 26;} //RED
	case(230){colorA = 30;} //BLUE
	case(231){colorA = 34;} //GREEN
	case(232){colorA = 37;} //YELLOW
	case(233){colorA = 32;} //AQUA
	case(234){colorA = 27;} // PURPLE
	case(235){colorA = 38;} //ORANGE
		 while(! Obj_BeDeleted(obj)) 
		{
		if(c<maxtime){
		Obj_SetAngle(obj,Obj_GetAngle(obj)+omega);
		}
		c++;
		if(c%(30-check*5)==0 && c>=60){
		CreateShotA(0,Obj_GetX(obj),Obj_GetY(obj),20);
		SetShotDataA(0,0,0,Obj_GetAngle(obj)+90,0,0.005,1,colorA);
		FireShot(0);
		CreateShotA(0,Obj_GetX(obj),Obj_GetY(obj),20);
		SetShotDataA(0,0,0,Obj_GetAngle(obj)-90,0,0.005,1,colorA);
		FireShot(0);
		}
		if(check==1){
		 if((Obj_GetX(obj)<=GetClipMinX+5)||(Obj_GetX(obj)>=GetClipMaxX-5)){
		 Obj_SetAngle(obj,180-Obj_GetAngle(obj));
		check = 0;
		 }
		 if(Obj_GetY(obj)<=GetClipMinY+5){
		 Obj_SetAngle(obj,-Obj_GetAngle(obj));
		 check = 0;
		 }
		}
		 yield;
		}
	}

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

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