#Title[ウパニシャッド]
#Text[奥義]
#PlayLevel[EXTRA]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
	#include_function ".\lib\youmu.dnh"
	
	let name = "奥義「隣に座ってひそひそ話す」";
	
	xIni = cx;
	yIni = cy;
	
	sub onInitialize {
		CutIn(YOUMU, name, bossCut, 1, 1, 530, 650);
		SetScore(800000);
		SetLife(10000);
		SetDamageRate(10, 10);
		SetTimer(55);
		back = CSD ~ "\img\back01.png";
		
		TMain;
	}

	sub onMainLoop {
		SetCollisionA(GetX, GetY, 32);
		yield;
	}

	sub onDrawLoop {
	}

	sub onFinalize {
		createItems(ITEM_SCORE, 18, 32);
	}

/////////////////////////////////////////////////////////////////////

	task TMain {
		getReady(240);
		SetAction(ACT_CHARGE, 999999);
		SetDamageRate(135, 250);
		
		let obj = createObjShot_(GetX, GetY, 0, 0, RING, RED, -1);
		Obj_SetCollisionToPlayer(obj, false);
		ObjShot_SetBombResist(obj, true);
		
		let r = ((cx - GetClipMinX)^2 + (cy - GetClipMinY)^2)^(1 / 2) + 8;
		let count = 0;
		let no = 5;
		
		loop {
			loop(no) {
				shot(rand(0, 360));
			}
			count++;
			if(count % 3 == 0) {no += 3; }
			wait(max(20, 100 - (no - 4) * 3));
		}
		
		task shot(_angle) {
			let angle = _angle;
			let _obj = createObjShot_(GetX + cos(angle) * r, GetY + sin(angle) * r, 0, angle + 90, BUTTER, rand_int(0, 7), 0);
			Obj_SetAutoDelete(_obj, false);
			
			let _r = r;
			let dr = -0.03;
			let ddr = -0.0005;
			
			loop {
				dr += ddr;
				_r += dr;
				angle += 0.5;
				let _x = cx + cos(angle) * _r;
				let _y = cy + sin(angle) * _r;
				
				if(_r <= 18) {
					Obj_Delete(_obj);
					return;
				}
				
				Obj_SetAngle(_obj, atan2(_y - Obj_GetY(_obj), _x - Obj_GetX(_obj)));
				Obj_SetSpeed(_obj, ((_x - Obj_GetX(_obj))^2 + (_y - Obj_GetY(_obj))^2)^(1 / 2));
				yield;
			}
		}
	}
	#include_function ".\lib\六師外道body.dnh"
}