#e
#Title[鉹ʏ2]
#Text[]
#ScriptVersion[2]
script_enemy_main
{
	let cx=GetCenterX();//STGV[̒SxW擾
	let cy=GetCenterY();//STGV[̒SyW擾
	let doll=0;
	let imgExRumia=GetCurrentScriptDirectory~"img\ExRumia.png";
	let imgExRumiaBack=GetCurrentScriptDirectory~"img\ExRumiaBack.png";
	LoadUserShotData(GetCurrentScriptDirectory~"shot.txt");
	@Initialize
	{
		SetLife(750);
		SetDamageRate(25,25);
		SetMovePosition02(cx,cy-120,60);
		SetTimer(60);
		SetGraphicRect(1,1,64,64);
		SetInvincibility(180);
		LoadGraphic(imgExRumia);
		LoadGraphic(GetCurrentScriptDirectory~".\img\ma.png");
		SetTexture(imgExRumia);
		shottask;
		movetask;
	}
	@MainLoop
	{
		yield;
		SetCollisionA(GetX(),GetY(),24);//蔻(e)o^
		SetCollisionB(GetX(),GetY(),24);//蔻(̓)o^
	}
	@Finalize
	{
	}
	@DrawLoop
	{
		SetGraphicRect(1,1,64,64);
		SetAlpha(255);
		DrawGraphic(GetX(),GetY());
	}
	task shottask
	{
		SetShotAutoDeleteClip(128,128,128,128);
		let angle=0;
		let speed=0;
		wait(120);
		loop
		{
			loop(3)
			{
				angle=rand(0,360);
				loop(12)
				{
					loop(5)
					{
						CreateObjShot(2,angle,RED32,0);
						angle+=72;
					}
					angle+=3;
					wait(3);
				}
				angle=rand(0,360);
				loop(20)
				{
					hoto(4.5,angle,32,155,4);
					hoto(4.5,angle,32,155,-4);
					angle+=18;
				}
				wait(120);
			}
			wait(150);
			loop(20)
			{
				speed=2;
				loop(5)
				{
					CreateShot01(GetX,GetY,speed,GetAngleToPlayer,94,10);
					speed+=1;
				}
				yield;
			}
			wait(30);
			loop(20)
			{
				speed=2;
				loop(5)
				{
					CreateShot01(GetX,GetY,speed,GetAngleToPlayer+20,89,10);
					CreateShot01(GetX,GetY,speed,GetAngleToPlayer-20,89,10);
					speed+=1;
				}
				yield;
			}
			wait(150);
		}
	}
	task movetask
	{
		yield;
		wait(120);
		loop
		{
			loop(3)
			{
				move(rand(40, 80),rand(-40, 40),60,GetClipMinX+32,GetClipMinY+48,GetClipMaxX-32,GetClipMinY+160);
				wait(36);
				wait(120);
			}
			SetMovePosition02(GetClipMaxX+60,cy,60);
			wait(120);
			SetMovePosition02(GetClipMaxX+60,GetClipMaxY,30);
			wait(30);
			SetMovePosition02(GetClipMinX-60,GetClipMaxY,20);
			wait(50);
			SetMovePosition02(GetClipMaxX+60,GetClipMaxY,20);
			wait(20);
			SetMovePosition02(GetClipMaxX+60,cy,30);
			wait(30);
			SetMovePosition02(cx,cy-120,60);
			wait(120);
		}
	}
	task CreateObjShot(let speed,let angle, let graphic, let delay)
	{
		let count=1;
		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)
			{
				Obj_SetX(obj, GetClipMinX*2 - Obj_GetX(obj));
				Obj_SetAngle(obj, 180 - Obj_GetAngle(obj));
				count--;
			}
			if(Obj_GetX(obj)>GetClipMaxX)
			{
				Obj_SetX(obj, GetClipMaxX*2 - Obj_GetX(obj));
				Obj_SetAngle(obj, 180 - Obj_GetAngle(obj));
				count--;
			}
			if(Obj_GetY(obj)<GetClipMinY)
			{
				Obj_SetY(obj, GetClipMinY*2 - Obj_GetY(obj));
				Obj_SetAngle(obj, 360 - Obj_GetAngle(obj));
				count--;
			}
			if(count<=0){ break; }
			yield;
		}
	}
	task hoto(let speed,let angle,let length,let graphic,let angle2)
	{
		let count=0;
		let obj = Obj_Create(OBJ_SINUATE_LASER);
		Obj_SetPosition(obj,GetX, GetY);
		Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, graphic);
		ObjShot_SetDelay(obj, 0);
		ObjSinuateLaser_SetLength(obj, length);
		ObjSinuateLaser_SetWidth(obj, 12);
		while(!Obj_BeDeleted(obj))
		{
			if(count<100)
			{
				speed-=0.025;
				angle-=angle2/2;
			}
			if(count<120)
			{
				angle-=angle2/2;
			}
			if(count>120&&speed<5)
			{
				speed+=0.05;
			}
			count++;
			Obj_SetSpeed(obj, speed);
			Obj_SetAngle(obj, angle);
			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;
		}
	}
}