#e
#Title[uu[}[L[v]
#Text[]
#Image[]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
	#include_function ".\lib\lib_anime_Ikumi.txt"

	let csd = GetCurrentScriptDirectory;

	let cx = GetCenterX;
	let cy = GetCenterY;

	let a = 0;
	let c_ang = 0;
	let c_scale;

	let img = csd ~ "img\dot_ikumi.png";
	let se = csd ~ "se\tm2_bom003.wav";

	@Initialize{
		SetLife(2500);
		SetDamageRate(50, 0);

		LoadSE(se);
		LoadGraphic(img);

		InitializeAction();
		LastSpell;
		TMain;
	}

	@MainLoop{
		if(OnEnemySpell){
			SetCollisionA(GetX, GetY, 25);
			SetCollisionB(GetX, GetY, 20);
		}

		yield;
	}

	@DrawLoop{
		if(OnEnemySpell){
			SetGraphicScale(1.0, 1.0);
			SetGraphicAngle(0,0,0);
			SetRenderState(ALPHA);
			SetAlpha(255);
			_DrawBoss(img, GetX, GetY);
		}
	}

	@Finalize{
	}

	task TMain{
		SetX(cx);
		SetY(150);

		wait(60);
		CutIn(YOUMU, "uu[}[L[v", "", 0, 0, 0, 0);
		SetScore(10000000);
		SetTimer(104);
		SetAction(ACT_SPELL, 150);
		wait(180);
		SetAction(ACT_SHOTB, 150);
		TShot;

		wait(360);
		SetDamageRate(100, 0);
	}

	task TShot{
		loop(100000){
			loop(5){
				Mercury01(rand(32, 416), 32, 6, 90, BLUE01);
				wait(30);
			}
			move;
		}
	}

	task Mercury01(x, y, speed, angle, img){
		CreateLaser01(x, y, speed, angle, 190, 10, img, 30);
		let frame = 0;
		let obj   = CreateLaser01(x, y, speed, angle, 190, 10, img, 30);
		while(!Obj_BeDeleted(obj)){
			if(Obj_GetY(obj)>=456 &&frame==0){
				let angle02 = 180;
				loop(7){
					Mercury02(Obj_GetX(obj), Obj_GetY(obj), speed+0.25, angle02, img);
					angle02+=180/6;
				}
				loop(24){
					CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 1.25, angle, img, 0);
					angle+=360/24;
				}
				frame++;
				PlaySE(se);
			}
			yield;
		}
	}

	task Mercury02(x, y, speed, angle, img){
		CreateLaser01(x, y, speed, angle, 200, 10, img, 0);
		let frame = 0;
		let obj   = CreateLaser01(x, y, speed, angle, 190, 10, img, 0);
		while(!Obj_BeDeleted(obj)){
			yield;
		}
	}

	task move {
		let wMove = 60;

		moveToPlayer(rand(40, 80), rand(-40, 40), wMove,
			GetClipMaxX - 48, GetClipMinY +  80,
			GetClipMinX + 48, GetClipMinY + 240);
		wait(wMove);
		SetAction(ACT_SHOTB, 150);
	}

	function moveToPlayer(xMove, yAdd, frame, left, top, right, bottom) {
		let x;
		let y;

		SetAction(ACT_MOVE, frame);

		if(GetPlayerX < GetX) {
			x = GetX - xMove;

			if(x > left) {
				x = GetX + xMove;
			}
		} else {
			x = GetX + xMove;

			if(right > x) {
				x = GetX - xMove;
			}
		}

		y = GetY + yAdd;
		if(y < top) {
			y = top;
		} else if(bottom < y) {
			y = bottom;
		}

		SetMovePosition02(x, y, frame);
	}

	function wait(w){
		loop(w){
			yield;
		}
	}
}


