#TouhouDanmakufu
#Title[nonspell5H]
#Text[nonspell5H]
#Image[.\img\spellcard0103.jpg]
#PlayLevel[Hard]
#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 dwait = 0;
let count = 0;
let bosscount = 0;
let angle = 0;
let switch = 1;
let Cut = GetCurrentScriptDirectory~"img\cut5.png";
let ThisShot = GetCurrentScriptDirectory~"system\supershot.txt";

@Initialize
{
drawcc(GetX,GetY+120,0,0);
SetLife(2200);
SetDamageRate(50,25);
SetTimer(60);
mainTask;
SetInvincibility(120);
SetMovePosition02(GetCenterX, GetClipMinY + 120, 100);
//PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
LoadGraphic(ImgBoss);
LoadUserShotData(ThisShot);
LoadGraphic(Cut);
LoadGraphic(ci);
LoadGraphic(bg1);
LoadGraphic(bg2);
//SetScore(500000);
//cutin("NAZRIN", "Taboo 'Red Fire , Blue Fire'", Cut, 0, 0, 325, 488);
SetTexture(ImgBoss);
SetGraphicRect(0, 0, 64, 64);
Aura;
}

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

@MainLoop 
{

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

frame++;

yield;
}

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

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

@BackGround
{
draw2;
}	

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

@Finalize
{
DeleteGraphic(ImgBoss);
}

// main task
task mainTask{
	checkmove;
	wait(120);
	SetColor(255,0,0);
	Concentration01(120);
	SetColor(0,255,0);
	Concentration01(120);
	SetColor(0,0,255);
	Concentration01(120);
	SetColor(255,255,0);
	Concentration01(120);
	SetColor(255,0,255);
	Concentration01(120);
	SetColor(255,255,255);
	Concentration01(120);
	PlaySE(CSD~"sound\charge.wav");
	wait(120);
	fire;
}

task fire{
	ascent(n in 0..128){
	PlaySE(CSD~"sound\shot1.wav");
	if(n==1){fireaim;}
	if(n<72){
	ascent(i in 0..10){
	Bullet(GetX,GetY,7,i*36+15*sin(n*2)+7.5*switch+15,54+n%15,10,0);
	Bullet(GetX,GetY,-7,i*36-15*sin(n*2)+7.5*switch+15,54+n%15,10,0);
	}
	}
	ascent(i in 0..3){
	CreateShotA(0,GetX,GetY,10);
	SetShotDataA(0,0,6,i*120+360*sin(n*11),0,-0.1,1.5,24+n%15);
	//SetShotDataA(0,90,NULL,NULL,0,0.1,5,24+n%15);
	FireShot(0);
	}
	wait(2);
	if(n==90){fire2;}
	}
	}

task fireaim{
	ascent(n in 0..15){
	ascent(i in 0..8){
	CreateShot01(GetX,GetY,3,GetAngleToPlayer+i*45+n*22.5,149+n%7,5);
	}
	wait(10);
	}
	}

task fire2{
	PlaySE(CSD~"sound\Eff1.wav");
	ascent(n in 0..72){
	ascent(i in 0..10){
	Bullet(GetX,GetY,7,i*36+15*sin(n*2)+7.5*switch+15,54+n%15,10,1);
	Bullet(GetX,GetY,-7,i*36-15*sin(n*2)+7.5*switch+15,54+n%15,10,1);
	}
	wait(2);
	}
	switch *= -1;
	SetMovePositionRandom01(rand(20,30),30,3,GetClipMinX+100,rand(130,160),GetClipMaxX-100,rand(100,150));
	checkmove;
	wait(30);
	fire;
	}

task Bullet(x, y, v, dir, graphic, delay,check) 
	{
    	 let obj = Obj_Create(OBJ_SHOT);
	 let c = 0;
    	 Obj_SetPosition   (obj, x, y);
    	 Obj_SetSpeed      (obj, v);
    	 Obj_SetAngle      (obj, dir);
	 if(check==0){
	 Obj_SetAlpha(obj,100);
	  Obj_SetCollisionToPlayer(obj,false);
	 }
    	 ObjShot_SetGraphic(obj, graphic);
    	 ObjShot_SetDelay  (obj, delay);
		 while(! Obj_BeDeleted(obj)) 
		{
		c++;
		if(c<60){
		Obj_SetAngle      (obj, Obj_GetAngle(obj)+v);
		}
		yield;
		}
	      
	}

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

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