

// w フレームだけ待つ
function wait(w) 
{
    loop(w) { yield; }
}

function WaitForZeroEnemy()//敵数が0になるまで待機する関数
{
	while(GetEnemyNum() != 0){yield;}
}

function GetDistanceToPlayer
{
	let dis=((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2)^0.5;
	return(dis);
}

task OutDamageRateZero
{
loop
{
	if(GetX<GetClipMinX-16 || GetClipMaxX+16<GetX || GetY<GetClipMinY-16 || GetClipMaxY+16<GetY)
	{
		SetDamageRate(0,0);
	}
	else
	{
		if(GetDistanceToPlayer<=60)
		{
			SetDamageRate(105,105);
		}
		if(GetDistanceToPlayer<=150)
		{
			SetDamageRate(102.5,102.5);
		}
		else
		{
			SetDamageRate(100,100);
		}
	}

yield;
}

}

function FinalizeItemSet(num)
{
let type;
alternative(GetCommonData("BURSTLEVEL"))
case(0)
{
	type=3;
}
case(1)
{
	type=4;
}
case(2)
{
	type=5;
}
case(3)
{
	type=6;
}
		if(!BeVanished)
		{
		loop(num)
		{
			ItemSet(GetX,GetY,type);
			if(GetDistanceToPlayer<=60)
			{
				ItemSet(GetX,GetY,3);
			}
			if(GetDistanceToPlayer<=90)
			{
				ItemSet(GetX,GetY,3);
			}
			if(GetDistanceToPlayer<=120)
			{
				ItemSet(GetX,GetY,3);
			}
			if(GetDistanceToPlayer<=150)
			{
				ItemSet(GetX,GetY,3);
			}
		}
		}
}

function ItemSet(x,y,type)//アイテム生成関数
{
	let XY=GetCommonDataDefault("ItemXY",[]);//共通データ内容を変数に渡す
	XY=XY~[x,y,type];//
	SetCommonData("ItemXY",XY);//共通データに変更後の配列を渡す
}

task Lissajous(R,G,B)
{
let a=5;
let b=6;
let A=50;
let B=40;
let angle=0;
let X;
let Y;
let t=0;
loop
{
	X=A*cos(a*t);
	Y=B*sin(b*t+angle);
	LissajousEffect1(GetX+X,GetY+Y,R,G,B);
	LissajousEffect1(GetX-X,GetY+Y,R,G,B);
	t+=1;
	yield;
}

}


task LissajousEffect1(X,Y,R,G,B)
{
		let randrect=5;
		let scax=0.3;
		let scay=0.3;
		let angle=0;
		let Xangle=-90;
		let Yangle=-90;	
		let Zangle=0;
		let RotateAngle=3;
		let alpha=200;
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,GetCurrentScriptDirectory~"..\img\CircleEffect.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -24+rand(-randrect,randrect), -24+rand(-randrect,randrect));
		ObjEffect_SetVertexXY(obj, 1,  24+rand(-randrect,randrect), -24+rand(-randrect,randrect));
		ObjEffect_SetVertexXY(obj, 2,  24+rand(-randrect,randrect),  24+rand(-randrect,randrect));
		ObjEffect_SetVertexXY(obj, 3, -24+rand(-randrect,randrect),  24+rand(-randrect,randrect));
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  48, 0);
		ObjEffect_SetVertexUV(obj, 2, 48,  48);
		ObjEffect_SetVertexUV(obj, 3, 0, 48);


		Obj_SetPosition(obj,X,Y);
		ObjEffect_SetScale(obj, scax,scay);
		loop(10)
		{
			Obj_SetY(obj,Obj_GetY(obj)-1);
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,alpha,R,G,B);
			}
			ObjEffect_SetScale(obj, scax,scay);
			scax+=0.3/10;
			scay+=0.3/10;
			alpha-=200/10;
			yield;
		}
		Obj_Delete(obj);
}

function MoveToPlayer02(xMove, yAdd, frame, left, top, right, bottom)
{
	let x;
	let y;

	if(GetPlayerX < GetX)
	{
		x = GetX - xMove;
		if(x < left)
		{
		x = GetX + xMove;
		}
	}
	else
	{
		x = GetX + xMove;
		if(right < x)
		{
			x = GetX - xMove;
		}
	}

	y = GetY + yAdd;
	if(y < top)
	{
		y = top;
	}
	else if(bottom < y)
	{
		y = bottom;
        }

        SetMovePosition02(x, y, frame);
	SetAction(ACT_MOVE,60);
}

function MoveToPlayer03(xMove, yAdd, weight,maxspeed, left, top, right, bottom)
{
	let x;
	let y;

	if(GetPlayerX < GetX)
	{
		x = GetX - xMove;
		if(x < left)
		{
		x = GetX + xMove;
		}
	}
	else
	{
		x = GetX + xMove;
		if(right < x)
		{
			x = GetX - xMove;
		}
	}

	y = GetY + yAdd;
	if(y < top)
	{
		y = top;
	}
	else if(bottom < y)
	{
		y = bottom;
        }

        SetMovePosition03(x, y, weight,maxspeed);
	SetAction(ACT_MOVE,60);
}


///////////////////////////////////////////////////////////////////////////////////////////
	let csd = GetCurrentScriptDirectory;
	let imgLetter =csd ~ "img/border.png"; 
	let BulletNum;
////////////////////////////////////////////////////////////////////////////////////////////
