
#include "./default_system/AllStarShot_Const.txt"
#include"./functions.txt"
#include "./cutin.txt"
let objScene = GetEnemyBossSceneObjectID();
@Initialize {
	// define a boss in bossObj and register it
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossObj);
	ObjEnemyBossScene_StartSpell(objScene);
	
	// move boss to desired x y location at desired speed
	ObjMove_SetDestAtSpeed(bossObj, 192,100,3);
	

	mainTask;	// run mainTask
	
} 

@Event { 
	// setting the boss timer and life
	alternative(GetEventType()) 
	case(EV_REQUEST_LIFE) { 
		SetScriptResult(3500);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(46);
	}
	case(EV_REQUEST_SPELL_SCORE) {
		SetScriptResult(20000);
	}
	case(EV_REQUEST_IS_DURABLE_SPELL){
	SetScriptResult(true);
	}
} 

@MainLoop {
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);
	
	// collision for the shots and player
	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,24);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,bossX,bossY,10);
	yield;
} 

@Finalize {
	if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT)
        +ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0){
		AddScore(ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));
	}

} 

task mainTask { 
	RenderBoss;
	movement;
	CutinA1("Normal Sign \"Swift\"",20);
	setOverlay;
	TEnd;
	yield;
} 

//ObjMove_SetDestAtSpeed(bossObj,x,y,speed);		

task movement {
	wait(180);
	loop(30){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		SE_Play(shoot2,50);
		fire;
		fireB;
		wait(8);
	}
	movement2;
	StarSpinShoot;
	loop{
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		SE_Play(shoot2,50);
		fire;
		fireB;
		wait(8);
		SE_Play(shoot,40);
		fire2;
		yield;
	}
	
}


task fire{
	let angleT=rand(85,95);
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		let obj = CreateShotA1(rand(0,GetStgFrameWidth),-10,rand(2,3),angleT,rand(175,175),0);
}
task fireB{
	let angleT=90;
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		let obj = CreateShotA1(rand(0,GetStgFrameWidth),-10,rand(2,3),angleT,rand(264,265),0);
}

task fire2{
	let angleT=90;
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		let obj = CreateShotA1(rand(0,GetStgFrameWidth),-20,rand(4,5),angleT,267,0);
}

task movement2{
	loop{
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		ObjMove_SetDestAtFrame(bossObj, rand(192-60, 192+60), rand(50,100), 60);
		wait(120);
	}
}
task starspin(spin){
	let angle = rand(0,360);
	let angleplus = 14;
	let speed = 0.5;
	
	loop(10){
		loop(10){
			let shot = CreateShotA1(bossX,bossY,speed,angle,273,0);
			angle+=360/10;
		}
		angle+=angleplus*spin;
		speed+=3/10;
	}
}

task StarSpinShoot{
	wait(120);
	loop{
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
	starspin(1);
	wait(300);
	}
}