#Title[いろは歌]
#Text[いろはにほへと]
#PlayLevel[EXTRA]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
	#include_function ".\lib\youmu.dnh"

	let name = "無情「咎なくて死す、本を津の小女」";
	
	xIni = cx;
	yIni = GetClipMinY + 96;
	
	let x;
	let y;
	
	sub onInitialize {
		CutIn(YOUMU, name, bossCut, 1, 1, 530, 650);
		SetScore(1000000);
		SetLife(2000);
		SetDamageRate(10, 10);
		SetTimer(60);
		back = CSD ~ "\img\back02.png";
		
		TMain;
	}

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

	sub onDrawLoop {
	}

	sub onFinalize {
		PlaySE(seFin);
	}

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

	task TMain {
		getReady(180);
		SetDamageRate(30, 100);
		
		loop {
			SetAction(ACT_STAND, 0);
			tsu;
			Concentration01(300);
			SetAction(ACT_CHARGE, 320);
			wait(320);
			SetAction(ACT_SLASH_H, 120);
			Explosion01(GetX, GetY, 0.5, 0.5, 120);
			conviction;
		}
	}
	
	task tsu {
		x = GetPlayerX;
		y = GetPlayerY;
		while(((x - GetPlayerX)^2 + (y - GetPlayerY)^2)^(1 / 2) <= 64) {
			x = rand(GetClipMinX + 128, GetClipMaxX - 128);
			y = rand(cy - 64, GetClipMaxY - 128);
		}
		let obj = createObjShot_(x, y, 0, 0, RING, BLUE, 2);
		Obj_SetCollisionToPlayer(obj, false);
		ObjShot_SetBombResist(obj, true);
		
		wait(560);
		
		Obj_Delete(obj);
	}
	
	sub conviction {
		let r = 0;
		let no = 3;
		let count = 1;
		let delay = 0;
		
		while(r < ((GetClipMinX - xIni)^2 + (GetClipMaxY - yIni)^2)^(1 / 2)) {
			loop(no) {
				shot(r, rand(0, 360), delay);
				count++;
				if(count % (no * 6 - 5) == 0) {
					no++;
				}
			}
			r += 15;
			delay++;
			yield;
		}
		
		wait(240);
		
		task shot (_r, _angle, _delay) {
			let _x = GetX + cos(_angle) * _r;
			let _y = GetY + sin(_angle) * _r;
			
			if(((x - _x)^2 + (y - _y)^2)^(1 / 2) <= 32) {
				return;
			}
			
			let obj = createObjShot_(_x, _y, 0, 0, SMALL, rand_int(0, 7), 0);
			
			wait(240 - _delay);
			
			let ox = Obj_GetX(obj);
			let oy = Obj_GetY(obj);
			let toPlayer = atan2(y - oy, x - ox);
			if(!isInScreen(ox, oy)) {
				Obj_Delete(obj);
				return;
			}
			loop(3) {
				createNmlShot01_(ox, oy, rand(0.2, 5), toPlayer + rand(10, 350), GRAIN, rand_int(0, 7), 3);
			}
			Obj_Delete(obj);
		}
	}
	#include_function ".\lib\六師外道body.dnh"
}