InstallFont(GetCurrentScriptDirectory() ~ "./Fonts/Russell Square Regular.ttf");

/* 
let die = SoundSFX(GSD~"./../lib/se/morri.wav");

	BFX_Explosion(bx, by, 100, 60*1);
	wait(60*1/2);
	
	StartSlow(TARGET_ALL, 15);
		PlaySFX(die);
		BFX_Explosion(bx, by, 300, 60*1);
		wait(60*2);
	StopSlow(TARGET_ALL); 
	
	DeleteShotAll(TYPE_ALL, TYPE_FADE);
	wait(60*1); */
	
function angtoP(obj){return atan2(py - ObjMove_GetY(obj), px - ObjMove_GetX(obj));}
function angtoB(obj){return atan2(by - ObjMove_GetY(obj), bx - ObjMove_GetX(obj));}	
function stgw(){return GetStgFrameWidth();}
function stgh(){return GetStgFrameHeight();}
function px(){return GetPlayerX();}
function py(){return GetPlayerY();}
function bx(){return ObjMove_GetX(objBoss);}
function by(){return ObjMove_GetY(objBoss);}
function gx(){return GetStgFrameWidth() / 2;}
function gy(){return GetStgFrameHeight() / 2;}
function wait(n){loop(n){yield;}}
function NormalizeAngle(angle){ angle %= 360; if(angle<0){angle += 360;} return angle; }
function GetAngularDistance(angle1, angle2){ let distance = NormalizeAngle(angle2 - angle1); if(distance>180){ distance-=360; } return distance; }

task DrawName(name, type){
	let objText = ObjText_Create();
	let alpha = 255;
	ObjText_SetText(objText, name);
	ObjText_SetFontType(objText, "Russell Square Regular");
	ObjText_SetFontSize(objText, 15);
	if(type == "MAMI"){
		ObjText_SetFontColorBottom(objText, 153, 102, 0);
		ObjText_SetFontColorTop(objText, 102, 51, 0);
	}
	if(type == "FIRE"){
		ObjText_SetFontColorTop(objText, 204, 51, 51);
		ObjText_SetFontColorBottom(objText, 166, 89, 89);
	}
	if(type == "YELLOW"){
		ObjText_SetFontColorBottom(objText, 255, 255, 102);
		ObjText_SetFontColorTop(objText, 179, 179, 0);
	}
	if(type == "DREAM"){
		ObjText_SetFontColorTop(objText, 255, 153, 255);
		ObjText_SetFontColorBottom(objText, 102, 0, 102);
	}
	ObjText_SetFontBorderType(objText, BORDER_SHADOW);
	ObjText_SetFontBorderColor(objText, 39, 24, 69);
	ObjText_SetFontBorderWidth(objText, 2);
	ObjText_SetHorizontalAlignment(objText, ALIGNMENT_LEFT);
	ObjRender_SetPosition(objText, 0, 10, 0);
	Obj_SetRenderPriority(objText,0.7);
	
	while(!Obj_IsDeleted(objBoss)){
		if(GetPlayerY > 80 && alpha < 255){
			alpha+=10;
		}
		if(GetPlayerY <= 80 && alpha > 100){
			alpha-=10;
		}
		ObjRender_SetAlpha(objText,alpha);
		yield;
	}
	
	Obj_Delete(objText);
}

task DrawAlert(name){
	let objText = ObjText_Create();
	let alpha = 255;
	ObjText_SetText(objText, name);
	ObjText_SetFontType(objText, "Russell Square Regular");
	ObjText_SetFontSize(objText, 14);
	ObjText_SetFontColorTop(objText, 204, 51, 51);
	ObjText_SetFontColorBottom(objText, 166, 89, 89);
	ObjText_SetFontBorderType(objText, BORDER_SHADOW);
	ObjText_SetFontBorderColor(objText, 39, 24, 69);
	ObjText_SetFontBorderWidth(objText, 3);
	ObjText_SetHorizontalAlignment(objText, ALIGNMENT_LEFT);
	ObjRender_SetPosition(objText, gx - 165, gy - 60, 0);
	Obj_SetRenderPriority(objText,0.7);
	
	while(!Obj_IsDeleted(objBoss)){
		if(GetPlayerY > 80 && alpha < 255){
			alpha+=10;
		}
		if(GetPlayerY <= 80 && alpha > 100){
			alpha-=10;
		}
		ObjRender_SetAlpha(objText,alpha);
		yield;
	}
	
	Obj_Delete(objText);
}

//Fuck it have some more laziness functions

function getx(obj){return ObjMove_GetX(obj);}
function gety(obj){return ObjMove_GetY(obj);}
function geta(obj){return ObjMove_GetAngle(obj);}
function getsp(obj){return ObjMove_GetSpeed(obj);}

function getrx(obj){return ObjRender_GetX(obj);}
function getry(obj){return ObjRender_GetY(obj);}
function getra(obj){return ObjRender_GetAngleZ(obj);}

function setx(obj,x){ObjMove_SetX(obj,x);}
function sety(obj,y){ObjMove_SetY(obj,y);}
function seta(obj,a){ObjMove_SetAngle(obj,a);}
function setsp(obj,s){ObjMove_SetSpeed(obj,s);}
function setpos(obj,x,y){ObjMove_SetPosition(obj,x,y);}
function setrpos(obj,x,y,z){ObjRender_SetPosition(obj,x,y,z);}

//check whether an object is safe to dereference
function isnull(obj){
	//can't check if it hasn't been set, initialize to NULL if there's a chance it'll come up
	if(!obj){return true;} //if it's null
	if(Obj_IsDeleted(obj)){return true;} //if it's been deleted
	return false;
}

function sec(i){ return 1/cos(i);}
function csc(i){ return 1/sin(i);}
function cot(i){ return 1/tan(i);}
function sqrt(i){ return power(i, -2);}

function rand_int(low,high){
	return round(rand(low-0.49999,high+0.49999));
}

task BGM_Play(name, vol){
	let bgm = ObjSound_Create;
		ObjSound_Load(bgm, GetCurrentScriptDirectory() ~ "BGM/" ~ name ~ ".ogg");
		ObjSound_SetRestartEnable(bgm, true);
		ObjSound_SetVolumeRate(bgm, vol);
		ObjSound_SetLoopEnable(bgm, true);
		ObjSound_SetSoundDivision(bgm, SOUND_BGM);
	
	if(GetCommonData("music", false) == false){
		ObjSound_Play(bgm);
	}
}

task Difficulty(num){
	let pic = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(pic, GetCurrentScriptDirectory() ~ "FX/diffs.png");
	ObjSprite2D_SetSourceRect(pic, 0, 59, 165, 86);
	alternative(num)
		case(0){ObjSprite2D_SetSourceRect(pic, 0, 0, 161, 27);} //Easy
		case(1){ObjSprite2D_SetSourceRect(pic, 0, 29, 208, 56);} //Normal
		case(2){ObjSprite2D_SetSourceRect(pic, 0, 59, 165, 86);} //Hard
		case(3){ObjSprite2D_SetSourceRect(pic, 0, 88, 200, 115);} //Unreal
		case(4){ObjSprite2D_SetSourceRect(pic, 0, 122, 183, 174);} //Easy Ex
		case(5){ObjSprite2D_SetSourceRect(pic, 0, 183, 178, 203);} //Ex
		case(6){ObjSprite2D_SetSourceRect(pic, 0, 212, 184, 270);} //Ex+a
	ObjSprite2D_SetDestCenter(pic);
	ObjRender_SetBlendType(pic, BLEND_ALPHA);
	ObjRender_SetScaleXYZ(pic, 1, 1, 0);
	Obj_SetRenderPriority(pic, 1);
	
	ObjRender_SetPosition(pic, 530, GetScreenHeight() - 50, 0);
}