#include "./Default_ShotConst.txt"

let objBoss;
let objScene = GetEnemyBossSceneObjectID();
let shot_sound = GetCurrentScriptDirectory ~ "./SFX/se_shot.wav";
let shot_soundII = GetCurrentScriptDirectory ~ "./SFX/se_shot2nd.wav";

//Default dimension of Danmakufu's playing field is 384 * 448 pixels.

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(3500);
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(45);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
}

@Initialize
{
	DeleteShotAll(TYPE_ALL,TYPE_IMMEDIATE);
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	ObjEnemy_SetDamageRate(objBoss, 0, 0);

	LoadSound(shot_sound);
	LoadSound(shot_soundII);

	TDrawLoop;
	TFinalize;
	MainTask;
	Spiral;
}

task TDrawLoop
{
	let img = GetCurrentScriptDirectory ~ "Wriggle.png";
	ObjPrim_SetTexture(objBoss, img);
	ObjSprite2D_SetSourceRect(objBoss, 0, 0, 40, 60);
	ObjSprite2D_SetDestCenter(objBoss);
}

task MainTask
{
	Movement;
	wait(180);
	ObjEnemy_SetDamageRate(objBoss, 100, 100);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		let angleA = GetAngleToPlayer(objBoss)-90;
		loop(10)
		{
			ascent(i in 0..3)
			{
				CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 3-i/2, angleA+i*3, DS_RICE_S_YELLOW, 30);
				CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 3-i/2, angleA-i*3, DS_RICE_S_YELLOW, 30);
			}
		angleA+=180/10;
		}
	wait(60);
	}
}

task Spiral
{
	wait(60);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		let angleT = 0;
		let spiral = 0;
		loop
		{	
			loop(4)
			{
				CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 2.5, angleT+spiral, DS_BALL_BS_YELLOW, 10);
				CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 2.5, angleT-spiral, DS_BALL_BS_YELLOW, 10);
				angleT+=360/4;
	  		}
			spiral+=7;
			PlaySE(shot_sound);
			wait(5);
		}
	}
}

task Movement
{
	ObjMove_SetDestAtWeight(objBoss, 192, 120, 60, 3);
	wait(180);
}

task TFinalize
{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
	Obj_Delete(objBoss);
	DeleteShotAll(TYPE_ALL,TYPE_ITEM);
	SetAutoDeleteObject(true);
	CloseScript(GetOwnScriptID());
	return;
}

@MainLoop
{
        ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32); 
        ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 24);
        yield;
}

function GetCenterX
{
	return GetStgFrameWidth/2;
}
function GetCenterY
{
	return GetStgFrameHeight/2;
}
function wait(n)
{
	loop(n){yield;}
}