#e
#Title[gʏ1]
#Text[]
#ScriptVersion[2]

script_enemy_main
{
	let cx=GetCenterX();
	let cy=GetCenterY();
	let imgExRumia=GetCurrentScriptDirectory~"img\ExRumia.png";
	let imgExRumiaBack=GetCurrentScriptDirectory~"img\ExRumiaBack.png";
	LoadUserShotData(GetCurrentScriptDirectory~"shot.txt");
	@Initialize
	{
		SetMovePosition02(cx,cy,60);
		SetLife(3000);
		SetDamageRate(100,100);
		SetTimer(60);
		SetGraphicRect(1,1,64,64);
		SetInvincibility(60);
		LoadGraphic(imgExRumia);
		SetTexture(imgExRumia);	
		shottask;
		movetask;
	}
	@MainLoop
	{
			yield;
			SetCollisionA(GetX(),GetY(),24);
			SetCollisionB(GetX(),GetY(),24);
	}
	@Finalize
	{
	}
	@DrawLoop
	{
		SetGraphicRect(1,1,64,64);
		SetAlpha(255);
		DrawGraphic(GetX(),GetY());
	}
	task shottask
	{
		let s=0;
		wait(60);
		loop
		{
			wait(3);
			shot(s,rand(GetClipMinX,GetClipMaxX),GetClipMaxY+32);
			shot(s,rand(GetClipMinX,GetClipMaxX),GetClipMinY-32);
			shot(s,GetClipMaxX+32,rand(GetClipMinY,GetClipMaxY));
			shot(s,GetClipMinX-32,rand(GetClipMinY,GetClipMaxY));
		}
	}
	task movetask
	{
		yield;
		loop
		{
			wait(90);
			move(rand(40, 80), rand(-40, 40), 60,GetClipMinX + 32, GetClipMinY + 32,GetClipMaxX - 32, GetClipMinY + 160);
			wait(90);
		}
	}
	function shot(let shotid,let shotx,let shoty)
	{
		CreateShotA(shotid,shotx,shoty,0);
		SetShotDirectionType(ABSOLUTE);
		SetShotDataA(shotid,0,2,GetAngleToPlayer,0,0,0,112);
		FireShot(shotid);
	}
	function move(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);
	}
	function wait(w) 
	{
		loop(w)
		{
			yield;
		}
	}
}