let csd = GetCurrentScriptDirectory;

#include_function ".\AnimationLib.dnh"


let Capture = csd~"se/capture.wav";
let BALL = csd~"./haku.png";
let bga=0;
let Charge = csd~"se/charge.wav";
let Defeat = csd~"se/defeat.wav";
let Laser = csd~"se/laser.wav";
let Option = csd~"se/option.wav";
let Shot1 = csd~"se/shot1.wav";
let Shot2 = csd~"se/shot2.wav";
let Shot3 = csd~"se/shot3.wav";
let Slash = csd~"se/slash.wav";
let time01 = csd~"se/time01.wav";
let time02 = csd~"se/time02.wav";


//~~~~~~~~Gameplay functions~~~~~~~~

let bgs = 0;



sub CaptureCheck
{
if (GotSpellCardBonus == true){PlaySE(Capture);}
}

function Wait(t){loop(t){yield;}}

let timerframe = 0;

sub Timer //Play timer sound effect when timer is low.
{
if (timerframe == 0)
	{
	if (GetTimer > 11){timerframe = -60;}
	if (GetTimer > 5 && GetTimer <= 11){PlaySE(time01); timerframe = -60;}
	if (GetTimer > 1 && GetTimer <= 5){PlaySE(time02); timerframe = -60;}
	if (GetTimer == 1){PlaySE(time02);}	
	}
timerframe++;
}

task Vulnerable(a,b,c,d,e)
{
SetDamageRate(a,b);
Wait(c);
SetDamageRate(d,e);
}

function Concentration(t,a,b,c)
{
SetColor(a,b,c);
Concentration01(t);
SetColor(255,255,255);
}

sub AimingOn{SetShotDirectionType(PLAYER);}
sub AimingOff{SetShotDirectionType(ABSOLUTE);}


//~~~~~~~~Math 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);}

// 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);}

function PM{return rand_int(0,1)*2-1;}

function InField(x, y){
if(x<GetClipMaxX+32 && x>GetClipMinX-32 && y<GetClipMaxY+32 && y>GetClipMinY-32){return true;}
else{return false;}
}

//~~~~~~~~Simple Movement~~~~~~~~


