#東方弾幕風
#Title[発想「弾幕天動説」]
#Text[試作]
#ScriptVersion[2]

script_enemy_main
{//Enemy01
	let count=0;
	let cx=GetCenterX();//STGシーンの中心x座標を取得
	let cy=GetCenterY();//STGシーンの中心y座標を取得
	let imgExRumia=GetCurrentScriptDirectory~"img\ExRumia.png";
	LoadUserShotData(GetCurrentScriptDirectory~"shot.txt");
	@Initialize
	{
		SetScore(30000);
		SetLife(600);
		SetDamageRate(10,0);
		SetMovePosition02(cx,cy-120,60);
		SetTimer(60);
		SetGraphicRect(1,1,64,64);
		SetInvincibility(60);
		LoadGraphic(imgExRumia);
		SetTexture(imgExRumia);	
		shottask;
		subtask;
		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
	{
		SetTexture(imgExRumia);	
		SetGraphicRect(1,1,64,64);
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
		SetAlpha(255);
		DrawGraphic(GetX,GetY);
	}
	task shottask
	{
		wait(120);
		let angle=rand(0,360);
		loop
		{
			CreateObjShot(2,angle,139,0);
			angle+=rand(9,15);
			wait(6);
		}
	}
	task subtask
	{
		let speed=0;
		wait(120);
		Explosion01(GetPlayerX,GetPlayerY,3,1,60);
		loop
		{
			if(GetX<GetClipMinX-20)
			{
				SetX(GetClipMaxX+10)
			}
			if(GetX>GetClipMaxX+20)
			{
				SetX(GetClipMinX-10)
			}
			if(GetY<GetClipMinY-20)
			{
				SetY(GetClipMaxY+10)
			}
			if(GetY>GetClipMaxY+20)
			{
				SetY(GetClipMinY-10)
			}
			if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
			{
				speed=1;
			}
			else
			{
				speed=3;
			}
			if(GetKeyState(VK_DOWN)==KEY_HOLD)
			{
				SetY(GetY-speed)
			}
			if(GetKeyState(VK_UP)==KEY_HOLD)
			{
				SetY(GetY+speed)
			}
			if(GetKeyState(VK_RIGHT)==KEY_HOLD)
			{
				SetX(GetX-speed)
			}
			if(GetKeyState(VK_LEFT)==KEY_HOLD)
			{
				SetX(GetX+speed)
			}
			SetPlayerX(224);
			SetPlayerY(350);
			yield;
		}
	}
	task CreateObjShot(let speed,let angle, let graphic, let delay)
	{
		let count=2;
		let speed2=0;
		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, delay);
		while(!Obj_BeDeleted(obj))
		{
			if(Obj_GetX(obj)<GetClipMinX-20&&count>0)
			{
				Obj_SetX(obj,GetClipMaxX+10);
				count--;
			}
			if(Obj_GetX(obj)>GetClipMaxX+20&&count>0)
			{
				Obj_SetX(obj,GetClipMinX-10);
				count--;
			}
			if(Obj_GetY(obj)<GetClipMinY-20&&count>0)
			{
				Obj_SetY(obj,GetClipMaxY+10);
				count--;
			}
			if(Obj_GetY(obj)>GetClipMaxY+20&&count>0)
			{
				Obj_SetY(obj,GetClipMinY-10);
				count--;
			}
			if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
			{
				speed2=1;
			}
			else
			{
				speed2=3;
			}
			if(GetKeyState(VK_DOWN)==KEY_HOLD)
			{
				Obj_SetY(obj,Obj_GetY(obj)-speed2)
			}
			if(GetKeyState(VK_UP)==KEY_HOLD)
			{
				Obj_SetY(obj,Obj_GetY(obj)+speed2)
			}
			if(GetKeyState(VK_RIGHT)==KEY_HOLD)
			{
				Obj_SetX(obj,Obj_GetX(obj)-speed2)
			}
			if(GetKeyState(VK_LEFT)==KEY_HOLD)
			{
				Obj_SetX(obj,Obj_GetX(obj)+speed2)
			}
			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;
		}
	}
}