script_enemy_main {
	#include_function ".\includeKoishi.txt"
	task TMain {
		SetDamageRate(150, 70);
		SetMovePosition03(GetCenterX, GetCenterY-100, 10, 9);
		SetInvincibility(180);
		while(OnPlayerMissed || OnBomb) { SetInvincibility(180); yield; }
		wait(120);
		TCharge(GetX, GetY);
		PlaySE2("charge");
		wait(60);
		attack1;
		attackH;
	}
	let field = 10;
	task attack1 {
		SetShotAutoDeleteClip(32, 32, 32, 32);
		let a = rand(0,360);
		let num = [80, 90, 100, 100][GetDifficulty];
		let ring = [10, 15, 20, 20][GetDifficulty];
		let safe = [2, 2, 2, 2][GetDifficulty];
		loop {
			loop(2) {
				PlaySE2("kira00");
				ascent(i in 0..num) {
					if(i%ring <= safe) {
						CreateRoseShot(a+i*360/num, 1, false);
					}
				}
				ascent(i in 0..num) {
					if(i%ring > safe) {
						CreateRoseShot(a+i*360/num, 0, true);
					}
				}
				a+=[22, 22, 31, 31][GetDifficulty];
				if(field < 25) { field+=3; } else { field=25; }
				wait([110, 90, 90, 75][GetDifficulty]);
			}
			loop(2) {
				PlaySE2("kira00");
				ascent(i in 0..num) {
					if(i%ring <= safe) {
						CreateRoseShot(a+i*360/num, 0, false);
					}
				}
				ascent(i in 0..num) {
					if(i%ring > safe) {
						CreateRoseShot(a+i*360/num, 1, true);
					}
				}
				a+=[22, 22, 31, 31][GetDifficulty];
				if(field < 25) { field+=3; } else { field=25; }
				wait([110, 90, 90, 75][GetDifficulty]);
			}
		}
	}
	let rosearr = [[],[]];
	task attackH {
		loop {
			let doexpand = false;
			let ang = 0;
			if(GetAngleToPlayer < 90 || GetAngleToPlayer > 270) {
				ang = atan2(GetPlayerY-GetY, GetPlayerX-GetX);
			} else {
				ang = GetAngleToPlayer;
			}
			ascent(c in 0..2) {
				ascent(i in 0..length(rosearr[c])) {
					let obj = rosearr[c][i];
					let ang2 = ang-Obj_GetAngle(obj); while(ang2 < 0) { ang2+=360; }
					ObjShot_SetGraphic(obj, 1+5*c+[0, 216][ang2 < field || ang2 > 360-field]);
				}
			}
			yield;
		}
	}
	task CreateRoseShot (let angle, let color, let grow) {
		angle%=360;
		let obj = Obj_Create(OBJ_SHOT);
		if(grow) { rosearr[color] = rosearr[color] ~ [obj]; }
		Obj_SetPosition(obj, GetX, GetY);
		Obj_SetSpeed(obj, 3/2);
		Obj_SetAngle(obj, angle);
		ObjShot_SetDelay(obj, 15);
		ObjShot_SetBombResist(obj, true);
		ObjShot_SetGraphic(obj, 1+color*5);
		let time = 30;
		while(!Obj_BeDeleted(obj)) {
			yield;
		}
		if(grow) { ascent(i in 0..length(rosearr[color])) { if(obj == rosearr[color][i]) { rosearr[color] = erase(rosearr[color], i); break; } } }
	}
}