#e
#Title[u̎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(600);
		SetMovePosition02(cx,cy-120,60);
		SetTimer(80);
		SetGraphicRect(1,1,64,64);
		SetInvincibility(360);
		LoadGraphic(imgExRumia);
		SetTexture(imgExRumia);	
		shottask;
		bombtask;
		CutIn(YOUMU,"u̎v",0,0,0,0,0);
	}
	@MainLoop
	{
		yield;
		SetCollisionA(GetX(),GetY(),24);//蔻(e)o^
		SetCollisionB(GetX(),GetY(),24);//蔻(̓)o^
	}
	@Finalize
	{
		loop(16)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-30,30),GetY+rand(-30,30));
		}
		CreateItem(ITEM_BOMB,GetX,GetY);
	}
	@DrawLoop
	{
		SetTexture(imgExRumia);	
		SetGraphicRect(1,1,64,64);
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
		DrawGraphic(GetX,GetY);
	}
	task shottask
	{
		wait(120);
		let x=0;
		let y=0;
		let angle=90;
		let angle2=0;
		let speed=0;
		let count=0;
		let time=0;
		let l=1;
		CreateShot01(GetX,GetY,3,90,33,10);
		wait(30);
		loop(80)
		{
			CreateObjShot(GetX,GetY,2.5,angle,9,10);
			angle-=count^2/500;
			count++;
			wait(1);
		}
		wait(60);
		count=0;
		loop
		{
			loop(l)
			{
				x=GetX+rand(count/5,count/5*-1);
				y=GetY+rand(count/5,count/5*-1);
				angle2=rand(count/24,count/24*-1);
				speed=rand(2.5+count/240,2.5-count/240);
				CreateObjShot(x,y,speed,270+20*sin(angle)+angle2,9,10);
			}
			angle+=12;
			time++;
			if(count<240&&time>60)
			{
				count+=2;
			}
			if(time>60)
			{
				l=2;
			}
			if(time%120==0&&time>60)
			{
				CreateShot02(GetX,GetY,5,GetAngleToPlayer,-0.05,2.5,25,10);
			}
			wait((240-count)/60+1);
		}
	}
	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;
		}
	}
	task CreateObjShot(let x,let y,let speed,let angle, let graphic, let delay)
	{
		let py=1;
		let speedy=0;
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,x,y);
		Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, graphic);
		ObjShot_SetDelay(obj, delay);
		loop(delay){ yield; }
		while(!Obj_BeDeleted(obj))
		{
			if(Obj_GetY(obj)-py<5)
			{
				speedy+=0.02;
			}
			py=Obj_GetY(obj);
			Obj_SetY(obj,Obj_GetY(obj)+speedy);
			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;
		}
	}
}