
#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,192,100,3.5);
	mainTask;	// run mainTask
	
} 

@Event { 
	// setting the boss timer and life
	alternative(GetEventType()) 
	case(EV_REQUEST_LIFE) { 
		SetScriptResult(6000);
	}
	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,20);
	yield;
} 

@Finalize {

} 

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

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

task movement {
	wait(120);
	loop{
		//fire;
		fire2;
		wait(30);
	}
}

task fire {
	let angleT = angleToPlayer;
	loop(5){
		CreateShotA1(bossX*sin(30),bossY*cos(30),4,angleT, 324,120);
		angleT+=360/5
	}
}

task fire2 {
	let angleT = rand(0,360);
	loop(20){
		Shootdelay;
	ascent(i in 1..4){
		CreateShotA1(bossX+40*cos(angleT),bossY+40*sin(angleT),i,angleT, 23,30);
	}
		angleT+=360/20
	}
}

task Shootdelay{
	wait(30);
	SE_Play(shoot,40);
}