#東方弾幕風
#Title[幻実「ブルーローズ」]
#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
	{
		SetScore(30000);
		SetLife(300);
		SetDamageRate(10,10);
		SetMovePosition02(cx,cy-120,60);
		SetTimer(60);
		SetGraphicRect(1,1,64,64);
		SetInvincibility(60);
		LoadGraphic(imgExRumia);
		SetTexture(imgExRumia);	
		shottask;
		movetask;
		CutIn(YOUMU,"幻実「ブルーローズ」",0,0,0,0,0);
	}
	@MainLoop
	{
		yield;
		SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),24);
	}
	@Finalize
	{
		loop(8)
		{
			CreateItem(ITEM_SCORE,cx+rand(-100,100),rand(20,100));
		}
	}
	@DrawLoop
	{
		SetGraphicRect(1,1,64,64);
		SetAlpha(255);
		DrawGraphic(GetX(),GetY());
	}
	task shottask
	{
		let angle=0;
		let speed=1;
		let right=0;
		let s=0;
		let s2=1;
		wait(120);
		loop
		{
			wait(60);
			right=5;
			angle=GetAngleToPlayer;
			loop(2)
			{
				loop(8)
				{
					speed=3;
					loop(36)
					{
						SetShotDirectionType(ABSOLUTE);
						CreateShotA(s,GetX,GetY,20);	
						SetShotDataA(s,0,speed,angle,0,0,0,6);
						FireShot(s);
						angle+=right;
						speed-=0.05;
					}
					angle+=45;
				}
				right=-5;
			}
		}
	}
	task movetask
	{
		wait(120);
		loop
		{
			wait(60);
			move(rand(40, 80), rand(-40, 40), 60,GetClipMinX + 32, GetClipMinY + 32,GetClipMaxX - 32, GetClipMinY + 160);
		}
	}
	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;
		}
	}
}