
#include "./default_system/Default_Effect.txt"
#include "./default_system/AllStarShot_Const.txt"
#include"./functions.txt"

@Initialize {
	// define a boss in bossObj and register it
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossObj);
	
	// move boss to desired x y location at desired speed
	
	ObjMove_SetDestAtSpeed(bossObj,300,100,3.5);
	mainTask;	// run mainTask
	
} 

@Event { 
	// setting the boss timer and life
	alternative(GetEventType()) 
	case(EV_REQUEST_LIFE) { 
		SetScriptResult(5000);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(41);
	}
} 

@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 {

} 

task mainTask { 
	RenderBoss;
	movement;
	TSpell;
	yield;
} 

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

task movement {
	wait(120);
	loop{
		loop(1){
			ObjMove_SetDestAtSpeed(bossObj,50,100,4);
			LaserRun;
			wait(180);
			ObjMove_SetDestAtSpeed(bossObj,300,100,4);
			LaserRun;
			wait(180);
		}
		ObjMove_SetDestAtSpeed(bossObj,192,100,3.5);
		wait(60);
		loop(6){
			circle;
			wait(10);
		}
		wait(60);
	}
}

task LaserPoint {
	let angleT = angleToPlayer;
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
	Laserdelay;
		let obj = CreateStraightLaserA1(bossX, bossY, angleT, 512, 20, 20, 1001, 60);
		ObjStLaser_SetSource(obj, true); //Do not show the laser source
		ObjLaser_SetGrazeInvalidFrame(obj, 5); //Allows for up to 1 graze each 5 frames
		ObjLaser_SetInvalidLength(obj, 5, 5); //5 percent of each end of the laser is safe
}

task circle {
	SE_Play(shoot2,50);
	let angleT = angleToPlayer-rand(-15,15);
	loop(32){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		CreateShotA1(bossX,bossY,1,angleT,rand(209,223),10);
		angleT+=360/32
	}
}
task LaserRun{
	loop(20){
	LaserPoint;
	wait(3);
	}
	
}
task Laserdelay{
	wait(60);
	SE_Play(laser,40);
}
