#include"./function.txt"

let BossObj;
let BossObjX = 0;
let BossObjY = 0;

let BossAlpha = 0;

let ImgBoss;

let imgBossObj = dir ~ "graphic/hibaru_dot.png";

let objScene = GetEnemyBossSceneObjectID();
let dif=GetCommonData("diff",1);

@Initialize 
{
	SetAutoDeleteObject(true);
	BossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ImgBoss = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(BossObj);
	ObjEnemy_Regist(ImgBoss);
	mainTask;
} 

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(0);
	}
}

@MainLoop 
{
	ObjRender_SetAlpha(ImgBoss,BossAlpha);
	BossObjX = ObjMove_GetX(BossObj);
	BossObjY = ObjMove_GetY(BossObj);
	ObjRender_SetPosition(ImgBoss,BossObjX,BossObjY,0);
	yield;
} 

@Finalize 
{ 
} 

task mainTask
{
	
	ObjRender_SetPosition(BossObj,GetStgFrameWidth/2+720,GetStgFrameHeight/2-120,0);
	loop(60){yield;}
	movesprite(ImgBoss,60,imgBossObj,1);
	let scale=1;
	let time=60;
	let angle;
	ObjRender_SetColor(ImgBoss,0,0,0);
	loop(2)
	{
		loop(time)
		{
			if(BossAlpha<256){BossAlpha+=256/time;}
			if(time==60)
			{
				ObjRender_SetPosition(BossObj,GetStgFrameWidth/2+720*scale*sin(-270+360*scale),GetStgFrameHeight/2-120+240*scale*cos(-270+360*scale),0);
				if(BossObjX>=0 && BossObjX<=GetStgFrameWidth && BossObjY>=0 && BossObjY<=GetStgFrameHeight)
				{
					angle=rand(0,360);
					loop(3)
					{
						Charge(BossObjX,BossObjY,rand(120,480)*scale,120,255,255,255,255,BLEND_SUBTRACT,1,0,angle,rand(60,240)*scale);
						angle+=120;
					}
				}
			}
			if(time==120)
			{
				ObjRender_SetPosition(BossObj,GetStgFrameWidth/2+720*scale*sin(-180+180*scale),GetStgFrameHeight/2-120+240*scale*cos(-180+180*scale),0);
			}
			scale-=0.5/time;
			yield;
		}
		if(scale>=0.5){loop(120){yield;}}
		movesprite(ImgBoss,time,imgBossObj,-1);
		ObjRender_SetColor(ImgBoss,255,255,255);
		time+=60;
	}
	idlesprite(ImgBoss,60,imgBossObj);
	loop(60){yield;}
	Obj_Delete(BossObj);
	Obj_Delete(ImgBoss);
	CloseScript(GetOwnScriptID());
}