script_enemy_main
{
	#include_function ".\func.txt"


	let gcsd = GetCurrentScriptDirectory;
	let boss = gcsd~"b03.png";
	let back = gcsd~"02b.png";
	let name = gcsd~"nm3.png";

	let tan00 = gcsd~"se006.wav";
	let tan01 = gcsd~"se004.wav";
	let cardget = gcsd~"se001.wav";
	
	let spell = gcsd~"02s.png";
	let backalpha = 0;

	@Initialize
	{
		Init(0, 6, 3, 45, 240, true, true, true, 500, false, false);
		SetLife(140);

		LoadUserShotData(gcsd~"supershot.txt");
		SetMovePosition03(GetCenterX, GetCenterY-160, 10, 5);
		CutIn(YOUMU, "Sun Chant uSpirit Firev", "", 0, 0, 0, 0);

		MainTask;

		LoadGraphic(boss);
		LoadGraphic(back);
		LoadGraphic(spell);
		LoadGraphic(name);
		LoadSE(tan00);
		LoadSE(tan01);
		LoadSE(cardget);
	}

	@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, 180, 30);
		SetGraphicScale(1, 1);
		DrawGraphic(GetClipMinX+90, GetClipMinY+30);
	}

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

		SetTexture(back);
		SetGraphicRect(0, 0, 640, 640);
		SetGraphicScale(1, 1);
		SetAlpha(255);
		DrawGraphic(GetX, 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 ~ "/320";

		if(GetGraze<320){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(24){CreateItem(ITEM_SCORE, GetX+rand(0, 64)*cos(rand(0, 360)), GetY+rand(0, 64)*sin(rand(0, 360)));}
	}

	task MainTask
	{
		Wait(120);
		attack;
	}

	task attack
	{
		let ang = 0;
		let ang2 = 0;

		loop
		{
			PlaySE(tan01);
			ascent(a in 0..4)
			{
				CreateShotA(0, GetX, GetY, 10);
				SetShotDataA(0, 0, 1, ang+a*90, 0, 0, 0, 25);
				ascent(b in -20..21)
				{
					CreateShotA(1, 0, 0, 0);
					SetShotDataA(1, 0, 1, ang+a*90+b*12, 0, 0, 0, 25);
					AddShot(60, 0, 1, 0);
				}
				SetShotKillTime(0, 61);
				FireShot(0);
			}
	
			move;
			ang+=21;
			Wait(60);
			PlaySE(tan00);
			Wait(60);

			loop(120)
			{
				PlaySE(tan01);
				CreateShot01(GetX, GetY, 0.5*sin(ang2*16)+1.5, ang2-90+rand(-2, 2), 29, 10);
				ang2+=3;
				yield;
			}
		}
	}

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