
#include "./default_system/Default_Effect.txt"
#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);
	Cutin("Dark Sky \"Stary Night\"",20);
	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(12000);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(62);
	}
	case(EV_REQUEST_SPELL_SCORE) {
		SetScriptResult(999999999);
	}
} 

@MainLoop {
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);
	
	// collision for the shots and player
	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,15);
	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;
	TFinish;
	overlay;
	yield;
} 

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

task movement {
	wait(180);
	loop{
		loop(60){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		RandStar;
		RandStar2;
		RandStar3;
		RandStar4;
		wait(2);
		}
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		FireB;
		FireA;
	}
}

task RandStar{
	ShootDelay2;
	let obj = CreateShotA1(rand(GetPlayerX-10,GetPlayerX-400),rand(GetPlayerY-10,GetPlayerY-400),rand(0.01,0.1),rand(0,360),192,10);
	wait(180);
	Obj_Delete(obj);
	
}
task RandStar2{
	ShootDelay2;
	let obj = CreateShotA1(rand(GetPlayerX+10,GetPlayerX+400),rand(GetPlayerY-10,GetPlayerY-400),rand(0.01,0.1),rand(0,360),192,10);
	wait(180);
	Obj_Delete(obj);
	
}
task RandStar3{
	ShootDelay2;
	let obj = CreateShotA1(rand(GetPlayerX+10,GetPlayerX+400),rand(GetPlayerY+10,GetPlayerY+400),rand(0.01,0.1),rand(0,360),192,10);
	wait(180);
	Obj_Delete(obj);
	
}
task RandStar4{
	ShootDelay2;
	let obj = CreateShotA1(rand(GetPlayerX-10,GetPlayerX-400),rand(GetPlayerY+10,GetPlayerY+400),rand(0.01,0.1),rand(0,360),192,10);
	wait(180);
	Obj_Delete(obj);
	
}

task ShootDelay2{
	wait(10);
	SE_Play(shoot2,50);
}
task FireA{
	let angleT = angleToPlayer;
	SE_Play(shoot,40);
	loop(8){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		 CreateLooseLaserA1(bossX,bossY, 1.75, angleT, 125, 18, 1022, 0);
		angleT+=360/8;
	}
}
task FireB{
	let angleT = angleToPlayer-25;
	SE_Play(shoot,40);
	loop(8){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		 CreateLooseLaserA1(bossX,bossY,0.875 , angleT, 75, 18, 1017, 0);
		angleT+=360/8;
	}
}


