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

@Initialize {
	SetForbidPlayerShot(true);
	SetForbidPlayerSpell(true);
	// define a boss in bossObj and register it
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossObj);
	// Warp the boss to this location when loaded
	ObjMove_SetPosition(bossObj,192,-100);
	
	// move boss to desired x y location at desired speed
	ObjMove_SetDestAtSpeed(bossObj, 192,100,5);
	SetPlayerLife(4);
	BGM_Play(bgm1,100);
	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(780);
	Shoot;

	loop{
		loop(5){
			fire;
			wait(10);
		}
		wait(80);
		ObjMove_SetDestAtSpeed(bossObj,50,160,2.5);
		wait(80);
		loop(6){
			circle;
				wait(10);
			}
			wait(80);
			ObjMove_SetDestAtSpeed(bossObj,187,130,2.5);
		wait(80);
		laserA1;
		wait(80);
		ObjMove_SetDestAtSpeed(bossObj,300,160,2.5);
		wait(80);
		Line;
		wait(80);
		ObjMove_SetDestAtSpeed(bossObj, 192,100,5);
		wait(80);
	}
}

task fire {
	let dir = angleToPlayer;
	Shootdelay;
	loop(18){
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
	ascent(i in 1..5){
		CreateShotA1(bossX,bossY,1*i,dir,23,20);
		}
		dir+=360/18 ;
	}
}

task circle {
	let angleT = angleToPlayer-rand(-15,15);
	Shootdelay2;
	loop(32){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		CreateShotA1(bossX,bossY,1,angleT,rand(209,223),20);
		angleT+=360/32
	}
}

task laserA1 {
	let angleT = angleToPlayer; 
	Laserdelay;
    loop(3){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		let obj = CreateStraightLaserA1(bossX, bossY, angleT, 512, 20, 20, 1001, 40);
		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
		angleT += 360/3; //Increments by 60 degrees clockwise each time the block is run
	}
}

task Line {
	let angleT = angleToPlayer;
	Shootdelay;
	ascent(i in 2..12){
		CreateShotA1(bossX,bossY,1/2*i,angleT-5,51,20);
		CreateShotA1(bossX,bossY,1/2*i,angleT-2.5,51,20);
		CreateShotA1(bossX,bossY,1/2*i,angleT,51,20);
		CreateShotA1(bossX,bossY,1/2*i,angleT+2.5,51,20);
		CreateShotA1(bossX,bossY,1/2*i,angleT+5,51,20);
	}
}

task Shoot{
	SetForbidPlayerShot(false);
	SetForbidPlayerSpell(false);
}

task Shootdelay{
	wait(20);
	SE_Play(shoot,40);
}
task Shootdelay2{
	wait(20);
	SE_Play(shoot2,50);
}
task Laserdelay{
	wait(40);
	SE_Play(laser,40);
}

