script_enemy_main
{
	#include_function ".\func.txt"


	let gcsd = GetCurrentScriptDirectory;
	let boss = gcsd~"b04.png";
	let back = gcsd~"03s.png";
	let name = gcsd~"nm4.png";
	
	let cardget = gcsd~"se001.wav";
	let slash = gcsd~"se003.wav";
	let tan00 = gcsd~"se006.wav";

	let spell = gcsd~"03s.png";
	let backalpha = 0;

	@Initialize
	{
		Init(0, 6, 3, 50, 240, true, true, true, 1000, false, false);
		SetLife(180);

		LoadUserShotData(gcsd~"supershot2.txt");
		SetMovePosition03(GetCenterX, GetCenterY-120, 10, 5);
		CutIn(YOUMU, "Enhancing Song uRed Duetv", "", 0, 0, 0, 0);

		MainTask;

		LoadGraphic(boss);
		LoadGraphic(back);
		LoadGraphic(spell);
		LoadSE(cardget);
		LoadSE(slash);
		LoadSE(tan00);
	}

	@MainLoop
	{
		if(OnEvent==false){SetCollision(GetX, GetY, 24);}

		yield;
	}

	@DrawLoop
	{
		SetColor(255, 255, 255);
		SetTexture(boss);
		SetGraphicRect(0, 0, 64, 64);
		SetGraphicScale(1, 1);
		DrawGraphic(GetX, GetY);

		SetTexture(name);
		SetGraphicRect(0, 0, 150, 30);
		SetGraphicScale(1, 1);
		DrawGraphic(GetClipMinX+75, GetClipMinY+30);
	}

	@BackGround
	{
		if(backalpha<255){backalpha+=5;}

		SetTexture(back);
		SetGraphicRect(0, 0, 640, 640);
		SetGraphicScale(1, 1);
		SetAlpha(255);
		DrawGraphic(GetCenterX, GetCenterY);

		SetTexture(spell);
		SetGraphicRect(0, 0, 640, 640);
		SetGraphicScale(1, 1);
		SetAlpha(backalpha);
		DrawGraphic(GetCenterX, GetCenterY);

		let string = "" ~ ToString(GetGraze);
     		let number = 0;
     		let graze = "";
      		while(number < length(string) && string[number] != '.')
		{
             			graze = graze ~ ToString(string[number]);
             			number++;
      		}
		let str = "Graze: " ~ graze ~ "/750";

		if(GetGraze<750){SetFontColor(0, 0, 255, 0, 0, 255);}
		else{SetFontColor(0, 200, 0, 0, 200, 0);}
		DrawText(str, GetClipMinX+8, GetClipMaxY-32, 12, 255);
		SetFontColor(255, 255, 255, 255, 255, 255);
	}

	@Finalize
	{
		if(GotSpellCardBonus)
		{
			PlaySE(cardget);
		}
		loop(30){CreateItem(ITEM_SCORE, GetX+rand(0, 64)*cos(rand(0, 360)), GetY+rand(0, 64)*sin(rand(0, 360)));}
	}

	task MainTask
	{
		Wait(120);
		let obj = Obj_Create(OBJ_SHOT);
		PlaySE(slash);
		CreateTurret(GetX, GetY, 1.2, 30, 0.01, 250, 10, 2, 7, 16, 90, 41, 10, 60);
		CreateTurret(GetX, GetY, 1.2, 150, 0.01, 250, 10, 2, -7, 16, 90, 41, 10, 60);
		//move;
		attack;
	}

	task attack
	{
		loop
		{
			loop(16)
			{
				CreateShot01(GetX, GetY, 2, GetAngleToPlayer, 11, 10);
				CreateShot01(GetX, GetY, 3, GetAngleToPlayer+30, 11, 10);
				CreateShot01(GetX, GetY, 3, GetAngleToPlayer-30, 11, 10);
				Wait(10);
			}
			Wait(120);
		}
	}

	task move
	{
		loop
		{
			Wait(60);
			SetMovePosition03(rand(GetClipMinX+80, GetClipMaxX-80), rand(GetClipMinY+90, GetClipMinY+150), 10, 2);
			Wait(120);
		}
	}

	task CreateTurret(let x, let y, let v, let a, let desc, let type, let d, let cv, let cav, let cn, let ca, let ctype, let cd, let cinterval)
	{
		let timer = 0;
		let av = 0;
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, v);
		Obj_SetAngle(obj, a);
		ObjShot_SetGraphic(obj, type);
		ObjShot_SetDelay(obj, d);
		ObjShot_SetBombResist(obj, true);
		while(!Obj_BeDeleted(obj))
		{
			while(Obj_GetSpeed(obj)>0){Obj_SetSpeed(obj, Obj_GetSpeed(obj)-desc); yield;}
			if(Obj_GetSpeed(obj)<=0){Obj_SetSpeed(obj, 0);}
			
			if(timer==cinterval)
			{
				PlaySE(tan00);
				ascent(a in 0..cn)
				{
					CreateShot01(Obj_GetX(obj), Obj_GetY(obj), cv, ca+(360/cn)*a+av, ctype, cd);
					timer = 0;
				}
			}			

			av+=cav;
			timer++;
			yield;
		}
	}
}