//--------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------
//Functions to be included in every script. Is automatically included in functions_general_stage.txt and functions_stage.txt
//--------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------

#include "./functions_sound.txt"

let pathScore = GetCurrentScriptDirectory ~ "../data/SCORE";
let pathConfig = GetCurrentScriptDirectory ~ "../data/CONFIG";

let VK_FLASH = VK_USER2+100;
let VK_SKIP = VK_USER2+101;
let VK_USER4 = VK_USER2+102;
let VK_USER5 = VK_USER2+103;
let VK_USER6 = VK_USER2+104;

let EV_SOUND_PLAY = 301;
let EV_SOUND_STOP = 302;

let EV_MUSIC_PLAY = 303;
let EV_MUSIC_STOP = 304;
let EV_MUSIC_FADE = 305;
let EV_MUSIC_VOL = 306;
let EV_MUSIC_C_STOP = 307;
let EV_MUSIC_C_FADE = 308;
let EV_MUSIC_PAUSE = 309;
let EV_MUSIC_RESUME = 310;

let EV_PLAYER_DIE = 400;




//parameter 1: an array of keys. ie: [VK_SHOT,VK_SLOWMOVE,VK_UP];
//parameter 2: an array of key states. ie: [KEY_PUSH,KEY_HOLD];
//return: returns true if ANY of the parameter keys are in ANY of the paramete states.
function IsKeyState(key,keystate)
{
	let val = false;
	ascent(i0 in 0..length(key))
		{
		ascent(i1 in 0..length(keystate))
			{
			if(GetVirtualKeyState(key[i0]) == keystate[i1])
				{
				val = true;
				break;
				}	
			}
		}
	return val;
}

//Gets the distance between two positions
function GetDistance(x,y,x1,y1)
{
	return (((x1-x)^2)+((y1-y)^2))^0.5;
}

//returns an integer from a string
function StringToInt(nameA)
{
	let nameM = "1";
	let num = 0;
	let dot = 0;	
	let dotS = false;
	ascent(i in 0..length(nameM))
		{
		let numA = 0;
		let name = ToString(nameM[i]);
		if(ToString(name) != ".")
			{
			alternative(name)
				case("0")
					{
					numA = 0;
					}
				case("1")
					{
					numA = 1;
					}
				case("2")
					{
					numA = 2;
					}
				case("3")
					{
					numA = 3;
					}
				case("4")
					{
					numA = 4;
					}
				case("5")
					{
					numA = 5;
					}
				case("6")
					{
					numA = 6;
					}
				case("7")
					{
					numA = 7;
					}
				case("8")
					{
					numA = 8;
					}
				case("9")
					{
					numA = 9;
					}
				others
					{
					RaiseError("This is not a valid number");
					}
			num+=numA*(10^(length(name)-1-i));
			}
		else
			{
			if(dotS == false)
				{
				dot = length(name)-1-i;
				dotS = true;
				}
			else
				{
				RaiseError("This is not a valid number");
				}
			}
		}
	num*=10^(-dot);
	return num;
}

task Obj_DelayDelete(target,time)
	{
	loop(time){yield;}
	Obj_Delete(target);
	}
