#e
#Title[nuGVFgXg[v]
#Text[]
#ScriptVersion[2]

script_enemy_main
{//Enemy01
	let count=0;
	let cx=GetCenterX();//STGV[̒SxW擾
	let cy=GetCenterY();//STGV[̒SyW擾
	let imgExRumia=GetCurrentScriptDirectory~"img\ExRumia.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,"nuGVFgXg[v",0,0,0,0,0);
	}
	@MainLoop
	{
		yield;
		SetCollisionA(GetX(),GetY(),24);//蔻(e)o^
		SetCollisionB(GetX(),GetY(),24);//蔻(̓)o^
	}
	@Finalize
	{
		loop(8)
		{
			CreateItem(ITEM_SCORE,cx+rand(-100,100),rand(20,100));
		}
	}
	@DrawLoop
	{
		SetTexture(imgExRumia);	
		SetGraphicRect(1,1,64,64);
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
		SetAlpha(255);
		DrawGraphic(GetX,GetY);
	}
	task shottask
	{
		wait(120);
		loop
		{
			CreateObjShot(2,GetAngleToPlayer,32,4);
			wait(120);
		}
	}
	task movetask
	{
		yield;
		loop
		{
			wait(240);
			move(rand(40, 80),rand(-40, 40),60,GetClipMinX+32,GetClipMinY+64,GetClipMaxX-32,GetClipMinY+160);
		}
	}
	task CreateObjShot(let speed,let angle, let graphic, let count)
	{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,GetX, GetY);
		Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, graphic);
		ObjShot_SetDelay(obj, 0);
		while(!Obj_BeDeleted(obj))
		{
			if(Obj_GetX(obj)<GetClipMinX)
			{
				Obj_SetX(obj, GetClipMinX*2 - Obj_GetX(obj));
				Obj_SetAngle(obj, 180 - Obj_GetAngle(obj));
				count--;
				loop(20)
				{
					CreateShot01(Obj_GetX(obj),Obj_GetY(obj),rand(0.5,3),rand(0,360),16,0);
				}
			}
			if(Obj_GetX(obj)>GetClipMaxX)
			{
				Obj_SetX(obj, GetClipMaxX*2 - Obj_GetX(obj));
				Obj_SetAngle(obj, 180 - Obj_GetAngle(obj));
				count--;
				loop(20)
				{
					CreateShot01(Obj_GetX(obj),Obj_GetY(obj),rand(0.5,3),rand(0,360),16,0);
				}
			}
			if(Obj_GetY(obj)<GetClipMinY)
			{
				Obj_SetY(obj, GetClipMinY*2 - Obj_GetY(obj));
				Obj_SetAngle(obj, 360 - Obj_GetAngle(obj));
				count--;
				loop(20)
				{
					CreateShot01(Obj_GetX(obj),Obj_GetY(obj),rand(0.5,3),rand(0,360),16,0);
				}
			}
			if(Obj_GetY(obj)>GetClipMaxY)
			{
				Obj_SetY(obj, GetClipMaxY*2 - Obj_GetY(obj));
				Obj_SetAngle(obj, 360 - Obj_GetAngle(obj));
				count--;
				loop(20)
				{
					CreateShot01(Obj_GetX(obj),Obj_GetY(obj),rand(0.5,3),rand(0,360),16,0);
				}
			}
			if(count==3)
			{
				ObjShot_SetGraphic(obj, 88);
			}
			if(count==2)
			{
				ObjShot_SetGraphic(obj, 72);
			}
			if(count==1)
			{
				ObjShot_SetGraphic(obj, 112);
			}
			if(count<=0){ break; }
			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;
		}
	}
}