#東方弾幕風
#Title[灯通常3]
#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-120,60);
		SetLife(1500);
		SetDamageRate(75,75);
		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;
		let angle=90;
		wait(100);
		loop
		{
			wait(2);
			shot(s,GetX+60,1,angle);
			shot(s,GetX+60,1,angle-90);
			shot(s,GetX+60,1,angle-180);
			shot(s,GetX+60,1,angle+90);
			shot(s,GetX-60,1,angle);
			shot(s,GetX-60,1,angle-90);
			shot(s,GetX-60,1,angle-180);
			shot(s,GetX-60,1,angle+90);
			angle+=8;
		}
	}
	task movetask
	{
		yield;
		wait(100);
		loop
		{
			wait(120);
			move(rand(40, 80),rand(-40, 40),60,GetClipMinX+32,GetClipMinY+64,GetClipMaxX-32,GetClipMinY+160);
		}
	}
	function shot(let shotid,let shotx,let speed,let angle)
	{
		CreateShotA(shotid,shotx,GetY,10);
		SetShotDataA(shotid,0,speed,angle,0,0,2,76);
		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;
		}
	}
}