#PlayLevel[EXTRA]
#Player[FREE]
#ScriptVersion[2]

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

	xIni = cx;
	yIni = GetClipMinY + 92;

	sub onInitialize {
		SetScore(700000);
		SetLife(6000);
		SetTimer(60);
		SetDamageRate(130, 130);
		back = CSD ~ ".\img\back.png";

		TMain;
	}

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

	sub onDrawLoop {
	}

	sub onFinalize {
		DeleteGraphic(bossImg);
	}

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

	task TMain {
		getReady(120);

		loop {
			SetAction(ACT_SHOT_A, 30);
			createShotA;
			wait(60);
			createShotB;
			moveToPlayer(rand(40, 80), rand(-20, 20), 60, 32, 32, 32, 128);
			wait(120);
		}
	}

	sub createShotA {
		let baseAngle = GetAngleToPlayer;
		let way = 7;
		let span = 30;
		let angle = baseAngle - span * (way - 1) / 2;

		loop(way) {
			shot(angle);
			angle += span;
		}

		task shot(_angle) {
			let obj = createObjShot_(GetX, GetY, 2, _angle, BUTTER, GREEN, 0);

			wait(60);

			let _baseAngle = atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj));
			let _way = 11;
			let _span = 20;
			let _angle = _baseAngle - _span * (_way - 1) / 2;
			loop(_way) {
				createNmlShot01_(Obj_GetX(obj), Obj_GetY(obj), 1.5, _angle, BUTTER, GREEN, -1);
				_angle += _span;
			}

			Obj_Delete(obj);
		}
	}

	sub createShotB {
		let baseAngle = rand(0, 360);
		let way = 24;
		let span = 360 / way;
		let angle = baseAngle;

		loop(way) {
			createNmlShot01_(GetX, GetY, 0.7, angle, BUTTER, YELLOW, 0);
			createNmlShot01_(GetX, GetY, 1.4, angle, BUTTER, YELLOW, 0);
			createNmlShot01_(GetX, GetY, 2.1, angle, BUTTER, YELLOW, 0);
			angle += span;
		}
	}
	#include_function ".\lib\˜ZŽtŠO“¹body.dnh"
}