#include".\shot\AllStarShot_Const.txt"
#include".\Resources.txt"
#include".\selibrary.txt"
#include".\OzzieEffects.txt"

let Nazrin = ID_INVALID;
let NazrinX = 0;
let NazrinY = 0;

@Event{
    SetTimer(60);
    SetLife(700);
    SetScore(1000000);
}
 
@Initialize{
	SetAutoDeleteObject(true);
	Nazrin = ObjEnemy_Create(OBJ_ENEMY_BOSS);	
    ObjEnemy_Regist(Nazrin);	
	
	renderNazrinUFO(Nazrin);
	BossManage;
	MainTask;     
}


@MainLoop{
	yield;
}

task MainTask{	
	movement;
	ObjEnemy_SetDamageRate(Nazrin,0,0);
	wait(60);
	SE_Play(charge1,50);
	if(GetCommonData("Difficulty",1)==1){ConcentrationA2(Nazrin,"MAGIC",60,7,150,[0,0,255]);}
	if(GetCommonData("Difficulty",1)==2){ConcentrationA2(Nazrin,"MAGIC",60,7,150,[255,0,255]);}
	if(GetCommonData("Difficulty",1)==3){ConcentrationA2(Nazrin,"MAGIC",60,7,150,[255,0,0]);}
	if(GetCommonData("Difficulty",1)==4){ConcentrationA2(Nazrin,"MAGIC",60,7,150,[0,255,0]);}
	wait(120);
	ObjEnemy_SetDamageRate(Nazrin,24,4);
	if(GetCommonData("Difficulty",1)==1){FireE;}
	if(GetCommonData("Difficulty",1)==2){FireN;}
	if(GetCommonData("Difficulty",1)==3){FireH;}
	if(GetCommonData("Difficulty",1)==4){FireL;}
}

task movement{
	ObjMove_SetDestAtSpeed(Nazrin,GetCenterX,GetCenterY-120,5);
}

task FireE{
	let Frame = 0;
	let speed;
	let graphic = 506;
	loop{
	Frame = 0;
	loop(15){
	speed = rand(2,5);
	SE_Play(shot,30);
		CreateShotA1(NazrinX+Frame,NazrinY,speed,90,graphic,15);
		CreateShotA1(NazrinX+Frame,NazrinY,speed,270,graphic,15);
		CreateShotA1(NazrinX-Frame,NazrinY,speed,90,graphic,15);
		CreateShotA1(NazrinX-Frame,NazrinY,speed,270,graphic,15);
	Frame+= 25;
	wait(2);}
	ObjMove_SetDestAtWeight(Nazrin,GetCenterX-rand(-110,+110),GetCenterY-120,10,4);
	wait(60);
	}
}

task FireN{
	let Frame = 0;
	let speed;
	let graphic = 504;
	loop{
	Frame = 0;
	loop(30){
	speed = rand(2,5);
	SE_Play(shot,30);
		CreateShotA1(NazrinX+Frame,NazrinY,speed,90,graphic,15);
		CreateShotA1(NazrinX+Frame,NazrinY,speed,270,graphic,15);
		CreateShotA1(NazrinX-Frame,NazrinY,speed,90,graphic,15);
		CreateShotA1(NazrinX-Frame,NazrinY,speed,270,graphic,15);
	Frame+= 12;
	wait(2);}
	ObjMove_SetDestAtWeight(Nazrin,GetCenterX-rand(-110,+110),GetCenterY-120,10,4);
	wait(60);
	}
}

task FireH{
	let Frame = 0;
	let speed;
	let graphic = 503;
	loop{
	Frame = 0;
	loop(40){
	speed = rand(2,6);
	SE_Play(shot,30);
		CreateShotA1(NazrinX+Frame,NazrinY,speed,90,graphic,15);
		CreateShotA1(NazrinX+Frame,NazrinY,speed,270,graphic,15);
		CreateShotA1(NazrinX-Frame,NazrinY,speed,90,graphic,15);
		CreateShotA1(NazrinX-Frame,NazrinY,speed,270,graphic,15);
	Frame+= 10;
		if(Frame>230){Frame=0;}
	wait(2);}
	ObjMove_SetDestAtWeight(Nazrin,GetCenterX-rand(-110,+110),GetCenterY-120,10,4);
	wait(60);
	}
}

task FireL{
	let Frame = 0;
	let speed;
	let graphic = 511;
	loop{
	Frame = 0;
	loop(80){
	speed = rand(1,6.5);
	SE_Play(shot,30);
		CreateShotA1(NazrinX+Frame,NazrinY,speed,90,graphic,15);
		CreateShotA1(NazrinX+Frame,NazrinY,speed,270,graphic,15);
		CreateShotA1(NazrinX-Frame,NazrinY,speed,90,graphic,15);
		CreateShotA1(NazrinX-Frame,NazrinY,speed,270,graphic,15);
	Frame+= 21;
		if(Frame>230){Frame=0;}
	wait(2);}
	ObjMove_SetDestAtWeight(Nazrin,GetCenterX-rand(-110,+110),GetCenterY-120,10,4);
	wait(60);
	}
}


task BossManage{

	while(ObjEnemy_GetInfo(Nazrin,INFO_LIFE)>0){
        NazrinX = ObjMove_GetX(Nazrin);
        NazrinY = ObjMove_GetY(Nazrin);

        ObjEnemy_SetIntersectionCircleToShot(Nazrin, NazrinX, NazrinY, 20);
        ObjEnemy_SetIntersectionCircleToPlayer(Nazrin, NazrinX,NazrinY, 10);
		yield;
	}
	
	Obj_Delete(Nazrin);
	
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    CloseScript(GetOwnScriptID()); 
}