
#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(12500);
	}
	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("Psychic Sign \"Stored Power\"",20);
	setOverlay;
	TEnd;
	yield;
} 

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

task movement {
	wait(180);
	
	SE_Play(laserSFX,40);
		loop{
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		fire;
		fireB;
		fireC;
		wait(10);
		fireLaser;
		}
}
task fireLaser {
	let angleT= rand(0,360);
	SE_Play(shoot2,50);
	loop(4){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
	 CreateLooseLaserA1(bossX,bossY, 3, angleT, 75, 18, rand(1020,1025), 0);
		angleT+=360/4;
		wait(1);
	}
}

task fire{
	let angleT=270;
	loop(1){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		let obj = CreateShotA1(bossX,bossY,2,angleT,rand(785,788),0);
		BulletReflectAll(obj);
		}
		angleT+=180/1;
}
task fireB{
	let angleT=190;
	loop(1){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		let obj = CreateShotA1(bossX,bossY,2,angleT,rand(785,788),0);
		BulletReflectAll(obj);
		}
		angleT+=180/1;
}
task fireC{
	let angleT=350;
	loop(1){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		let obj = CreateShotA1(bossX,bossY,2,angleT,rand(785,788),0);
		BulletReflectAll(obj);
		}
		angleT+=180/1;
}



task BulletReflectAll(obj){
	while(ObjMove_GetX(obj)>0&&ObjMove_GetX(obj) < GetStgFrameWidth&&ObjMove_GetY(obj) >0) {yield;}
	if (ObjMove_GetX(obj) <=  0){
		ObjMove_SetX(obj, 0);
		ObjMove_SetAngle(obj, rand(0,90));
	} 
	else if (ObjMove_GetX(obj) >= GetStgFrameWidth){
		ObjMove_SetX(obj, GetStgFrameWidth);
		ObjMove_SetAngle(obj, rand(90,180));
	} else if(ObjMove_GetY(obj)<=0) {
		ObjMove_SetY(obj, 0);
		ObjMove_SetAngle(obj, rand(-182,-358));
	}
	wait(10);
	ObjShot_SetGraphic(obj,rand(20,26));
}