
#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(3000);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(46);
	}
	case(EV_REQUEST_SPELL_SCORE) {
		SetScriptResult(10000);
	}
	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("Electric Sign \"Shock Wave\"",20);
	setOverlay;
	TEnd;
	yield;
} 

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

task movement {
	wait(120);
	loop{
		loop(2){
			SE_Play(shoot,40);
			fire1;
			fire2;
			fire3;
			fire4;
			fire5;
			wait(10);
		}
		wait(20);
		laserA1;
		wait(20);
		/*loop(10){
			fireX;
			wait(2);
		}*/
		ObjMove_SetDestAtFrame(bossObj, rand(192-60, 192+60), rand(50,100), 60);
		wait(80);
	}
}

task fire1 {
	let angleT = rand(0,360);
	loop(20){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		CreateShotA1(bossX+ 80*cos(angleT),bossY+ 40*sin(angleT),rand(4,5),angleT,14,20);
			angleT+=360/20;
	}
}
task fire2 {
	let angleT = rand(0,360);
	loop(15){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		CreateShotA1(bossX+ 60*cos(angleT),bossY+ 50*sin(angleT),rand(1,3),angleT,30,20);
			angleT+=360/15;
	}
}
task fire3 {
	let angleT = rand(0,360);
	loop(20){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		CreateShotA1(bossX,bossY,3,angleT,62,20);
			angleT+=360/20;
	}
}
task fire4 {
	let angleT = rand(0,360);
	loop(30){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		CreateShotA1(bossX+ 80*cos(angleT),bossY+ 40*sin(angleT),rand(2,4),angleT,221,20);
			angleT+=360/30;
	}
}
task fire5 {
	let angleT = rand(0,360);
	loop(30){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		CreateShotA1(bossX+ rand(60,80)*cos(angleT),bossY+ 20*sin(angleT),rand(1,5),angleT,264,20);
			angleT+=360/30;
	}
}

task laserA1 {
	let angleT = angleToPlayer; 
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
	laserDelay;
	CreateStraightLaserA1(bossX, bossY, angleT-30, 512, 30, 20, 1057, 60);
	CreateStraightLaserA1(bossX, bossY, angleT-15, 512, 30, 20, 1057, 60);
	CreateStraightLaserA1(bossX, bossY, angleT, 512, 30, 20, 1057, 60);
	CreateStraightLaserA1(bossX, bossY, angleT+15, 512, 30, 20, 1057, 60);
	CreateStraightLaserA1(bossX, bossY, angleT+30, 512, 30, 20, 1057, 60);
	
}

/*task fireX{
	let angleT = rand(0,360);
	SE_Play(shoot2,55);
	loop(10){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		CreateShotA1(bossX,bossY,rand(0.5,3),angleT,207,10);
		angleT+= 360/10
		}
}*/

task laserDelay{
	wait(60);
	SE_Play(laserSFX,40);
}