#東方弾幕風
#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,0);
		SetMovePosition02(cx,cy-120,60);
		SetTimer(60);
		SetGraphicRect(1,1,64,64);
		SetInvincibility(60);
		LoadGraphic(imgExRumia);
		SetTexture(imgExRumia);	
		shottask;
		movetask;
		bombtask;
		CutIn(YOUMU,"幻実「ブルーローズ」",0,0,0,0,0);
	}
	@MainLoop
	{
		yield;
	}
	@Finalize
	{
		loop(8)
		{
			CreateItem(ITEM_SCORE,cx+rand(-100,100),rand(20,100));
		}
	}
	@DrawLoop
	{
		SetGraphicRect(1,1,64,64);
		DrawGraphic(GetX(),GetY());
	}
	task shottask
	{
		let angle=0;
		let speed=1;
		let right=0;
		let s=0;
		let s2=1;
		let a=120;
		wait(a);
		loop
		{
			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;
			}
			wait(a);
			if(a>60)
			{
				a-=10;
			}
		}
	}
	task movetask
	{
		let a=120;
		wait(a);
		loop
		{
			move(rand(40, 80), rand(-40, 40), 60,GetClipMinX + 32, GetClipMinY + 32,GetClipMaxX - 32, GetClipMinY + 160);
			wait(a);
			if(a>60)
			{
				a-=10;
			}
		}
	}
	task bombtask
	{
		loop
		{
			if(OnBomb)
			{
				SetAlpha(64);
				SetDamageRate(0,0);
			}
			else
			{
				SetAlpha(255);
				SetDamageRate(10,0);
				SetCollisionA(GetX(),GetY(),24);
				SetCollisionB(GetX(),GetY(),24);
			}
			yield;
		}
	}
	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;
		}
	}
}