#e[Stage]
#Title[̎̒]
#Text[ExXe[W]
#BackGround[User(.\img\bg.png,0,-2)]
#BGM[]
#Player[FREE]
#PlayLevel[EXTRA]
#Image[.\img\image.png]
#ScriptVersion[2]

script_stage_main
{
	#include_function ".\init.txt"

	let cd = GetCurrentScriptDirectory();
	let img_title = cd ~ "img\title.png";
	let f_title = 0;
	let f_bonus = 0;
	let title_alpha = 0;
	let stage_start = 0;
	let stage = 7;
	let g_count = 0;

	@Initialize()
	{
		SetCommonData("stage", 1);

		SetRateScoreSystemEnable(false);

		LoadGraphic(img_fairy);
		LoadGraphic(img_title);
		LoadGraphic(img_cbstr);
		LoadGraphic(img_cbnum);

		ExpertEx(false, 0, 3);

		T_Count();
		T_Main();
	}

	@Finalize()
	{
		DeleteGraphic(img_fairy);
		DeleteGraphic(img_title);
		DeleteGraphic(img_cbstr);
		DeleteGraphic(img_cbnum);
	}

	@MainLoop()
	{
		yield;
	}

	@DrawTopObject()
	{
		if( f_title ){
			SetTexture(img_title);
			SetGraphicAngle(0, 0, 0);
			SetGraphicRect(0, 0, 136, 312);
			SetAlpha(title_alpha * 255 / 60);
			DrawGraphic(GetCenterX(), GetCenterY());
			SetAlpha(255);
		}
		if( f_bonus ){
			let base_y = 120;
			let gp = [0, 1, 2, 3, 4, 7];

			if( GetCommonDataDefault("crazy01", 0) ){
				gp[3] = 5;
			}
			if( GetCommonDataDefault("crazy02", 0) ){
				gp[4] = 6;
			}
			SetTexture(img_cbstr);
			ascent( let i in 0..6 ){
				SetGraphicRect(0, gp[i] * 26, 336, (gp[i] + 1) * 26);
				DrawGraphic(GetCenterX(), GetClipMinY() + base_y + i * 36);
			}
			DrawNumber(GetPlayerLife(), GetCenterX() + 48, GetClipMinY() + base_y, 0);
			DrawNumber(GetPlayerBomb(), GetCenterX() + 48, GetClipMinY() + base_y + 36, 0);
			DrawNumber(GetPoint(), GetCenterX() + 48, GetClipMinY() + base_y + 72, 0);
			DrawNumber(GetCommonDataDefault("clearbonus", 0), GetCenterX() + 168, GetClipMinY() + base_y + 180, 2);
		}
	}

	@BackGround()
	{
		BackGround7();
	}

	function DrawNumber(num, x, y, addzero)
	{
		let chk = num;
		let fig = 0;
		let part;

		SetTexture(img_cbnum);

		loop(addzero){
			part = 0;
			SetGraphicRect(part * 12, 0, (part + 1) * 12, 26);
			DrawGraphic(x - 6 - fig * 12, y);
			fig ++;
		}

		while( (chk > 0 || fig == addzero) && fig - addzero < 30 )
		{
			chk = trunc(chk / 10);
			part = num - chk * 10;
			num = chk;
			SetGraphicRect(part * 12, 0, (part + 1) * 12, 26);
			DrawGraphic(x - 6 - fig * 12, y);
			fig ++;
		}
	}

	task T_ShowTitle()
	{
		f_title = 1;
		loop(60){
			title_alpha ++;
			yield;
		}
		Wait(120);
		loop(60){
			title_alpha --;
			yield;
		}
		f_title = 0;
	}

	task T_Count()
	{
		loop{
			g_count ++;
			yield;
		}
	}

	task T_Main()
	{
		T_Stage7();
	}

	#include_function ".\_stage7.txt"
	#include_function ".\f_base.txt"
}
