#e
#Title[鉹ʏ1]
#Text[]
#ScriptVersion[2]
script_enemy_main
{
	let alpha=255;
	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(1000);
		SetDamageRate(50,50);
		SetMovePosition02(cx,cy-120,60);
		SetTimer(60);
		SetGraphicRect(1,1,64,64);
		SetInvincibility(180);
		LoadGraphic(imgExRumia);
		LoadGraphic(GetCurrentScriptDirectory~".\img\enemy\faily_red.png");
		LoadGraphic(GetCurrentScriptDirectory~".\img\ma.png");
		SetTexture(imgExRumia);
		shottask;
	}
	@MainLoop
	{
		yield;
		SetCollisionA(GetX(),GetY(),24);//蔻(e)o^
		SetCollisionB(GetX(),GetY(),24);//蔻(̓)o^
	}
	@Finalize
	{
	}
	@DrawLoop
	{
		SetGraphicRect(1,1,64,64);
		SetAlpha(alpha);
		DrawGraphic(GetX(),GetY());
		if(alpha>0)
		{
			alpha--;
		}
	}
	task shottask
	{
		wait(120);
		CreateEnemyFromScript("fam",GetX,GetY,0,0,0);
		CreateEnemyFromScript("fam",GetX,GetY,0,0,120);
		CreateEnemyFromScript("fam",GetX,GetY,0,0,240);
		loop
		{
			CreateEnemyFromScript("doll",GetX,GetY,0,0,0);
			CreateEnemyFromScript("unblela",rand(GetClipMinX,GetClipMaxX),GetClipMinY-24,0,0,240);
			wait(120);
		}
	}
	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;
		}
	}
}
script_enemy doll
{
	LoadUserShotData(GetCurrentScriptDirectory~"shot.txt");
	@Initialize
	{
		SetLife(500);
		SetDamageRate(0,0);
		SetMovePosition02(rand(GetClipMaxX,GetClipMinX),rand(GetClipMinY,GetCenterY),60);
		SetInvincibility(60);
		SetTexture(GetCurrentScriptDirectory~".\img\enemy\faily_red.png");
		shottask;
		movetask;
	}
	@MainLoop
	{
		yield;
		SetCollisionB(GetX(),GetY(),24);
	}
	@Finalize
	{
	}
	@DrawLoop
	{
		SetShotDirectionType(ABSOLUTE);
		SetGraphicRect(0,0,32,35);
		SetGraphicAngle(0,0,0);
		SetAlpha(255);
		DrawGraphic(GetX(),GetY());
	}
	task shottask
	{
		CreateObjLaser(GetX,GetY,atan2(GetEnemyY-GetY,GetEnemyX-GetX),0,3,152,0);
		wait(120);
		loop(6)
		{
			wait(6);
			CreateShot01(GetX,GetY,2,GetAngleToPlayer+rand(-10,10),89,0);
		}
	}
	task movetask
	{
		SetMovePosition02(rand(GetClipMaxX,GetClipMinX),rand(GetClipMinY,GetCenterY),60);
		wait(240);
		SetMovePosition02(GetEnemyX,GetEnemyY,60);
		wait(60);
		VanishEnemy;
	}
	task CreateObjLaser(let x, let y, let angle, let length,let width, let graphic, let delay)
	{
		let count=0;
		let obj = Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, 0);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, graphic);
		ObjShot_SetDelay(obj, delay);
		ObjLaser_SetLength(obj, length);
		ObjLaser_SetWidth(obj, width);
		ObjLaser_SetSource(obj, false);
		Obj_SetAutoDelete(obj,false);
		Obj_SetCollisionToPlayer(obj, false);
	        loop(delay){ yield; }
		while(!Obj_BeDeleted(obj))
		{
			Obj_SetPosition(obj, GetX, GetY);
			Obj_SetAngle(obj,atan2(GetEnemyY-GetY,GetEnemyX-GetX));
			ObjLaser_SetLength(obj,((GetX - GetEnemyX) ^ 2 + (GetY - GetEnemyY) ^ 2) ^ 0.5);
			yield;
			count++;
			if(count>=300)
			{
				Obj_Delete(obj);
			}
		}
	}
	function wait(w) 
	{
		loop(w)
		{
			yield;
		}
	}
}
script_enemy fam
{
	let angle=1;
	LoadUserShotData(GetCurrentScriptDirectory~"shot.txt");
	@Initialize
	{
		SetLife(500);
		SetDamageRate(0,0);
		SetInvincibility(60);
		SetTexture(GetCurrentScriptDirectory~".\img\ma.png");
		shottask;
		movetask;
	}
	@MainLoop
	{
		yield;
		SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),24);
	}
	@Finalize
	{
	}
	@DrawLoop
	{
		SetGraphicAngle(0,0,angle);
		SetGraphicRect(0,0,64,64);
		SetAlpha(255);
		DrawGraphic(GetX(),GetY());
		angle++;
	}
	task shottask
	{
		loop
		{
			wait(3);
			CreateShot01(GetX,GetY,1.2,atan2(GetY-GetEnemyY,GetX-GetEnemyX),70,0);
		}
	}
	task movetask
	{
		let angle=GetArgument;
		let angle2=0;
		let r=0;
		let r2=-90;
		loop
		{
			SetX(GetEnemyX+r*cos(angle));
			SetY(GetEnemyY+r*sin(angle));
			angle+=2*sin(angle2);
			angle2++;
			r=60+60*sin(r2);
			r2+=0.794;
			yield;
		}
	}
	function wait(w) 
	{
		loop(w)
		{
			yield;
		}
	}
}
script_enemy unblela
{
	let angle=1;
	LoadUserShotData(GetCurrentScriptDirectory~"shot.txt");
	@Initialize
	{
		SetLife(50);
		SetDamageRate(100,100);
		SetInvincibility(60);
		SetTexture(GetCurrentScriptDirectory~".\img\ma.png");
	}
	@MainLoop
	{
		yield;
		SetSpeed(1);
		SetAngle(90);
		SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),24);
	}
	@Finalize
	{
		let angle=GetAngleToPlayer;
		loop(24)
		{
			CreateShot02(GetX,GetY,0,angle,0.05,3,27,0);
			angle+=15;
		}
	}
	@DrawLoop
	{
		SetGraphicAngle(0,0,angle);
		SetGraphicRect(0,0,64,64);
		SetAlpha(255);
		DrawGraphic(GetX(),GetY());
		angle++;
	}
	function wait(w) 
	{
		loop(w)
		{
			yield;
		}
	}
}