#e
#Title[ԒʏP]
#Text[]
#ScriptVersion[2]
#PlayLevel[Normal]


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(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;
		Concentration01(60);
		wait(60);
		let po=GetY-100;
		loop(10)
		{
			shot(s,GetX-100,po);
			po+=20;
		}	
		let po=GetY+100;
		loop(10)
		{
			shot(s,GetX+100,po);
			po-=20;
		}
		let po=GetX+100;
		loop(10)
		{
			shot(s,po,GetY-100);
			po-=20;
		}
		let po=GetX-100;
		loop(10)
		{
			shot(s,po,GetY+100);
			po+=20;
		}
		yield;
		loop
		{
			loop(120)
			{
				yield;
			}
			Concentration01(60);
			loop(60)
			{
				yield;
			}
			let po=GetY-100;
			loop(10)
			{
				shot(s,GetX-100,po);
				po+=20;
			}	
			let po=GetY+100;
			loop(10)
			{
				shot(s,GetX+100,po);
				po-=20;
			}
			let po=GetX+100;
			loop(10)
			{
				shot(s,po,GetY-100);
				po-=20;
			}
			let po=GetX-100;
			loop(10)
			{
				shot(s,po,GetY+100);
				po+=20;
			}
		}
	}
	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)
	{
		let gp =GetAngleToPlayer;
		CreateShotA(shotid,shotx,shoty,10);
		SetShotDirectionType(SEQUENCE);
		SetShotDataA(shotid,0,0,0,0,0,2,9);
		SetShotDataA(shotid,120,1,rand(gp-60,gp+60),0.1,0,2,25);
		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;
		}
	}
}