////////////////////////////////////////////////////
// Distance Functions                             //
////////////////////////////////////////////////////

// Returns the distance from (x1, y1) to (x2, y2)
function Distance(x1, y1, x2, y2){
	return ((x1-x2)^2 + (y1-y2)^2)^0.5;
}

// Returns the distance from the given point to the player.
function DistanceFromPlayer(x, y){
	return Distance(x, y, GetPlayerX, GetPlayerY);
}

// Returns the distance from the given point to the boss.
function DistanceFromBoss(x, y){
	return Distance(x, y, GetEnemyX, GetEnemyY);
}

// Returns the distance from the given point to the enemy.
function DistanceFromEnemy(x, y){
	return Distance(x, y, GetX, GetY);
}

////////////////////////////////////////////////////
// Angle Functions                                //
////////////////////////////////////////////////////

// Returns the angle from (x1, y1) to (x2, y2)
function AngleFrom(x1, y1, x2, y2){
	return atan2(y2-y1, x2-x1);
}

// Returns the angle from the player to the given point.
function AngleFromPlayer(x, y){
	return AngleFrom(GetPlayerX, GetPlayerY, x, y);
}

// Returns the angle from the given point to the player.
function AngleToPlayer(x, y){
	return AngleFrom(x, y, GetPlayerX, GetPlayerY);
}

// Returns the angle from the boss to the given point.
function AngleFromBoss(x, y){
	return AngleFrom(GetEnemyX, GetEnemyY, x, y);
}

// Returns the angle from the given point to the boss.
function AngleToBoss(x, y){
	return AngleFrom(x, y, GetEnemyX, GetEnemyY);
}

// Returns the angle from the enemy to the given point.
function AngleFromEnemy(x, y){
	return AngleFrom(GetX, GetY, x, y);
}

// Returns the angle from the given point to the enemy.
function AngleToEnemy(x, y){
	return AngleFrom(x, y, GetX, GetY);
}

////////////////////////////////////////////////////
// Effect Functions                               //
////////////////////////////////////////////////////

// Creates an effect like a bullet's delay but does not fire a bullet.
function CreateDelayEffect(x, y, color, duration){
	CreateShotA(255, x, y, duration);
	SetShotDataA(255, 0, 500, 0, 0, 0, 0, color);
	SetShotKillTime(255, 0);
	FireShot(255);
}

// Creates an effect like a laser's source glow but does not fire a laser.
function CreateGlowEffect(x, y, color, duration){
	CreateLaserA(254, x, y, 1, 1, color, duration);
	SetShotDataA(254, 0, 0, 0, 0, 0, 0);
	SetShotKillTime(254, duration);
	FireShot(254);
}

////////////////////////////////////////////////////
// String Functions                               //
////////////////////////////////////////////////////

// Truncates a number into an integer and converts it to a string.
function IntString(number){
	let str = ToString(number);
	let str2 = "";
	let i = 0;
	while (str[i] != '.'){
		str2 = str2 ~ [str[i]];
		i++;
	}
	return(str2); 
}

////////////////////////////////////////////////////
// Information Functions                          //
////////////////////////////////////////////////////

// Returns the lower of the two numbers.
function lower(num1, num2){
	if(num1 < num2){
		return num1;
	}
	else if(num2 < num1){
		return num2;
	}
	else if(num1 == num2){
		return num1;
	}
}

// Returns the greater of the two numbers.
function upper(num1, num2){
	if(num1 > num2){
		return num1;
	}
	else if(num2 < num1){
		return num2;
	}
	else if(num1 == num2){
		return num1;
	}
}