#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["S1"]
#Text["S1"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Background["./BG.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/AllStarShot_Const.dnh"
#include"./system/Default_Effect.Txt"
#BGM["./boss6.mp3"]


let objBoss;
let GCSD=GetCurrentScriptDirectory~"";
let enemy;
let bSpell=false;
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
let idle = true;
let atk = false;
let fog = 0;
let objScene=GetEnemyBossSceneObjectID();
let arr = [1,6,4,2,3,5,0];
@Initialize
{
SetBoss(false);
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),25);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),26);
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(1);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(23);
	}
}

//----------------------------------------------------
task mainTask{
	SetShotAutoDeleteClip(32,32,32,32);
	ObjMove_SetPosition(objBoss,stgx,-120);
	wait(60);
	PlaySound("Charge3",95,0);
	Circle(0,64,0,-1);
	Circle(0,0,64,-2);
	Circle(64,0,0,-3);
	wait(120);
	PlaySound("Eff5",100,0);
	ObjMove_SetPosition(objBoss,stgx,130);
	Circle(64,64,64,10);
	DamageRateAtFrame(0,0,120);
	wait(60);
	FirePillar;
	}
//----------------------------------------------------

task FirePillar{
	let l_color = [1003,1015,1014,1011,1009,1005];
	let s = 1;
	wait(35);
	PlaySound("Boon2",100,0);
		ascent(i in 0..6){
		Pillar(i*70+15,GetEnemyY-450,90,l_color[i],i);
		}
		wait(225);		// 340
			ascent(n in 0..20){
			let x = stgx+rand(-180,180);
			let y = GetEnemyY+rand(-30,30);
			let st = rand(0,40);
			ascent(i in 0..9){
			ShotA1(x,y,rand(1,4),i*40+st,round(rand(17,32)),round(rand(201,207)),8);
			}
			wait(2);
			}
		SetShotAutoDeleteClip(64,64,64,64);
		wait(75);
		descent(n in 0..30){
			PlaySound("Shot6",100,0);
			ascent(i in -1..2){
			ascent(a in 0..3){
			ShotA1(n*14,60+n,1+a*1.5,getDotAngle(GetPlayerX,GetPlayerY,n*14,60+n)+i*45,300+n%7,0,6);
			ShotA1(30*14-n*14,60+n,1+a*1.5,getDotAngle(GetPlayerX,GetPlayerY,30*14-n*14,60+n)+i*45,300+n%7,0,6);
			}
			}
			wait(n%2);
		}
		wait(30);
		while(!Obj_IsDeleted(objBoss)){
			let x = stgx+rand(-190,190);
			let y = GetEnemyY+rand(-30,60);
			let st = rand(0,40);
			PlaySound("Shot6",92,0);
			ascent(i in 0..4){
				ascent(j in 0..3){
				ShotA1(x,y,1.5+j,i*90+j*20*s+st,302,204,12);
				}	
			}
			s = -s;
			wait(9);
		}
	}
	
	task Pillar(x,y,dir,color,num){
	let obj = CreateStraightLaserA1(x,y,dir,515,0,99999,color,0);
	let eff = CreateStraightLaserA1(x,y,dir,515,0,99999,color,0);
	let delaycolor = [202,208,207,206,205,203];
	ObjRender_SetColor(obj,192,192,192);
	ObjRender_SetColor(eff,128,128,64);
	Obj_SetRenderPriorityI(eff,31);
	let acc = 0;
	let c = 0;
	//ObjStLaser_SetSource(obj,false);
	Stable;
		ascent(i in 0..30){
		ObjLaser_SetIntersectionWidth(obj,i/2);
		ObjLaser_SetRenderWidth(obj,i/2);
		wait(1);
		}
		wait(18);
		while(ObjMove_GetY(obj)+515*sin(dir)<448+64){
		ObjMove_SetX(obj,ObjMove_GetX(obj)+c*cos(dir));
		ObjMove_SetY(obj,ObjMove_GetY(obj)+c*sin(dir));
		c+= acc;
		acc += 0.025;
		yield;
		}
		ScreenShake(30);
		PlaySound("don",100,0);
		wait(90+num*2);
			PlaySound("Enep1",95,0);
			let shotc = color-952;
			ascent(i in 0..10){
			ascent(j in 0..2){
			let shot = ShotA2(ObjMove_GetX(obj)-5,ObjMove_GetY(obj)+i*44+j*180-90,0.5,i*37,0.005,3,shotc,delaycolor[num],6);
			ObjMove_AddPatternA2(shot,60,NO_CHANGE,NO_CHANGE,0.005,0,3);
			}
			}
			Obj_Delete(obj);
			task Stable{
				ascent(i in 0..60){
				ObjLaser_SetIntersectionWidth(eff,i/2);
				ObjLaser_SetRenderWidth(eff,i/2);
				wait(i%2);
				}
					while(!Obj_IsDeleted(obj)){
					ObjMove_SetPosition(eff,ObjMove_GetX(obj),ObjMove_GetY(obj));
					ObjLaser_SetRenderWidth(eff,rand(57/2,63/2));
					yield;
					}
					Obj_Delete(eff);
			}
			}
			
					task ScreenShake(time){
				descent(i in 0..time/2){
				Set2DCameraFocusX(Get2DCameraX + rand(-i/10, i/10));
				Set2DCameraFocusY(Get2DCameraY + rand(-i/10, i/10));
				yield;
				Reset2DCamera;
				yield;
				}
				Reset2DCamera;
			}
//----------------------------------------------------

task TRender
{
	DrawBoss;
}

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

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		EndBoss(0);
		yield;
		CloseScript(GetOwnScriptID());
	}