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

function GetEnemyX{
	if(ObjMove_GetX(objEnemy)!=0){return ObjMove_GetX(objEnemy);}
	else{return -1000;}
}

function GetEnemyY{
	if(ObjMove_GetY(objEnemy)!=0){return ObjMove_GetY(objEnemy);}
	else{return -1000;}
}

function GetAngleToEnemy(obj){
	let angle=atan2(GetEnemyY-ObjMove_GetY(obj),GetEnemyX-ObjMove_GetX(obj));
	return angle;
}

function GetPointAngle(x1,y1,x2,y2){
	let angle=atan2(y1-y2,x1-x2);
	return angle;
}

function GetDistance(x1,y1,x2,y2){
return(((x2-x1)^2+(y2-y1)^2)^(1/2));
}

function GetEX1(x,gapLength,gapWidth,gapAngle,gapAlign){
	return x+gapWidth*cos(gapAngle)*cos(gapAlign)-gapLength*sin(gapAngle)*sin(gapAlign);
}

function GetEY1(y,gapLength,gapWidth,gapAngle,gapAlign){
	return y+gapWidth*cos(gapAngle)*sin(gapAlign)+gapLength*sin(gapAngle)*cos(gapAlign);
}

task DamageRateAtFrame(shot,bomb,frame)
{
	let time=frame;
	while(IsPlayerSpellActive)
	{
		ObjEnemy_SetDamageRate(objEnemy, 0,0);
		time--;
		yield;
	}
	while(time>0)
	{
		time--;
		yield;
	}
	ObjEnemy_SetDamageRate(objEnemy, shot,bomb);
}

task BorderMove(leftX,rightX,topY,bottomY,weight,time)
{
	let vx = (rightX-leftX)/2;
	let vy = (bottomY-topY)/2;
	let rx = rand(-vx,vx);
	let ry = rand(-vy,vy);
	if(GetEnemyX-leftX+rx<0){rx*=-1;}
	if(GetEnemyX-rightX+rx>0){rx*=-1;}
	if(GetEnemyY-topY+ry<0){ry*=-1;}
	if(GetEnemyY-bottomY+ry>0){ry*=-1;}
	ObjMove_SetDestAtWeight(objEnemy, GetEnemyX+rx, GetEnemyY+ry, weight,time);
}

task SetHoming(obj,maxTraverse,time,delay){ 
	wait(delay);
	let angle = ObjMove_GetAngle(obj);
	let count = 0;
    while(! Obj_IsDeleted(obj) && count<time) {
		count++;
        ObjMove_SetAngle(obj, angle);
        let dir = atan2(GetPlayerY - ObjMove_GetY(obj),GetPlayerX - ObjMove_GetX(obj));
        let diff = dir - angle;
        while(diff >= 180) { diff -= 360; } 
        while(diff < -180) { diff += 360; }
        let diffAbs = (|diff|);
        if(diffAbs < maxTraverse) {angle = dir;} 
		else {angle += maxTraverse * diff / diffAbs;}
		yield;
    }
	}