#e
#Title[XyJ]
#Text[̉iv@]
#ScriptVersion[2]


script_enemy_main {
	let name	= "@Bủiv@ցv";
	let imgBoss	= "script\img\ExRumia.png";

	// ʒu
	let xIni	= GetCenterX;
	let yIni	= GetClipMinY + 140;

	@Initialize {
		CutIn(YOUMU, name, "", 0, 0, 0, 0);

		SetLife(8000);
		SetTimer(99);
		SetDamageRate(5, 5);
		SetScore(500000);

		LoadGraphic(imgBoss);
		SetTexture(imgBoss);
		setGraphicStop;

		TMain;
	}

	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);

		yield;
	}

	@DrawLoop {
		DrawGraphic(GetX, GetY);
	}

	@Finalize {
		DeleteGraphic(imgBoss);
	}

	// C^XN
	task TMain {
		yield;

		standBy;

		//e
		TRate;
		TShot;
	}

	task TShot()
	{
		let level = 0;
		let shot_flg = 0;
		
		TShot_sub(0);
		loop
		{
			if (GetLife() < 2000 && level < 3) { shot_flg = 1; level = 3; }
			else if (GetLife() < 4000 && level < 2) { shot_flg = 1; level = 2; }
			else if (GetLife() < 6000 && level < 1) { shot_flg = 1; level = 1; }
			
			if (shot_flg)
			{
				shot_flg = 0;
				SetInvincibility(60);
				DeleteEnemyShot(ALL);
				wait(30);
				TShot_sub(level);
			}
			yield;
		}
	}

	//eˏo^XN
	task TShot_sub(level)
	{
		let size = 150;
		let aspd = -0.35;
		let spd = 1.2;
		let tmp = aspd*size;
		let way = 30;
		let lway = 2;

		let swt = 30;

		PlaySE(GetCurrentScriptDirectory ~ "/se/eco00_e.wav");

		if (level > 2)
		{
			aspd = 1.3;
			spd = 1.8;
			tmp = aspd*size;
			lway = 8;
			swt = 90;
		}
		else if (level > 1)
		{
			aspd = -0.7;
			spd = 1.5;
			tmp = aspd*size;
			lway = 6;
			swt = 75;
		}
		else if (level > 0)
		{
			aspd = 0.5;
			spd = 1.35;
			tmp = aspd*size;
			lway = 4;
			swt = 60;
		}
		shot_haguruma(GetX, GetY, 40, 0, 150, 180, aspd, ORANGE21, spd, ORANGE12, 80, 60);
		
		let size2 = 60;
		if (level > 2)
			{ size2 = 80; }
		else if (level > 1)
			{ size2 = 70; }
		else if (level > 0)
			{ size2 = 65; }

		let tmp2 = size2/size;
		let tmp2w = int(way*tmp2);
		shot_haguruma(GetX, GetY, tmp2w, 360/tmp2w/2, size2, 0, -tmp/size2, RED21, spd*1.3, RED12, 80, 30);
		if (level > 0)
		{
			shot_haguruma(GetX, GetY, int(way*tmp2), 360/tmp2w/2, size2-20, 0, -tmp/size2, RED21, spd*1.1, RED12, 80, 30);
		}
		if (level > 2)
		{
			shot_haguruma(GetX, GetY, int(way*tmp2), 360/tmp2w/2, size2-40, 0, -tmp/size2, RED21, spd*0.9, RED12, 80, 30);
		}

		let size3 = (size-size2)/2;
		let tmp2 = size3/size;
		let tmp_r = (size+size2)/2;
		
		ascent (let i in 0 .. lway)
		{
			shot_haguruma(GetX+cos((i+0.5)*360/lway+90)*tmp_r, GetY+sin((i+0.5)*360/lway+90)*tmp_r,
				int(way*tmp2), 0, size3, 0, tmp/size3, BLUE21, spd*0.8, BLUE12, 95, swt);
		}

	}

	function shot_haguruma(x, y, way, half, size, a_plus, c_angle, graphic, speed, graphic2, wt, timer)
	{
		ascent(let i in 0 .. way)
		{
			shot_haguruma_sub(x, y, i*360/way+half, size, a_plus, c_angle, graphic, speed, graphic2, wt, timer);
		}
	}

	task shot_haguruma_sub(x, y, angle, size, a_plus, c_angle, graphic, speed, graphic2, wt, timer)
	{
		//IuWFNge̍쐬
		let obj = Obj_Create(OBJ_SHOT);
		
		//p[^̐ݒ
		Obj_SetPosition(obj, x, y);
		ObjShot_SetGraphic(obj, graphic);
		Obj_SetAutoDelete(obj,false);
		ObjShot_SetBombResist(obj, true);
		
		let tmp_r = 0;
		let tmp_timer = wt;
		let tmp_p = size/wt;
		let tmp_ap = 90;
		if (c_angle < 0) { tmp_ap = -90; }
		
		while(!Obj_BeDeleted(obj)) {
			if (tmp_timer < 1) {
				tmp_timer = timer;
				PlaySE(GetCurrentScriptDirectory ~ "/se/hit82.wav");
				CreateShot01(Obj_GetX(obj), Obj_GetY(obj), speed, angle+tmp_ap, graphic2, 20);
			}
			if (size > tmp_r) { tmp_r += tmp_p;}
			angle += c_angle;
			
			Obj_SetPosition(obj, x+cos(angle)*tmp_r, y+sin(angle)*tmp_r);
			Obj_SetAngle(obj, angle+a_plus);
			tmp_timer--;
			yield;
		}

		Obj_Delete(obj);
	}

	// _[W[g̕ύX
	task TRate {
		wait(300);
		SetDamageRate(90, 90);
	}

	// ʒuֈړAUJn
	sub standBy {
		let wIni = 120;

		SetMovePosition02(xIni, yIni, wIni);
		setGraphicMove;

		SetInvincibility(wIni);
		wait(wIni);

		setGraphicPose;
	}

	// OtBbN̐ݒ
	sub setGraphicStop  { SetGraphicRect(  0,   0,  64,  64); }
	sub setGraphicPose  { SetGraphicRect( 64,   0, 128,  64); }
	sub setGraphicLeft  { SetGraphicRect(128,   0, 192,  64); }
	sub setGraphicRight { SetGraphicRect(192,   0, 256,  64); }

	sub setGraphicMove {
		if(GetSpeedX < 0) {
			setGraphicLeft;
		} else {
			setGraphicRight;
		}
	}
	

	// w t[҂
	function wait(w) {
		loop(w) { yield; }
	}
}
