#TouhouDanmakufu[Plural]
#ScriptVersion[3]
#System["./System/Default_System.txt"]
#Title["Aloutte Noire"]
#Text["Made by Vigor (NecroHeart)"]
#Player["./player/Tsubakura.dnh"]
#Background["./graphic/BG.dnh"]
#include"./function.txt"

let song = ObjSound_Create;
let vol=0;

let midboss=true;
SetCommonData("sevol",80);

let menu=true;
let infinite=false;

let dif=0;

InstallFont(dir ~ "graphic/Raleway-Regular.tff");
InstallFont(dir ~ "graphic/Raleway-SemiBold.tff");

@Initialize
{
	SetPlayerClip(10,10,630,710);
	ObjRender_SetPosition(GetPlayerObjectID,GetStgFrameWidth/2,GetStgFrameHeight/2+420,0);
	TPlural;
}

@Event
{
	alternative(GetEventType())
	case(EV_PAUSE_ENTER)
	{
		ObjSound_Stop(song);
	}
	case(EV_PAUSE_LEAVE)
	{
		ObjSound_Play(song);
	}
}

@MainLoop
{
	ObjSound_SetRestartEnable(song,true);
	ObjSound_SetLoopEnable(song,true);
	ObjSound_SetVolumeRate(song,vol);
	yield;
}
@Finalize{}
task TPlural
{
	TShade;
	PlayerHUD;
	BossHUD;
	Disable;
	loop(60)
	{
		SetPlayerClip(10,10,630,710);
		ObjRender_SetPosition(GetPlayerObjectID,GetStgFrameWidth/2,GetStgFrameHeight/2+420,0);
		SetVirtualKeyState(VK_USER1,KEY_FREE);
		yield;
	}
	TMenu;
	while(menu==true)
	{
		SetPlayerClip(10,10,630,840);
		if(infinite==true){SetPlayerLife(999);}
		if(infinite==false){SetPlayerLife(3);}
		SetPlayerClip(10,10,630,710);
		ObjRender_SetPosition(GetPlayerObjectID,GetStgFrameWidth/2,GetStgFrameHeight/2+420,0);
		yield;
	}
	Song;
	loop(120)
	{
		SetPlayerClip(10,10,630,710);
		ObjRender_SetPosition(GetPlayerObjectID,GetStgFrameWidth/2,GetStgFrameHeight/2+420,0);
		yield;
	}
	let hh=420;
	loop(120)
	{
		hh-=240/120;
		SetPlayerClip(10,10,630,290+hh);
		ObjRender_SetPosition(GetPlayerObjectID,GetStgFrameWidth/2,GetStgFrameHeight/2+hh,0);
		yield;
	}
	ObjRender_SetPosition(GetPlayerObjectID,GetStgFrameWidth/2,GetStgFrameHeight/2+180,0);
	SetPlayerClip(10,10,630,470);
	Boss;
}
function Boss
{
	let dir=GetCurrentScriptDirectory();
	let obj=ObjEnemyBossScene_Create();
	ObjEnemyBossScene_Add(obj,0,dir~"PreBattle.txt");
	ObjEnemyBossScene_Add(obj,1,dir~"Attack1.txt");
	ObjEnemyBossScene_Add(obj,2,dir~"Attack2.txt");
	ObjEnemyBossScene_Add(obj,3,dir~"Attack3.txt");
	ObjEnemyBossScene_Add(obj,4,dir~"Attack4.txt");
	ObjEnemyBossScene_Add(obj,5,dir~"Attack5.txt");
	ObjEnemyBossScene_Add(obj,6,dir~"Attack6.txt");
	ObjEnemyBossScene_Regist(obj);
	while(!Obj_IsDeleted(obj)){yield;}
	loop(360){yield;}
	if(GetCommonData("creditroll",false)==true)
	{
		Credits;
		loop(360){yield;}
		ObjRender_SetPosition(GetPlayerObjectID,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
	}
}
task Disable
{
	let spd = GetPlayerSpeed;
	SetPlayerSpeed(0,0);
	SetForbidPlayerShot(true);
	SetForbidPlayerSpell(true);
	loop
	{
		if(menu==true)
		{
			SetForbidPlayerShot(true);
			SetForbidPlayerSpell(true);
			SetPlayerSpeed(0,0);
		}
		if(menu==false)
		{
			loop(360){yield;}
			SetForbidPlayerShot(false);
			SetForbidPlayerSpell(false);
			SetPlayerSpeed(spd[0],spd[1]);
		}
		yield;
	}
}
task Song
{
	while(vol>0){yield;}
	ObjSound_Stop(song);
	ObjSound_Load(song,dir ~ "./audio/Dirt.ogg");
	ObjSound_Play(song);
	while(GetCommonData("creditroll",false)==false)
	{
		if(vol<256){vol+=100/360;}
		ObjSound_SetVolumeRate(song,vol);
		yield;
	}
	loop(720)
	{
		if(vol>0){vol-=100/360;}
		ObjSound_SetVolumeRate(song,vol);
		yield;
	}
	vol=0;
	ObjSound_Stop(song);
	if(GetCommonData("creditroll",false)==true)
	{
		loop(30){yield;}
		ObjSound_Load(song,dir ~ "./audio/Chain.ogg");
		ObjSound_Play(song);
		loop(61*60)
		{
			if(vol<256){vol+=100/180;}
			ObjSound_SetVolumeRate(song,vol);
			yield;
		}
	}
	while(vol>0)
	{
		vol-=100/360;
		ObjSound_SetVolumeRate(song,vol);
		yield;
	}
	CloseStgScene();
}
task TShade
{
	let obj= ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,dir ~ "graphic/Shade.png");
	ObjSprite2D_SetSourceRect(obj,0,0,640,480);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
	let alpha=1;
	while(menu==true)
	{
		ObjRender_SetAlpha(obj,256*alpha);
		yield;
	}
	loop(360)
	{
		if(alpha>0){alpha-=1/360;}
		ObjRender_SetAlpha(obj,256*alpha);
		yield;
	}
	loop
	{
		if(alpha<0.2){alpha+=1/120;}
		ObjRender_SetAlpha(obj,256*alpha);
		yield;
	}
	Obj_Delete(obj);
}
task TMenu
{
	let texts = ["Easy Extra","Extra","Absurdly Extra"];
	let mx = GetStgFrameWidth/2;
	let my = GetStgFrameHeight/2;
	let obj = [];
	let ca=0;
	let w=0;
	let delay=10;
	let i = 0;
	loop(length(texts)+1)
	{
		obj= obj ~ [ObjPrim_Create(OBJ_SPRITE_2D)];
		Obj_SetRenderPriority(obj[i],1);
		ObjPrim_SetTexture(obj[i],dir ~ "graphic/difficulty.png");
		ObjSprite2D_SetSourceRect(obj[i],0,0,256,128);
		ObjSprite2D_SetDestCenter(obj[i]);
		ObjRender_SetPosition(obj[i],mx,my,0);
		ObjRender_SetScaleXYZ(obj[i],256/256,256/256,1);
		fade(obj[i],i);
		
		task fade(obj,i)
		{
			let al=0;
			loop
			{
				if(!Obj_IsDeleted(obj)){infinite=false;}
				if(i==0){ObjSprite2D_SetSourceRect(obj,0,0,256,128);}
				if(i==1){ObjSprite2D_SetSourceRect(obj,0,128,256,256);}
				if(i==2){ObjSprite2D_SetSourceRect(obj,0,256,256,384);}
				if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD)
				{
					if(!Obj_IsDeleted(obj)){infinite=true;}
					if(i==0){ObjSprite2D_SetSourceRect(obj,256,0,512,128);}
					if(i==1){ObjSprite2D_SetSourceRect(obj,256,128,512,256)}
					if(i==2){ObjSprite2D_SetSourceRect(obj,256,256,512,384);}
				}
				if(ca==i){if(al<255){al+=255/delay;}}
				if(ca!=i){if(al>0){al-=255/delay;}}
				ObjRender_SetAlpha(obj,al);
				yield;
				if(menu==false){Obj_Delete(obj);}
			}
		}
		i++;
	}
	ObjRender_SetBlendType(obj[length(texts)],BLEND_ADD_ARGB);
	loop(30){yield;}
	while(menu==true)
	{
		w++;
		yield;
		if(w<=delay)
		{
			SetVirtualKeyState(VK_SLOWMOVE,KEY_FREE);
			SetVirtualKeyState(VK_LEFT,KEY_FREE);
			SetVirtualKeyState(VK_RIGHT,KEY_FREE);
			SetVirtualKeyState(VK_OK,KEY_FREE);
		}
		if(GetVirtualKeyState(VK_SLOWMOVE) == KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE) == KEY_PULL)
		{
			SEPlay(dir ~ "audio/cursor_04.wav",100);
			w=0;
		}
		if(GetVirtualKeyState(VK_LEFT) == KEY_PUSH)
		{
			SEPlay(dir ~ "audio/cursor_00.wav",100);
			ca-=1;
			w=0;
		}
		else if(GetVirtualKeyState(VK_RIGHT) == KEY_PUSH)
		{
			SEPlay(dir ~ "audio/cursor_00.wav",100);
			ca+=1;
			w=0;
		}
		if(ca<0){ca=2;}
		if(ca>2){ca=0;}
		dif=ca+1;
		ObjRender_SetPosition(obj[length(texts)], mx,my,0);
		if(GetVirtualKeyState(VK_OK) == KEY_PUSH)
		{
			alternative(ca)
			case(0)
			{
				SEPlay(dir ~ "audio/cursor_01.wav",100);
				SetCommonData("diff",1);
				menu=false;
			}
			case(1)
			{
				SEPlay(dir ~ "audio/cursor_01.wav",100);
				SetCommonData("diff",2);
				menu=false;
			}
			case(2)
			{
				if(infinite==true){SEPlay(dir ~ "audio/cursor_03.wav",100);}
				if(infinite==false)
				{
					SetCommonData("diff",3);
					menu=false;
				}
			}
		}
	}
}
function DigitToArray(let digit,let count)
{
	let res = [];
	digit = truncate(digit);
	loop
	{
		let tnum = truncate(digit % 10);
		digit /= 10;
		res = [tnum] ~ res;
		if(truncate(digit) == 0){break;}
	}
	loop(max(0, count - length(res))){res = [0] ~ res;}
	return res;
}
///////////////
/// Credits ///
///////////////
task Credits
{
	FullDisable;
	task FullDisable
	{
		while(GetCommonData("creditroll",false)==true)
		{
			SetForbidPlayerShot(true);
			SetForbidPlayerSpell(true);
			SetVirtualKeyState(VK_USER1,KEY_PULL);
			SetVirtualKeyState(VK_USER1,KEY_FREE);
			SetSkipModeKey(KEY_INVALID);
			SetVirtualKeyState(VK_LEFT,KEY_PULL);
			SetVirtualKeyState(VK_LEFT,KEY_FREE);
			SetVirtualKeyState(VK_RIGHT,KEY_PULL);
			SetVirtualKeyState(VK_RIGHT,KEY_FREE);
			SetVirtualKeyState(VK_UP,KEY_PULL);
			SetVirtualKeyState(VK_UP,KEY_FREE);
			SetVirtualKeyState(VK_DOWN,KEY_PULL);
			SetVirtualKeyState(VK_DOWN,KEY_FREE);
			yield;
		}
	}
	task Breaker
	{
		while(GetVirtualKeyState(VK_SLOWMOVE)!=KEY_HOLD){yield;}
		SetCommonData("creditroll",false);
		CloseStgScene();
	}
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let objx=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,dir ~ "graphic/SpellCard.png");
	ObjPrim_SetTexture(objx,dir ~ "graphic/SpellCard.png");
	ObjSprite2D_SetSourceRect(obj,0,0,128,128);
	ObjSprite2D_SetDestCenter(obj);
	ObjSprite2D_SetSourceRect(objx,0,0,128,128);
	ObjSprite2D_SetDestCenter(objx);
	ObjRender_SetColor(obj,0,0,0);
	ObjRender_SetColor(objx,0,0,0);
	ObjRender_SetScaleXYZ(obj,800/128,490/128,1);
	ObjRender_SetScaleXYZ(objx,800/128,490/128,1);
	let xo=GetStgFrameWidth/2;
	let yo=GetStgFrameHeight/2;
	let al=0;
	loop(360)
	{
		al+=256/360;
		ObjRender_SetAlpha(obj,al);
		ObjRender_SetAlpha(objx,al);
		ObjRender_SetPosition(obj,xo,yo,0);
		ObjRender_SetPosition(objx,xo,yo,0);
		yield;
	}
	Breaker;
	loop(60){yield;}
	ImageShow(dir ~ "graphic/Credits.png",xo,yo-15,0,0,256,64,obj,245,360/512);
	loop(60){yield;}
	ImageShow(dir ~ "graphic/Credits.png",xo,yo+15,0,64,256,128,obj,185,240/512);
	loop(120){yield;}
	let xc=-1;
	let time=60;
	loop(60)
	{
		xc+=2/60;
		Charge(xo-128*360/512*xc,yo-15,rand(time,time*2),time,255,255,255,30,BLEND_ADD_ARGB,-1,rand(-1,1),rand(0,360),rand(60,120));
		Charge(xo-128*240/512*xc,yo+15,rand(time,time*2),time,255,255,255,30,BLEND_ADD_ARGB,-1,rand(-1,1),rand(0,360),rand(60,120));
		time--;
		yield;
	}
	loop(60)
	{
		xc-=2/60;
		time=rand(60,120);
		Charge(xo-128*360/512*xc,yo-15,rand(time,time*4),time,255,255,255,30,BLEND_ADD_ARGB,1,rand(-1,1),rand(0,360),rand(60,120));
		Charge(xo-128*300/512*xc,yo+15,rand(time,time*4),time,255,255,255,30,BLEND_ADD_ARGB,1,rand(-1,1),rand(0,360),rand(60,120));
	}
	ImageShow(dir ~ "graphic/Credits.png",xo,yo-15,256,0,512,64,obj,240,360/512);
	ImageShow(dir ~ "graphic/Credits.png",xo,yo+15,256,64,512,128,obj,240,300/512);
	loop(60){yield;}
	mainloop;
	loop(180){yield;}
	time=60;
	xc=1;
	loop(60)
	{
		xc-=2/60;
		Charge(xo-90-192*360/512*xc,yo-150,rand(time,time*4),time,255,255,255,30,BLEND_ADD_ARGB,-1,rand(-1,1),rand(0,360),rand(60,120));
		Charge(xo+90+64*360/512*xc,yo+150,rand(time,time*4),time,255,255,255,30,BLEND_ADD_ARGB,-1,rand(-1,1),rand(0,360),rand(60,120));
		time--;
		yield;
	}
	ImageShow(dir ~ "graphic/Credits.png",xo-90,yo-150,0,128,384,192,obj,360,360/512);
	ImageShow(dir ~ "graphic/Credits.png",xo+90,yo+150,384,128,512,192,obj,360,300/512);
	let y1=yo;
	let y2=yo;
	loop(60)
	{
		ObjRender_SetPosition(obj,xo,y1,0);
		ObjRender_SetPosition(objx,xo,y2,0);
		y1-=360/60;
		y2+=360/60;
		yield;
	}
	loop(2)
	{
		loop(60)
		{
			SetVirtualKeyState(VK_SLOWMOVE,KEY_HOLD);
			yield;
		}
		loop(60){yield;}
	}
	loop(60)
	{
		ObjRender_SetPosition(obj,xo,y1,0);
		ObjRender_SetPosition(objx,xo,y2,0);
		y1+=360/60;
		y2-=360/60;
		yield;
	}
	ObjRender_SetPosition(obj,xo,yo,0);
	ObjRender_SetPosition(objx,xo,yo,0);
	time=60;
	xc=1;
	loop(60)
	{
		xc-=2/60;
		Charge(xo+192*240/512*xc,yo-15,rand(time,time*4),time,255,255,255,30,BLEND_ADD_ARGB,-1,rand(-1,1),rand(0,360),rand(60,120));
		Charge(xo-64*150/512*xc,yo+15,rand(time,time*4),time,255,255,255,30,BLEND_ADD_ARGB,-1,rand(-1,1),rand(0,360),rand(60,120));
		time--;
		yield;
	}
	ImageShow(dir ~ "graphic/Credits.png",xo,yo-15,0,192,384,256,obj,360,240/512);
	ImageShow(dir ~ "graphic/Credits.png",xo,yo+15,384,192,512,256,obj,360,150/512);
	let anglez=0;
	let scaley=490;
	loop(60)
	{
		ObjRender_SetAngleZ(obj,anglez);
		ObjRender_SetAngleZ(objx,anglez);
		ObjRender_SetScaleY(obj,scaley/128);
		ObjRender_SetScaleY(objx,scaley/128);
		anglez+=30/60;
		scaley-=90/60;
		yield;
	}
	loop(240){yield;}
	loop(60)
	{
		ObjRender_SetAngleZ(obj,anglez);
		ObjRender_SetAngleZ(objx,anglez);
		ObjRender_SetScaleY(obj,scaley/128);
		ObjRender_SetScaleY(objx,scaley/128);
		anglez-=30/60;
		scaley+=90/60;
		yield;
	}
	ObjRender_SetAngleZ(obj,0);
	ObjRender_SetAngleZ(objx,0);
	ObjRender_SetScaleY(obj,490/128);
	ObjRender_SetScaleY(objx,490/128);
	time=60;
	xc=1;
	loop(60)
	{
		xc-=2/60;
		Charge(xo-192*360/512*xc,yo-210,rand(time,time*4),time,255,255,255,30,BLEND_ADD_ARGB,-1,rand(-1,1),rand(0,360),rand(60,120));
		Charge(xo+64*240/512*xc,yo+210,rand(time,time*4),time,255,255,255,30,BLEND_ADD_ARGB,-1,rand(-1,1),rand(0,360),rand(60,120));
		time--;
		yield;
	}
	ImageShow(dir ~ "graphic/Credits.png",xo,yo-180,0,256,384,320,obj,480,360/512);
	ImageShow(dir ~ "graphic/Credits.png",xo,yo+180,384,256,512,320,obj,480,240/512);
	let ang=rand(0,360);
	loop(7)
	{
		lasermation(xo,yo,240,ang,1,1.5);
		lasermation(xo,yo,240,ang+180/7,-1,1);
		lasermation(xo,yo,240,ang,1,0.5);
		ang+=360/7;
	}
	time=360;
	loop(360)
	{
		Charge(xo,yo,rand(time,time*4),time,255,255,255,30,BLEND_ADD_ARGB,-1,rand(-1,1),rand(0,360),rand(60,120));
		time--;
		yield;
	}
	loop(360)
	{
		time=rand(60,240);
		Charge(xo,yo,rand(time,time*4),time,255,255,255,30,BLEND_ADD_ARGB,1,rand(-1,1),rand(0,360),rand(60,120));
	}
	Ring(xo,yo,240,255,255,255,BLEND_ADD_ARGB,1800,256,1);
	loop(120){yield;}
	task lasermation(xx,yy,d,angle,av,scale)
	{
		let obj1= ObjPrim_Create(OBJ_SPRITE_2D);
		let obj2= ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj1,dir ~ "graphic/laser.png");
		ObjPrim_SetTexture(obj2,dir ~ "graphic/laser.png");
		ObjSprite2D_SetSourceRect(obj1,0,256,512,512);
		ObjSprite2D_SetSourceRect(obj2,0,0,512,256);
		ObjSprite2D_SetDestRect(obj1,-64,-128,448,128);
		ObjSprite2D_SetDestRect(obj2,-64,-128,448,128);
		ObjRender_SetBlendType(obj1,BLEND_ADD_ARGB);
		ObjRender_SetBlendType(obj2,BLEND_ADD_ARGB);
		let alpha=1;
		let calpha=1;
		let xyz=2;
		let cxyz=1;
		let ca=1;
		while(alpha>0)
		{
			if(alpha>=256){calpha*=-1;}
			if(xyz<=1){cxyz*=-1;}
			alpha+=256/d*calpha;
			xyz-=1/d*cxyz;
			ObjRender_SetAlpha(obj1,alpha/2);
			ObjRender_SetAlpha(obj2,alpha/2);
			ObjRender_SetScaleXYZ(obj1,256/512*xyz*scale,128/256*xyz*scale,1);
			ObjRender_SetScaleXYZ(obj2,256/512*xyz*scale,128/256*xyz*scale,1);
			ObjRender_SetAngleZ(obj1,angle);
			ObjRender_SetAngleZ(obj2,angle);
			ObjRender_SetPosition(obj1,xx,yy,0);
			ObjRender_SetPosition(obj2,xx,yy,0);
			angle+=av*ca;
			ca-=1/d*2;
			yield;
		}
		Obj_Delete(obj1);
		Obj_Delete(obj2);
	}
	ImageShow(dir ~ "graphic/Credits.png",xo,yo-195,0,320,384,384,obj,1800,240/512);
	ImageShow(dir ~ "graphic/Credits.png",xo,yo-165,384,320,512,384,obj,1800,180/512);
	loop(120){yield;}
	ImageShowSpin(dir ~ "graphic/LenEns.png",xo-120,yo-95,yo+75,0,0,640,480,540,220/640,400/640,-90,-1,255);
	loop(360){yield;}
	ImageShowSpin(dir ~ "graphic/LenEns.png",xo+120,yo-95,yo+75,640,0,1280,480,540,220/640,400/640,-90,-1,255);
	loop(360){yield;}
	ImageShowSpin(dir ~ "graphic/LenEns.png",xo-120,yo-95,yo+75,0,480,640,960,540,220/640,400/640,-90,-1,255);
	loop(360){yield;}
	ImageShowSpin(dir ~ "graphic/LenEns.png",xo+120,yo-95,yo+75,640,480,1280,960,540,220/640,400/640,-90,-1,255);
	loop(600){yield;}
	time=120;
	xc=1;
	loop(120)
	{
		xc-=2/120;
		Charge(xo+256*360/512*xc,yo-30,rand(time,time*4),time,255,255,255,30,BLEND_ADD_ARGB,-1,rand(-1,1),rand(0,360),rand(60,120));
		time--;
		yield;
	}
	ImageShow(dir ~ "graphic/Credits.png",xo,yo-30,0,384,512,448,obj,660,360/512);
	loop(120){yield;}
	time=120;
	xc=1;
	loop(120)
	{
		xc-=2/120;
		Charge(xo-256*360/512*xc,yo+30,rand(time,time*4),time,255,255,255,30,BLEND_ADD_ARGB,-1,rand(-1,1),rand(0,360),rand(60,120));
		time--;
		yield;
	}
	ImageShow(dir ~ "graphic/Credits.png",xo,yo+30,0,448,512,512,obj,480,360/512);
	loop(240){yield;}
	SetCommonData("creditroll",false);
	task mainloop
	{
		loop
		{
			yield;
			let timeX=rand(30,60);
			Charge(rand(0,640),rand(0,480),rand(timeX,timeX*4),timeX,255,255,255,30,BLEND_ADD_ARGB,1,rand(-3,3),rand(0,360),rand(30,120));
		}
	}
}
///////////
/// HUD ///
///////////
task PlayerHUD
{
	while(menu==true){yield;}
	let xx=GetStgFrameWidth/2-280;
	let yy=GetStgFrameHeight/2+200;
	let scalepic=80;
	let alphascale=0;
	let fontsize=14;
	difficulty;
	symbol;
	fps;
	time;
	if(infinite==false){life;}
	if(infinite==true){death;}
	bomb;
	task difficulty
	{
		let xxt=xx+40+(scalepic/2);
		let yyt=yy-12-(scalepic/8);
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,dir~"graphic/difficulty.png");
		ObjSprite2D_SetSourceRect(obj,0,0,256,128);
		if(dif==1 && infinite==false){ObjSprite2D_SetSourceRect(obj,0,0,256,128);}
		if(dif==1 && infinite==true){ObjSprite2D_SetSourceRect(obj,256,0,512,128);}
		if(dif==1 && infinite==false){ObjSprite2D_SetSourceRect(obj,0,0,256,128);}
		if(dif==2 && infinite==true){ObjSprite2D_SetSourceRect(obj,256,128,512,256);}
		if(dif==2 && infinite==false){ObjSprite2D_SetSourceRect(obj,0,128,256,256);}
		if(dif==3 && infinite==true){ObjSprite2D_SetSourceRect(obj,256,256,512,384);}
		if(dif==3 && infinite==false){ObjSprite2D_SetSourceRect(obj,0,256,256,384);}
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetPosition(obj,xxt,yyt,0);
		ObjRender_SetScaleXYZ(obj,(scalepic-8)/128,(scalepic-8)/128,1);
		loop
		{
			ObjRender_SetAlpha(obj,256*alphascale);
			yield;
		}
	}
	task symbol
	{
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,dir~"graphic/Symbol.png");
		ObjSprite2D_SetSourceRect(obj,0,0,512,256);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetPosition(obj,xx,yy,0);
		ObjRender_SetScaleXYZ(obj,scalepic/256,scalepic/256,1);
		loop
		{
			ObjRender_SetAlpha(obj,256*alphascale);
			yield;
		}
	}
	task life
	{
		let xxt=xx+9+(scalepic/2);
		let yyt=yy+4;
		let objt = ObjText_Create();
		ObjText_SetText(objt,"Life");
		ObjText_SetFontType(objt,"Raleway-SemiBold");
		ObjText_SetFontSize(objt,fontsize);
		ObjText_SetFontColorTop(objt,255,255,255);
		ObjText_SetFontColorBottom(objt,255,255,255);
		ObjText_SetFontBold(objt,true);
		ObjText_SetFontBorderWidth(objt,1);
		ObjText_SetFontBorderType(objt,BORDER_SHADOW);
		ObjText_SetFontBorderColor(objt,0,0,0);
		ObjRender_SetPosition(objt,xxt,yyt,0);
		lifegauge;
		task lifegauge
		{
			let lifelimit=3;
			let dimlife=32;
			let scalext=0.3;
			let scaleyt=0.3;
			let xxl=xxt+9-(dimlife*lifelimit/2*(1-scalext))+28;
			let yyl=yyt+dimlife/4;
			let objt1=ObjPrim_Create(OBJ_SPRITE_2D);
			let objt2=ObjPrim_Create(OBJ_SPRITE_2D);
			ObjPrim_SetTexture(objt1,dir~"graphic/Gauge.png");
			ObjPrim_SetTexture(objt2,dir~"graphic/Gauge.png");
			ObjRender_SetScaleXYZ(objt1,scalext,scaleyt,0);
			ObjRender_SetScaleXYZ(objt2,scalext,scaleyt,0);
			ObjRender_SetColor(objt1,255,255,255);
			ObjRender_SetColor(objt2,240,60,60);
			loop
			{
				ObjRender_SetAlpha(objt1,256*alphascale);
				ObjRender_SetAlpha(objt2,256*alphascale);
				let lifeget=GetPlayerLife;
				if(lifeget>lifelimit){lifeget=lifelimit;}
				if(GetPlayerLife<=0){SetPlayerLife(0);}
				ObjSprite2D_SetSourceRect(objt1,0,dimlife,dimlife*lifelimit,dimlife*2);
				ObjSprite2D_SetSourceRect(objt2,0,0,dimlife*lifeget,dimlife);
				ObjSprite2D_SetDestRect(objt1,-dimlife/2*lifelimit,-dimlife/2,dimlife/2*lifelimit,dimlife/2);
				ObjSprite2D_SetDestRect(objt2,0,-dimlife/2,dimlife*lifeget,dimlife/2);
				ObjRender_SetPosition(objt1,xxl+(dimlife*lifelimit/2),yyl,0);
				ObjRender_SetPosition(objt2,xxl+(dimlife*lifelimit/2*(1-scalext)),yyl,0);
				ObjRender_SetAlpha(objt,256*alphascale);
				yield;
			}
		}
	}
	task death
	{
		let xxt=xx+9+(scalepic/2);
		let yyt=yy+4;
		let objt = ObjText_Create();
		ObjText_SetText(objt,"Death");
		ObjText_SetFontType(objt,"Raleway-SemiBold");
		ObjText_SetFontSize(objt,fontsize);
		ObjText_SetFontColorTop(objt,255,255,255);
		ObjText_SetFontColorBottom(objt,255,255,255);
		ObjText_SetFontBold(objt,true);
		ObjText_SetFontBorderWidth(objt,1);
		ObjText_SetFontBorderType(objt,BORDER_SHADOW);
		ObjText_SetFontBorderColor(objt,0,0,0);
		ObjRender_SetPosition(objt,xxt,yyt,0);
		deathdraw;
		task deathdraw
		{
			let objd = ObjText_Create();
			ObjText_SetFontType(objd,"Raleway-Regular");
			ObjText_SetFontSize(objd,fontsize);
			ObjText_SetFontColorTop(objd,255,255,255);
			ObjText_SetFontColorBottom(objd,255,255,255);
			ObjText_SetFontBold(objd,true);
			ObjText_SetFontBorderWidth(objd,1);
			ObjText_SetFontBorderType(objd,BORDER_SHADOW);
			ObjText_SetFontBorderColor(objd,0,0,0);
			ObjRender_SetY(objd,yyt);
			let deathcount=0;
			loop
			{
				let getlife1=GetPlayerLife;
				yield;
				let getlife2=GetPlayerLife;
				if(getlife2<getlife1){deathcount++;}
				let deathfont=IntToString(deathcount);
				ObjText_SetText(objd,deathfont);
				ObjRender_SetX(objd,xxt+43+(ObjText_GetTotalWidth(objd)/2));
				ObjRender_SetAlpha(objt,256*alphascale);
				ObjRender_SetAlpha(objd,256*alphascale);
			}
		}
	}
	task bomb
	{
		let xxt=xx+9+(scalepic/2);
		let yyt=yy+4+(scalepic/8);
		let objt = ObjText_Create();
		ObjText_SetText(objt,"Bomb");
		ObjText_SetFontType(objt,"Raleway-SemiBold");
		ObjText_SetFontSize(objt,fontsize);
		ObjText_SetFontColorTop(objt,255,255,255);
		ObjText_SetFontColorBottom(objt,255,255,255);
		ObjText_SetFontBold(objt,true);
		ObjText_SetFontBorderWidth(objt,1);
		ObjText_SetFontBorderType(objt,BORDER_SHADOW);
		ObjText_SetFontBorderColor(objt,0,0,0);
		ObjRender_SetPosition(objt,xxt,yyt,0);
		bombgauge;
		task bombgauge
		{
			let bomblimit=3;
			let dimbomb=32;
			let scalext=0.3;
			let scaleyt=0.3;
			let xxl=xxt+9-(dimbomb*bomblimit/2*(1-scalext))+28;
			let yyl=yyt+dimbomb/4;
			let objt1=ObjPrim_Create(OBJ_SPRITE_2D);
			let objt2=ObjPrim_Create(OBJ_SPRITE_2D);
			ObjPrim_SetTexture(objt1,dir~"graphic/Gauge.png");
			ObjPrim_SetTexture(objt2,dir~"graphic/Gauge.png");
			ObjRender_SetScaleXYZ(objt1,scalext,scaleyt,0);
			ObjRender_SetScaleXYZ(objt2,scalext,scaleyt,0);
			ObjRender_SetColor(objt1,255,255,255);
			ObjRender_SetColor(objt2,60,240,60);
			loop
			{
				ObjRender_SetAlpha(objt1,256*alphascale);
				ObjRender_SetAlpha(objt2,256*alphascale);
				let bombget=GetPlayerSpell;
				if(bombget>bomblimit){bombget=bomblimit;}
				if(GetPlayerSpell<=0){SetPlayerSpell(0);}
				ObjSprite2D_SetSourceRect(objt1,0,dimbomb,dimbomb*bomblimit,dimbomb*2);
				ObjSprite2D_SetSourceRect(objt2,0,0,dimbomb*bombget,dimbomb);
				ObjSprite2D_SetDestRect(objt1,-dimbomb/2*bomblimit,-dimbomb/2,dimbomb/2*bomblimit,dimbomb/2);
				ObjSprite2D_SetDestRect(objt2,0,-dimbomb/2,dimbomb*bombget,dimbomb/2);
				ObjRender_SetPosition(objt1,xxl+(dimbomb*bomblimit/2),yyl,0);
				ObjRender_SetPosition(objt2,xxl+(dimbomb*bomblimit/2*(1-scalext)),yyl,0);
				ObjRender_SetAlpha(objt,256*alphascale);
				yield;
			}
		}
	}
	task time
	{
		let xxt=xx+8+(scalepic/2);
		let yyt=yy+4-(scalepic/8);
		let objt = ObjText_Create();
		ObjText_SetText(objt,"Time");
		ObjText_SetFontType(objt,"Raleway-SemiBold");
		ObjText_SetFontSize(objt,fontsize);
		ObjText_SetFontColorTop(objt,255,255,255);
		ObjText_SetFontColorBottom(objt,255,255,255);
		ObjText_SetFontBold(objt,true);
		ObjText_SetFontBorderWidth(objt,1);
		ObjText_SetFontBorderType(objt,BORDER_SHADOW);
		ObjText_SetFontBorderColor(objt,0,0,0);
		ObjRender_SetPosition(objt,xxt,yyt,0);
		seconddraw;
		task seconddraw
		{
			let objs = ObjText_Create();
			ObjText_SetFontType(objs,"Raleway-Regular");
			ObjText_SetFontSize(objs,fontsize);
			ObjText_SetFontColorTop(objs,255,255,255);
			ObjText_SetFontColorBottom(objs,255,255,255);
			ObjText_SetFontBold(objs,true);
			ObjText_SetFontBorderWidth(objs,1);
			ObjText_SetFontBorderType(objs,BORDER_SHADOW);
			ObjText_SetFontBorderColor(objs,0,0,0);
			ObjRender_SetY(objs,yyt);
			loop
			{
				let time=ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID,INFO_TIMERF)/60;
				if(time>0 && time<=10 && time%1==0){SEPlay(dir ~ "audio/endtime.wav",100);}
				if(time<0){ObjText_SetText(objs,"");}
				if(time>=0){ObjText_SetText(objs,rtos("00.00",time));}
				ObjRender_SetX(objs,xxt+20+(ObjText_GetTotalWidth(objt)/2));
				ObjRender_SetAlpha(objt,256*alphascale);
				ObjRender_SetAlpha(objs,256*alphascale);
				yield;
			}
		}
	}
	task fps
	{
		let xxt=xx-1+(scalepic/2);
		let yyt=yy+4+(scalepic/8*2);
		let objt = ObjText_Create();
		ObjText_SetText(objt,"fps");
		ObjText_SetFontType(objt,"Raleway-SemiBold");
		ObjText_SetFontSize(objt,fontsize);
		ObjText_SetFontColorTop(objt,255,255,255);
		ObjText_SetFontColorBottom(objt,255,255,255);
		ObjText_SetFontBold(objt,true);
		ObjText_SetFontBorderWidth(objt,1);
		ObjText_SetFontBorderType(objt,BORDER_SHADOW);
		ObjText_SetFontBorderColor(objt,0,0,0);
		ObjRender_SetPosition(objt,xxt+56,yyt,0);
		fpsdraw;
		task fpsdraw
		{
			let objs = ObjText_Create();
			ObjText_SetFontType(objs,"Raleway-Regular");
			ObjText_SetFontSize(objs,fontsize);
			ObjText_SetFontColorTop(objs,255,255,255);
			ObjText_SetFontColorBottom(objs,255,255,255);
			ObjText_SetFontBold(objs,true);
			ObjText_SetFontBorderWidth(objs,1);
			ObjText_SetFontBorderType(objs,BORDER_SHADOW);
			ObjText_SetFontBorderColor(objs,0,0,0);
			ObjRender_SetY(objs,yyt);
			loop
			{
				let fraps=GetCurrentFps;
				if(IsReplay){fraps=GetReplayFps;}
				ObjText_SetText(objs,rtos("000.00",fraps));
				ObjRender_SetX(objs,xxt-1+(ObjText_GetTotalWidth(objt)/2));
				ObjRender_SetAlpha(objt,256*alphascale);
				ObjRender_SetAlpha(objs,256*alphascale);
				yield;
			}
		}
	}
	loop
	{
		if(GetPlayerX<=210 && GetPlayerX>=0 && GetPlayerY<=480 && GetPlayerY>=390 && alphascale>0.25){alphascale-=0.75/30;}
		if(GetPlayerX>210 || GetPlayerX<0 || GetPlayerY>480 || GetPlayerY<390){if(alphascale<1){alphascale+=0.75/30;}}
		yield;
	}
}
task BossHUD
{
	while(menu==true){yield;}
	let xx=GetStgFrameWidth/2+280;
	let yy=GetStgFrameHeight/2-200;
	let scalepic=80;
	let alphascale=0;
	let fontsize=14;
	symbol;
	life;
	score;
	task symbol
	{
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,dir~"graphic/Symbol.png");
		ObjSprite2D_SetSourceRect(obj,0,256,512,512);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetPosition(obj,xx,yy,0);
		ObjRender_SetScaleXYZ(obj,scalepic/256,scalepic/256,1);
		loop
		{
			ObjRender_SetAlpha(obj,256*alphascale);
			yield;
		}
	}
	task life
	{
		let xxt=GetStgFrameWidth-scalepic*1.5-10;
		let yyt=yy-4;
		let objt = ObjText_Create;
		ObjText_SetText(objt,"Health");
		ObjText_SetFontType(objt,"Raleway-SemiBold");
		ObjText_SetFontSize(objt,fontsize);
		ObjText_SetFontColorTop(objt,255,255,255);
		ObjText_SetFontColorBottom(objt,255,255,255);
		ObjText_SetFontBold(objt,true);
		ObjText_SetFontBorderWidth(objt,1);
		ObjText_SetFontBorderType(objt,BORDER_SHADOW);
		ObjText_SetFontBorderColor(objt,0,0,0);
		ObjRender_SetPosition(objt,xxt,yyt,0);
		let clife=0;
		lifegauge;
		lifenumber;
		task lifegauge
		{
			let lifelimit=3;
			let dimlife=32;
			let scalext=620-scalepic;
			let scaleyt=12;
			let range=4;
			let xxl=GetStgFrameWidth/2-scalepic/2;
			let yyl=yyt-8;
			let objt1=ObjPrim_Create(OBJ_SPRITE_2D);
			let objt2=ObjPrim_Create(OBJ_SPRITE_2D);
			ObjPrim_SetTexture(objt1,dir~"graphic/Bar.png");
			ObjPrim_SetTexture(objt2,dir~"graphic/Bar.png");
			ObjSprite2D_SetSourceRect(objt1,0,0,512,16);
			ObjSprite2D_SetSourceRect(objt2,0,0,512,16);
			ObjSprite2D_SetDestCenter(objt1);
			ObjSprite2D_SetDestRect(objt2,0,-8,512,8);
			ObjRender_SetAngleZ(objt2,180);
			ObjRender_SetColor(objt1,255,255,255);
			ObjRender_SetColor(objt2,60,60,60);
			loop
			{
				ObjRender_SetAlpha(objt1,256*alphascale/2*clife);
				ObjRender_SetAlpha(objt2,256*alphascale/2*clife);
				let life1=ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_ACTIVE_STEP_TOTAL_MAX_LIFE);
				let life2=ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_ACTIVE_STEP_TOTAL_LIFE);
				ObjRender_SetScaleXYZ(objt1,scalext/512,scaleyt/16,0);
				ObjRender_SetScaleXYZ(objt2,((scalext-range)/512)*life2/life1,(scaleyt-range)/16,0);
				ObjRender_SetPosition(objt1,xxl,yyl,0);
				ObjRender_SetPosition(objt2,xxl-1+(scalext-range)/2,yyl-range/4,0);
				yield;
			}
		}
		task lifenumber
		{
			let objd1 = ObjText_Create;
			let objd2 = ObjText_Create;
			let objd3 = ObjText_Create;
			ObjText_SetFontType(objd1,"Raleway-Regular");
			ObjText_SetFontType(objd2,"Raleway-Regular");
			ObjText_SetFontType(objd3,"Raleway-Regular");
			ObjText_SetFontSize(objd1,fontsize);
			ObjText_SetFontSize(objd2,fontsize);
			ObjText_SetFontSize(objd3,fontsize);
			ObjText_SetFontColorTop(objd1,255,255,255);
			ObjText_SetFontColorBottom(objd1,255,255,255);
			ObjText_SetFontColorTop(objd2,255,255,255);
			ObjText_SetFontColorBottom(objd2,255,255,255);
			ObjText_SetFontColorTop(objd3,255,255,255);
			ObjText_SetFontColorBottom(objd3,255,255,255);
			ObjText_SetFontBold(objd1,true);
			ObjText_SetFontBorderWidth(objd1,1);
			ObjText_SetFontBold(objd2,true);
			ObjText_SetFontBorderWidth(objd2,1);
			ObjText_SetFontBold(objd3,true);
			ObjText_SetFontBorderWidth(objd3,1);
			ObjText_SetFontBorderType(objd1,BORDER_SHADOW);
			ObjText_SetFontBorderColor(objd1,0,0,0);
			ObjText_SetFontBorderType(objd2,BORDER_SHADOW);
			ObjText_SetFontBorderColor(objd2,0,0,0);
			ObjText_SetFontBorderType(objd3,BORDER_SHADOW);
			ObjText_SetFontBorderColor(objd3,0,0,0);
			loop
			{
				let lifecount1=ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_ACTIVE_STEP_TOTAL_MAX_LIFE);
				let lifecount2=ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_ACTIVE_STEP_TOTAL_LIFE);
				let lifefont1=IntToString(lifecount1);
				let lifefont2=IntToString(lifecount2);
				ObjText_SetText(objd1,lifefont1);
				ObjText_SetText(objd2,"/");
				ObjText_SetText(objd3,lifefont2);
				ObjText_SetHorizontalAlignment(objd1,ALIGNMENT_RIGHT);
				ObjText_SetHorizontalAlignment(objd2,ALIGNMENT_RIGHT);
				ObjText_SetHorizontalAlignment(objd3,ALIGNMENT_RIGHT);
				ObjText_SetMaxWidth(objd1,ObjText_GetTextLength(objd1)*fontsize);
				ObjText_SetMaxWidth(objd2,fontsize);
				ObjText_SetMaxWidth(objd3,ObjText_GetTextLength(objd1)*fontsize);
				let xxo=xxt-((ObjText_GetTextLength(objd1)+0.5)*fontsize);
				ObjRender_SetPosition(objd1,xxo,yyt,0);
				xxo-=ObjText_GetTotalWidth(objd1)/2-fontsize*2.5;
				ObjRender_SetPosition(objd2,xxo,yyt,0);
				xxo-=ObjText_GetTotalWidth(objd2)/2+fontsize*4.5;
				ObjRender_SetPosition(objd3,xxo,yyt,0);
				ObjRender_SetAlpha(objd1,256*alphascale*clife);
				ObjRender_SetAlpha(objd2,256*alphascale*clife);
				ObjRender_SetAlpha(objd3,256*alphascale*clife);
				yield;
			}
		}
		loop
		{
			let lifecheck=ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_ACTIVE_STEP_TOTAL_LIFE);
			if(lifecheck<=0 && clife>0){clife-=1/30;}
			if(lifecheck>0 && clife<1){clife+=1/30;}
			ObjRender_SetAlpha(objt,256*alphascale*clife);
			yield;
		}
	}
	task score
	{
		let xxt=GetStgFrameWidth-scalepic*1.5-10;
		let yyt=yy-36;
		let objt = ObjText_Create();
		ObjText_SetText(objt,"Score");
		ObjText_SetFontType(objt,"Raleway-SemiBold");
		ObjText_SetFontSize(objt,fontsize);
		ObjText_SetFontColorTop(objt,255,255,255);
		ObjText_SetFontColorBottom(objt,255,255,255);
		ObjText_SetFontBold(objt,true);
		ObjText_SetFontBorderWidth(objt,1);
		ObjText_SetFontBorderType(objt,BORDER_SHADOW);
		ObjText_SetFontBorderColor(objt,0,0,0);
		ObjRender_SetPosition(objt,xxt,yyt,0);
		drawscore;
		task drawscore
		{
			let objd = ObjText_Create;
			ObjText_SetFontType(objd,"Raleway-Regular");
			ObjText_SetFontSize(objd,fontsize);
			ObjText_SetFontColorTop(objd,255,255,255);
			ObjText_SetFontColorBottom(objd,255,255,255);
			ObjText_SetFontBold(objd,true);
			ObjText_SetFontBorderWidth(objd,1);
			ObjText_SetFontBorderType(objd,BORDER_SHADOW);
			ObjText_SetFontBorderColor(objd,0,0,0);
			loop
			{
				let scorecount=GetScore;
				let scorefont=IntToString(scorecount);
				ObjText_SetText(objd,scorefont);
				ObjText_SetHorizontalAlignment(objd,ALIGNMENT_RIGHT);
				ObjText_SetMaxWidth(objd,fontsize*13);
				ObjRender_SetPosition(objd,xxt-fontsize*13.5,yyt,0);
				ObjRender_SetAlpha(objd,256*alphascale);
				ObjRender_SetAlpha(objt,256*alphascale);
				yield;
			}
		}
	}
	loop
	{
		if(GetPlayerY>=0 && GetPlayerY<=90 && alphascale>0.25){alphascale-=0.75/30;}
		if(GetPlayerY<0 || GetPlayerY>90){if(alphascale<1){alphascale+=0.75/30;}}
		yield;
	}
}