let CSD = GetCurrentScriptDirectory;
let MD = GetModuleDirectory;
let IsBossExisting = false;
let maxlife = 0;

#include"./../LIB/Function_Misc.dnh"
#include"./SE_Const.dnh"


@Initialize {
	SetPauseScriptPath(CSD ~ "Pause.dnh");
	SetEndSceneScriptPath(CSD ~ "EndScene.dnh");
	SetReplaySaveSceneScriptPath(CSD ~ "ReplaySaveScene.dnh");
	
	// LoadTextureSet(System_All);
	
	InitFrame;
	
	InstallFont(CSD ~ "FONT/Eurostib.TTF");
	InstallFont(CSD ~ "FONT/THSpatial.ttf");
	InstallFont(CSD ~ "FONT/rusq.ttf");
	InstallFont(CSD ~ "FONT/LBRITED.TTF");
	InstallFont(CSD ~ "FONT/Lekton-Regular.ttf");
	InstallFont(CSD ~ "FONT/RussoOne-Regular.ttf");
	InstallFont(CSD ~ "FONT/CRYSTALC.TTF");
	
	SetStgFrame(40, 16, 424, 464, 20, 80);
	
	HUD;
	BossEffects;
	BossTimer;
	BossName;
	CurrentFps;
	SnapShot;
	if(IsReplay) { ReplayFps; }
	
	StartItemScript(CSD ~ "Item.dnh");
	let scriptEffect = LoadScriptInThread(CSD ~ "Effect.dnh");
	StartScript(scriptEffect);
	let scriptSound = LoadScript(CSD ~ "Audio.dnh");
	StartScript(scriptSound);
}
@MainLoop {
	DebugKeys;
	yield;
}
@Event {
	alternative(GetEventType)
	case(EV_START_BOSS_STEP) {
		if(length(GetEnemyBossObjectID)!=0) { maxlife = ObjEnemy_GetInfo(GetEnemyBossObjectID[0],INFO_LIFE); }
	}
}
function DebugKeys {
	if(GetCommonData("Debug",true)) {
		if(GetKeyState(KEY_I)==KEY_PUSH) { SetPlayerInvincibilityFrame(100000); }
		if(GetKeyState(KEY_H)==KEY_PUSH) {
			if(length(GetEnemyBossObjectID)!=0) { ObjEnemy_AddLife(GetEnemyBossObjectID[0],-maxlife/10); }
		}
		if(GetKeyState(KEY_K)==KEY_PUSH) {
			if(length(GetEnemyBossObjectID)!=0) { ObjEnemy_AddLife(GetEnemyBossObjectID[0],-maxlife); }
		}
		if(GetKeyState(KEY_U)==KEY_PUSH) { SetPlayerInvincibilityFrame(0); }
	}
}
function InitFrame {
	let path = CSD ~ "IMG/frame.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 0);
	ObjSprite2D_SetSourceRect(obj, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
	ObjSprite2D_SetDestRect(obj, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}
task SnapShot {
	loop {
		if(GetKeyState(KEY_INSERT)==KEY_PUSH) { SaveSnapShotA1(PSD ~ "Snapshot/"~GetCurrentDateTimeS[0..4]~ "-" ~GetCurrentDateTimeS[4..6]~ "-" ~GetCurrentDateTimeS[6..8]~ "-" ~GetCurrentDateTimeS[8..10]~ "-" ~GetCurrentDateTimeS[10..12]~ "-" ~GetCurrentDateTimeS[12..14]~ ".png"); }
		yield;
	}
}
task SpellTime {
	let objScene = GetEnemyBossSceneObjectID;
	let bosstime = 99;
	let GetTimer = 99;
	LoadSound(timeout);
	LoadSound(timeout2);
	while(!Obj_IsDeleted(objScene)) {
		GetTimer = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER);
		if(bosstime != GetTimer && GetTimer <11){
			if(GetTimer>4){ PlaySE(timeout); }
			if(GetTimer<5 && GetTimer>-1){ PlaySE(timeout2); }
			bosstime = GetTimer;
		}
		yield;
	}
}
task BossEffects {
	loop {
		if(!IsBossExisting) {
			while(length(GetEnemyBossObjectID)==0) { yield; }
			while(GetCommonData("OnEvent",false)==true) { yield; }
			if(GetAreaCommonData("Options","LifeBar",true)) { BossLife; }
			else { TBossLife; }
			if(GetAreaCommonData("Options","Aura",true)) { Aura; }
			BossMagicCircle;
			SpellTime;
			BossShadow;
			BossName;
			IsBossExisting = true;
		}
		if(GetEnemyBossSceneObjectID == ID_INVALID) { IsBossExisting = false; }
		yield;
	}
}
function Aura {
	loop(2) { yield; }
	let effect = GetCurrentScriptDirectory ~ "IMG/Aura.png";
	let scalecounter = 1.5;
	let objEnemy = ID_INVALID;
	let objScene = GetEnemyBossSceneObjectID;
	let RED = 0;
	let GREEN = 0;
	let BLUE = 0;
	AuraA;

	task AuraA {
		yield;
		loop(5){
			AuraA;
			loop(6) { yield; }
		}

		task AuraA {
			let scale_0 = 4;
			let scale = scale_0;
			let scale_d = -3.5/30;
			let color = [0, 0, 0];
			let color_r_d = 224/30;
			let color_gb = 150;
			let color_gb_ang = 0;
			let color_gb_ang_d = 90/30;

			let obj = ObjPrim_Create(OBJ_SPRITE_2D);

			ObjPrim_SetTexture(obj, effect);
			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
			Obj_SetRenderPriorityI(obj, 38);
			ObjRender_SetAngleXYZ(obj, 0, 0, rand(0,360));
			ObjRender_SetScaleXYZ(obj, scale, scale * scalecounter, scale);
			ObjSprite2D_SetSourceRect(obj, 0, 0, 50, 50);
			ObjSprite2D_SetDestCenter(obj);

			while(!Obj_IsDeleted(objScene)){
				if(Obj_IsDeleted(objScene)) { break; }
				if(length(GetEnemyBossObjectID)>0) {
					objEnemy = GetEnemyBossObjectID[0];
					RED = Obj_GetValueD(objEnemy,"Aura Color",[100,100,100])[0];
					GREEN = Obj_GetValueD(objEnemy,"Aura Color",[100,100,100])[1];
					BLUE = Obj_GetValueD(objEnemy,"Aura Color",[100,100,100])[2];
				}
				loop(29){
					if(length(GetEnemyBossObjectID)>0) { objEnemy = GetEnemyBossObjectID[0]; }
					scale += scale_d;
					color_gb_ang += color_gb_ang_d;

					color[0] = color_gb * sin(color_gb_ang)^RED;
					color[1] = color_gb * sin(color_gb_ang)^GREEN;
					color[2] = color_gb * sin(color_gb_ang)^BLUE;

					ObjRender_SetColor(obj, color[0], color[1], color[2]);
					ObjRender_SetScaleXYZ(obj, scale, scale * scalecounter, scale);
					if(length(GetEnemyBossObjectID)>0) { ObjRender_SetPosition(obj, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 0); }
					yield;
					//if(Obj_IsDeleted(objEnemy)) { break; }
				}
				scale = scale_0;
				color_gb_ang = 0;
				color = [0, 0, 0];

				ObjRender_SetColor(obj, color[0], color[1], color[2]);

				ObjRender_SetScaleXYZ(obj, scale, scale * scalecounter, scale);
				ObjRender_SetAngleXYZ(obj, 0, 0, rand(0,360));
				ObjRender_SetPosition(obj, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 0);

				yield;
			}
			Obj_Delete(obj);
		}
	}
}
task BossShadow {
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, CSD ~ "IMG/shadow.png");
	Obj_SetRenderPriorityI(obj, 1);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 52, 16);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetY(obj, GetStgFrameHeight+24);
	
	let objEnemy = ID_INVALID;
	let objScene = GetEnemyBossSceneObjectID;
	let alpha = 0;
	
	while(!Obj_IsDeleted(objScene)) {
		if(length(GetEnemyBossObjectID)>0) { objEnemy = GetEnemyBossObjectID[0]; }
		ObjRender_SetX(obj,ObjMove_GetX(objEnemy)+GetStgFrameLeft);
		ObjRender_SetAlpha(obj, alpha);
		if(alpha<150) { alpha+=150/30; }
		yield;
	}
	Obj_Delete(obj);
}
sub HUD {
	DifficultyDisplay;
	// HiScoreDisplay;
	ScoreDisplay;
	PointValueDisplay;
	GrazeDisplay;
	PlayerSpellDisplay;
	PlayerLifeDisplay;
	// PowerDisplay;
	POCDisplay;
	// BalanceDisplay;

	task DifficultyDisplay {
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,90);
		ObjPrim_SetTexture(obj, CSD ~ "IMG/Difficulty.png");
		
		ObjRender_SetPosition(obj,538,34,0);
		
		loop {
			if(GetAreaCommonData("PlayState","Difficulty","Hard")=="Easy") { ObjSprite2D_SetSourceRect(obj, 0, 0, 192, 45); }
			if(GetAreaCommonData("PlayState","Difficulty","Hard")=="Normal") { ObjSprite2D_SetSourceRect(obj, 0, 45, 192, 85); }
			if(GetAreaCommonData("PlayState","Difficulty","Hard")=="Hard") { ObjSprite2D_SetSourceRect(obj, 0, 88, 192, 126); }
			if(GetAreaCommonData("PlayState","Difficulty","Hard")=="Lunatic") { ObjSprite2D_SetSourceRect(obj, 0, 128, 192, 167); }
			if(GetAreaCommonData("PlayState","Difficulty","Hard")=="Extra") { ObjSprite2D_SetSourceRect(obj, 0, 170, 192, 210); }
			if(GetAreaCommonData("PlayState","Difficulty","Hard")=="Last Word") { ObjSprite2D_SetSourceRect(obj, 0, 212, 192, 252); }
			ObjSprite2D_SetDestCenter(obj);
			yield;
		}
	}
	task HiScoreDisplay {
		let objScore = ObjText_Create;
		ObjText_SetText(objScore, "HiScore");
		ObjText_SetFontType(objScore, "Eurostile");
		ObjText_SetFontSize(objScore, 18);
		ObjText_SetFontBold(objScore, true);
		ObjText_SetFontColorTop(objScore, 255, 255, 255);
		ObjText_SetFontColorBottom(objScore, 255, 255, 255);
		ObjText_SetFontBorderType(objScore, BORDER_FULL);
		ObjText_SetFontBorderColor(objScore, 0, 0, 0);
		ObjText_SetFontBorderWidth(objScore, 2);
		Obj_SetRenderPriorityI(objScore, 1);
		ObjRender_SetX(objScore, 425);
		ObjRender_SetY(objScore, 50);
		
		let objNum = ObjText_Create;
		ObjText_SetFontType(objNum, "RussellSquare");
		ObjText_SetFontSize(objNum,21);
		ObjText_SetFontColorTop(objNum,255,255,255);
		ObjText_SetFontColorBottom(objNum,150,150,150);
		ObjText_SetFontBorderType(objNum,BORDER_FULL);
		ObjText_SetFontBorderWidth(objNum,2);
		ObjText_SetFontBorderColor(objNum,0,0,0);
		ObjText_SetHorizontalAlignment(objNum,ALIGNMENT_RIGHT);
		ObjText_SetMaxWidth(objNum,GetStgFrameWidth);
		Obj_SetRenderPriorityI(objNum,90);
		
		loop {
			let score = GetCommonData("HiScore",0);
			score = min(score, 1999999999);
			
			ObjText_SetText(objNum,ToCommas(score));
			ObjRender_SetPosition(objNum,254,50,0);
			yield;
		}
		
	}
	task ScoreDisplay {
		let objScore = ObjText_Create;
		ObjText_SetText(objScore, "Score");
		ObjText_SetFontType(objScore, "Eurostile");
		ObjText_SetFontSize(objScore, 18);
		ObjText_SetFontBold(objScore, true);
		ObjText_SetFontColorTop(objScore, 255, 255, 255);
		ObjText_SetFontColorBottom(objScore, 255, 255, 255);
		ObjText_SetFontBorderType(objScore, BORDER_FULL);
		ObjText_SetFontBorderColor(objScore, 0, 0, 0);
		ObjText_SetFontBorderWidth(objScore, 2);
		Obj_SetRenderPriorityI(objScore, 1);
		ObjRender_SetX(objScore, 425);
		ObjRender_SetY(objScore, 71);
		
		let objNum = ObjText_Create;
		ObjText_SetFontType(objNum, "RussellSquare");
		ObjText_SetFontSize(objNum,21);
		ObjText_SetFontColorTop(objNum,255,255,255);
		ObjText_SetFontColorBottom(objNum,150,150,150);
		ObjText_SetFontBorderType(objNum,BORDER_FULL);
		ObjText_SetFontBorderWidth(objNum,2);
		ObjText_SetFontBorderColor(objNum,0,0,0);
		ObjText_SetHorizontalAlignment(objNum,ALIGNMENT_RIGHT);
		ObjText_SetMaxWidth(objNum,GetStgFrameWidth);
		Obj_SetRenderPriorityI(objNum,90);
		
		loop {
			let score = GetScore;
			score = min(score, 1999999999);
			
			ObjText_SetText(objNum,ToCommas(score));
			ObjRender_SetPosition(objNum,254,71,0);
			yield;
		}
		
	}
	task PlayerLifeDisplay {
		let objText = ObjText_Create;
		ObjText_SetText(objText, "Lives");
		ObjText_SetFontType(objText, "Eurostile");
		ObjText_SetFontSize(objText, 18);
		ObjText_SetFontBold(objText, true);
		ObjText_SetFontColorTop(objText, 255, 128, 255);
		ObjText_SetFontColorBottom(objText, 192, 32, 192);
		ObjText_SetFontBorderType(objText, BORDER_FULL);
		ObjText_SetFontBorderColor(objText, 0, 0, 0);
		ObjText_SetFontBorderWidth(objText, 2);
		Obj_SetRenderPriorityI(objText, 1);
		ObjRender_SetX(objText, 432);
		ObjRender_SetY(objText, 96);

		let objStar1 = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		ObjPrim_SetTexture(objStar1, CSD ~ "IMG/system.png");
		Obj_SetRenderPriorityI(objStar1, 90);
		ObjSpriteList2D_SetSourceRect(objStar1, 111, 1, 127, 17);
		
		let objStar2 = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		ObjPrim_SetTexture(objStar2, CSD ~ "IMG/system.png");
		Obj_SetRenderPriorityI(objStar2, 90);
		ObjSpriteList2D_SetSourceRect(objStar2, 239, 1, 255, 17);
		
		let objStar3 = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(objStar3, CSD ~ "IMG/system.png");
		Obj_SetRenderPriorityI(objStar3, 90);
		

		loop {
			let life = GetPlayerLife;
			let pieces = GetCommonData("LifePieces",0);
			
			ObjSpriteList2D_ClearVertexCount(objStar1);
			ascent(i in 0..8) {
				ObjSpriteList2D_SetDestRect(objStar1, 502+i*16, 99, 502+(i+1)*16, 115);
				ObjSpriteList2D_AddVertex(objStar1);
			}
			
			ObjSpriteList2D_ClearVertexCount(objStar2);
			ascent(i in 0..life) {
				ObjSpriteList2D_SetDestRect(objStar2, 502+i*16, 99, 502+(i+1)*16, 115);
				ObjSpriteList2D_AddVertex(objStar2);
			}
			ObjSprite2D_SetSourceRect(objStar3, 111+pieces*16, 1, 127+pieces*16, 17);
			// ObjSprite2D_SetDestRect(objStar3, 502+life*16, 99, 502+(life+1)*16, 115);
			yield;
		}
	}
	task PlayerSpellDisplay {
		let objText = ObjText_Create;
		ObjText_SetText(objText, "Spell");
		ObjText_SetFontType(objText, "Eurostile");
		ObjText_SetFontSize(objText, 18);
		ObjText_SetFontBold(objText, true);
		ObjText_SetFontColorTop(objText, 128, 255, 128);
		ObjText_SetFontColorBottom(objText, 32, 192, 32);
		ObjText_SetFontBorderType(objText, BORDER_FULL);
		ObjText_SetFontBorderColor(objText, 0, 0, 0);
		ObjText_SetFontBorderWidth(objText, 2);
		Obj_SetRenderPriorityI(objText, 1);
		ObjRender_SetX(objText, 432);
		ObjRender_SetY(objText, 117);
		
		let objStar1 = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		ObjPrim_SetTexture(objStar1, CSD ~ "IMG/system.png");
		Obj_SetRenderPriorityI(objStar1, 90);
		ObjSpriteList2D_SetSourceRect(objStar1, 111, 21, 127, 37);
		
		let objStar2 = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		ObjPrim_SetTexture(objStar2, CSD ~ "IMG/system.png");
		Obj_SetRenderPriorityI(objStar2, 90);
		ObjSpriteList2D_SetSourceRect(objStar2, 239, 21, 255, 37);
		
		let objStar3 = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(objStar3, CSD ~ "IMG/system.png");
		Obj_SetRenderPriorityI(objStar3, 90);

		loop {
			let spell = GetPlayerSpell;
			let pieces = GetCommonData("SpellPieces",0);
			
			ObjSpriteList2D_ClearVertexCount(objStar1);
			ascent(i in 0..8) {
				ObjSpriteList2D_SetDestRect(objStar1, 502+i*16, 120, 502+(i+1)*16, 136);
				ObjSpriteList2D_AddVertex(objStar1);
			}
			
			ObjSpriteList2D_ClearVertexCount(objStar2);
			ascent(i in 0..spell) {
				ObjSpriteList2D_SetDestRect(objStar2, 502+i*16, 120, 502+(i+1)*16, 136);
				ObjSpriteList2D_AddVertex(objStar2);
			}
			ObjSprite2D_SetSourceRect(objStar3, 111+pieces*16, 21, 127+pieces*16, 37);
			ObjSprite2D_SetDestRect(objStar3, 502+spell*16, 120, 502+(spell+1)*16, 136);
			yield;
		}
	}
	task PowerDisplay {
		let objPower = ObjText_Create;
		ObjText_SetText(objPower, "Power");
		ObjText_SetFontType(objPower, "Eurostile");
		ObjText_SetFontSize(objPower, 18);
		ObjText_SetFontBold(objPower, true);
		ObjText_SetFontColorTop(objPower, 255, 128, 128);
		ObjText_SetFontColorBottom(objPower, 192, 32, 32);
		ObjText_SetFontBorderType(objPower, BORDER_FULL);
		ObjText_SetFontBorderColor(objPower, 0, 0, 0);
		ObjText_SetFontBorderWidth(objPower, 2);
		Obj_SetRenderPriorityI(objPower, 1);
		ObjRender_SetX(objPower, 442);
		ObjRender_SetY(objPower, 142);

		let objNum = ObjText_Create;
		ObjText_SetFontType(objNum, "RussellSquare");
		ObjText_SetFontSize(objNum,20);
		ObjText_SetFontColorTop(objNum,255,128,128);
		ObjText_SetFontColorBottom(objNum,192,32,32);
		ObjText_SetFontBorderType(objNum,BORDER_FULL);
		ObjText_SetFontBorderWidth(objNum,2);
		ObjText_SetFontBorderColor(objNum,0,0,0);
		ObjText_SetHorizontalAlignment(objNum,ALIGNMENT_RIGHT);
		ObjText_SetMaxWidth(objNum,GetStgFrameWidth);
		Obj_SetRenderPriorityI(objNum,90);

		loop {
			let power = GetPlayerPower;
			
			ObjText_SetText(objNum,rtos("0.00",power) ~ " / 4.00");
			ObjRender_SetPosition(objNum,234,142,0);
			yield;
		}
	}
	task PointValueDisplay {
		let objValue = ObjText_Create;
		ObjText_SetText(objValue, "Value");
		ObjText_SetFontType(objValue, "Eurostile");
		ObjText_SetFontSize(objValue, 18);
		ObjText_SetFontBold(objValue, true);
		ObjText_SetFontColorTop(objValue, 128, 128, 255);
		ObjText_SetFontColorBottom(objValue, 32, 32, 192);
		ObjText_SetFontBorderType(objValue, BORDER_FULL);
		ObjText_SetFontBorderColor(objValue, 0, 0, 0);
		ObjText_SetFontBorderWidth(objValue, 2);
		Obj_SetRenderPriorityI(objValue, 1);
		ObjRender_SetX(objValue, 442);
		ObjRender_SetY(objValue, 163);

		let objNum = ObjText_Create;
		ObjText_SetFontType(objNum, "RussellSquare");
		ObjText_SetFontSize(objNum,20);
		ObjText_SetFontColorTop(objNum,128,128,255);
		ObjText_SetFontColorBottom(objNum,32,32,192);
		ObjText_SetFontBorderType(objNum,BORDER_FULL);
		ObjText_SetFontBorderWidth(objNum,2);
		ObjText_SetFontBorderColor(objNum,0,0,0);
		ObjText_SetHorizontalAlignment(objNum,ALIGNMENT_RIGHT);
		ObjText_SetMaxWidth(objNum,GetStgFrameWidth);
		Obj_SetRenderPriorityI(objNum,90);

		loop {
			let point = GetCommonData("ItemValue",10000);
			point = min(truncate(point/10)*10, 999999);
			
			ObjText_SetText(objNum,ToCommas(point));
			ObjRender_SetPosition(objNum,234,163,0);
			yield;
		}
	}
	task GrazeDisplay {
		let objGraze = ObjText_Create;
		ObjText_SetText(objGraze, "Graze");
		ObjText_SetFontType(objGraze, "Eurostile");
		ObjText_SetFontSize(objGraze, 18);
		ObjText_SetFontBold(objGraze, true);
		ObjText_SetFontColorTop(objGraze, 128, 128, 128);
		ObjText_SetFontColorBottom(objGraze, 32, 32, 32);
		ObjText_SetFontBorderType(objGraze, BORDER_FULL);
		ObjText_SetFontBorderColor(objGraze, 0, 0, 0);
		ObjText_SetFontBorderWidth(objGraze, 2);
		Obj_SetRenderPriorityI(objGraze, 1);
		ObjRender_SetX(objGraze, 442);
		ObjRender_SetY(objGraze, 184);

		let objNum = ObjText_Create;
		ObjText_SetFontType(objNum, "RussellSquare");
		ObjText_SetFontSize(objNum,20);
		ObjText_SetFontColorTop(objNum,128,128,128);
		ObjText_SetFontColorBottom(objNum,32,32,32);
		ObjText_SetFontBorderType(objNum,BORDER_FULL);
		ObjText_SetFontBorderWidth(objNum,2);
		ObjText_SetFontBorderColor(objNum,0,0,0);
		ObjText_SetHorizontalAlignment(objNum,ALIGNMENT_RIGHT);
		ObjText_SetMaxWidth(objNum,GetStgFrameWidth);
		Obj_SetRenderPriorityI(objNum,90);

		loop {
			let graze = GetGraze;
			graze = min(graze, 99999);
			
			ObjText_SetText(objNum,ToCommas(graze));
			ObjRender_SetPosition(objNum,234,184,0);
			yield;
		}
	}
	task POCDisplay {
		let objEffect = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(objEffect, CSD ~ "IMG/system.png");
		Obj_SetRenderPriorityI(objEffect, 90);
		ObjSprite2D_SetSourceRect(objEffect, 6, 415, 38, 447);
		ObjSprite2D_SetDestCenter(objEffect);
		
		let objEffect2 = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(objEffect2, CSD ~ "IMG/system.png");
		Obj_SetRenderPriorityI(objEffect2, 90);
		ObjSprite2D_SetSourceRect(objEffect2, 66, 418, 77, 447);
		ObjSprite2D_SetDestCenter(objEffect2);
		
		let objStar1 = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(objStar1, CSD ~ "IMG/system.png");
		Obj_SetRenderPriorityI(objStar1, 90);
		ObjSprite2D_SetSourceRect(objStar1, 6, 452, 37, 481);
		ObjSprite2D_SetDestCenter(objStar1);
		
		let objStar2 = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(objStar2, CSD ~ "IMG/system.png");
		Obj_SetRenderPriorityI(objStar2, 90);
		ObjSprite2D_SetSourceRect(objStar2, 6, 452, 37, 481);
		ObjSprite2D_SetDestCenter(objStar2);
		
		let objText = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(objText, CSD ~ "IMG/system.png");
		Obj_SetRenderPriorityI(objText, 90);
		ObjSprite2D_SetSourceRect(objText, 43, 425, 63, 437);
		ObjSprite2D_SetDestCenter(objText);
		
		let spin = 0;
		
		loop {
			let poc = GetCommonData("PointOfCollection",100)+16;
			
			ObjRender_SetPosition(objText,18,poc-1,0);
			ObjRender_SetPosition(objEffect,17,poc-1,0);
			ObjRender_SetPosition(objEffect2,34,poc,0);
			ObjRender_SetPosition(objStar1,16.5,poc-1.5,0);
			ObjRender_SetPosition(objStar2,16.5,poc-1.5,0);
			ObjRender_SetAngleZ(objStar1,spin);
			ObjRender_SetAngleZ(objStar2,-spin);
			spin+=0.3;
			yield;
		}
	}
	task BalanceDisplay {
		let objBalance = ObjText_Create;
		ObjText_SetText(objBalance, "Balance");
		ObjText_SetFontType(objBalance, "Eurostile");
		ObjText_SetFontSize(objBalance, 18);
		ObjText_SetFontBold(objBalance, true);
		ObjText_SetFontColorTop(objBalance, 71, 172, 255);
		ObjText_SetFontColorBottom(objBalance, 32, 77, 114);
		ObjText_SetFontBorderType(objBalance, BORDER_FULL);
		ObjText_SetFontBorderColor(objBalance, 0, 0, 0);
		ObjText_SetFontBorderWidth(objBalance, 2);
		Obj_SetRenderPriorityI(objBalance, 1);
		ObjRender_SetX(objBalance, 491);
		ObjRender_SetY(objBalance, 205);
	
		let objEffect = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(objEffect, CSD ~ "IMG/system.png");
		Obj_SetRenderPriorityI(objEffect, 90);
		ObjSprite2D_SetSourceRect(objEffect, 78, 444, 252, 469);
	
		let objEffect2 = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(objEffect2, CSD ~ "IMG/system.png");
		Obj_SetRenderPriorityI(objEffect2, 90);
		ObjSprite2D_SetSourceRect(objEffect2, 78, 418, 252, 443);
		
		let objNum = ObjText_Create;
		ObjText_SetFontType(objNum, "RussellSquare");
		ObjText_SetFontSize(objNum,18);
		ObjText_SetFontColorTop(objNum,255,255,255);
		ObjText_SetFontColorBottom(objNum,255,255,255);
		ObjText_SetFontBorderType(objNum,BORDER_FULL);
		ObjText_SetFontBorderWidth(objNum,2);
		ObjText_SetFontBorderColor(objNum,0,0,0);
		ObjText_SetHorizontalAlignment(objNum,ALIGNMENT_CENTER);
		ObjText_SetMaxWidth(objNum,GetStgFrameWidth);
		Obj_SetRenderPriorityI(objNum,90);
		
		loop {
			let balance = GetCommonData("Balance",0)/10000;
			
			ObjSprite2D_SetDestRect(objEffect2,0,0,170,25);
			ObjSprite2D_SetDestRect(objEffect,0,0,170*balance,25);
			ObjRender_SetPosition(objEffect2,446,228,0);
			ObjRender_SetPosition(objEffect,446,228,0);
			
			ObjText_SetText(objNum,IntToString(balance*100) ~ "%");
			ObjRender_SetPosition(objNum,337,229,0);
			yield;
		}
	}
}
task TBossLife {
	let pathHealth = CSD ~ "IMG/Default_System.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathHealth);
	Obj_SetRenderPriority(obj, 0.7);

	let lastRemStep = -1;
	let lifeRateRender = 0;
	let fade = 0;
	let objScene = ID_INVALID;
	
	loop {
		objScene = GetEnemyBossSceneObjectID;
		ObjSpriteList2D_ClearVertexCount(obj);
		if(GetPlayerY < 96){
			fade = max(fade-10, 85);
		} else { fade = min(fade+10, 255); }
		ObjRender_SetAlpha(obj, fade);
		if(objScene != ID_INVALID){
			RenderLife;
		}
		yield;
	}


	function RenderLife {
		let countRemStep = ObjEnemyBossScene_GetInfo(objScene, INFO_REMAIN_STEP_COUNT);
		if(lastRemStep != countRemStep){
			lifeRateRender = 0;
		}

		let lifeTotalMax = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_TOTAL_MAX_LIFE);
		let lifeTotal = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_TOTAL_LIFE);
		let lifeRate = min(lifeTotal / lifeTotalMax, lifeRateRender);
		ObjSpriteList2D_SetSourceRect(obj, 1, 1, 127, 11);
		ObjSpriteList2D_SetDestRect(obj, 72, 8, 72 + 270 * lifeRate, 12);
		ObjSpriteList2D_AddVertex(obj);

		ObjSpriteList2D_SetSourceRect(obj, 132, 1, 137, 11);
		let listLifeDiv = [0] ~ ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_LIFE_RATE_LIST);
		ascent(iDiv in 0 .. length(listLifeDiv)){
			let rate = listLifeDiv[iDiv];
			let x = 72 + 270 * (1-rate);
			ObjSpriteList2D_SetDestRect(obj, x-1, 4, x + 1, 14);
			ObjSpriteList2D_AddVertex(obj);
		}

		ObjSpriteList2D_SetSourceRect(obj, 1, 1, 127, 11);
		ascent(iStep in 0 .. countRemStep){
			let remStepRate = 58 / countRemStep;
			ObjSpriteList2D_SetDestRect(obj, 4 + iStep * remStepRate + 2, 8,
				4 + (iStep + 1) * remStepRate, 12);
			ObjSpriteList2D_AddVertex(obj);
		}

		lifeRateRender += 0.01;
		lifeRateRender = min(lifeRateRender, 1);
		lastRemStep = countRemStep;
	}
}
task BossTimer {
	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	let pathDigit = CSD ~ "IMG/SystemDigit.png";
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.81);
	
	let posinc = 0;
	let ypos = 8;
	let yielder = 0;
	let grow = 0;
	let count = 4;
	let maxt = 99.99;
	let scale = 1;
	let fade = 0;
	let bosstime = truncate(maxt);
	let cyoff = 0;
	
	let objScene = ID_INVALID;
	let x = (GetStgFrameWidth/2)-( (6 + (count-1) * (14*scale))/2 ) + GetStgFrameLeft;
	loop {
		x = (GetStgFrameWidth/2)-( (6+(count-1) * (14*scale))/2) + GetStgFrameLeft;
		if(GetPlayerY < 90) {
			fade = max(fade-10, 85);
		} else { fade = min(fade+10, 255); }
		
		
		objScene = GetEnemyBossSceneObjectID;
		ObjSpriteList2D_ClearVertexCount(obj);
		if(objScene != ID_INVALID && GetCommonData("OnEvent",false)==false){
			RenderTimer;
			SpellTime(objScene);
			if(ObjEnemyBossScene_GetInfo(objScene, INFO_IS_SPELL) == true ||
				ObjEnemyBossScene_GetInfo(objScene, INFO_IS_LAST_SPELL) == true ||
				ObjEnemyBossScene_GetInfo(objScene, INFO_IS_DURABLE_SPELL) == true){
					if(yielder>25){
						posinc = max(posinc-0.05, 0);
					}
					yielder++;
			} else {
					posinc = min(posinc-0.05, 0);
					yielder = 0;
			}
		} else { fade = 0; ypos = 8; }
		
		ObjRender_SetAlpha(obj, fade);
		if(GetAreaCommonData("Options","LifeBar",true)) { ObjRender_SetY(obj, ypos+13); }
		else { ObjRender_SetY(obj, ypos+20); }
		
		yield;
	}

	function RenderTimer {
		let timer = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMERF)/60;
		timer = min(max(0, timer), maxt);
		timer *= 100;
		
		let listNum = DigitToArray(timer, count);
		
		ascent(iObj in 0 .. count-2){
			let num = listNum[iObj];
			ObjRender_SetX(obj, x + (iObj-grow/20) * (14+grow));
			ObjSpriteList2D_SetSourceRect(obj, num * 16, 0, (num + 1) * 16, 32);
			ObjSpriteList2D_SetDestRect(obj, -grow, 0, 16, 32+grow);
			ObjSpriteList2D_AddVertex(obj);
		}
		
		ObjRender_SetX(obj, x + (count-2) * 14 - 2);
		ObjSpriteList2D_SetSourceRect(obj, 11 * 16, 0, (11 + 1) * 16, 32);
		ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 32);
		ObjSpriteList2D_AddVertex(obj);
		
		ascent(iObj in count-2 .. count){
			let num = listNum[iObj];
			ObjRender_SetX(obj, x + 15 + iObj * 10);
			ObjSpriteList2D_SetSourceRect(obj, num * 16, 0, (num + 1) * 16, 32);
			ObjSpriteList2D_SetDestRect(obj, 0, 5, 12, 32);
			ObjSpriteList2D_AddVertex(obj);
		}
		
		
		yield;
		
	}
	task SpellTime(SpellTimeSceneObjectID){
		let GetTimer = ObjEnemyBossScene_GetInfo(SpellTimeSceneObjectID, INFO_TIMER);
		if(bosstime != GetTimer && GetTimer <11){
			if(GetTimer > 4){ grow = 6; }
			if(GetTimer < 5 && GetTimer>-1){ grow = 8; }
			bosstime = GetTimer;
		}
		if(GetTimer<=10){
			ObjRender_SetColor(obj, 255, 100-grow*8, 100-grow*8);
		} else { ObjRender_SetColor(obj, 255, 255, 255); }
		grow = max(grow-1, 0);
	}
}
function DigitToArray(digit, 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;
}
function ToCommas(input) {
	let number = "";
	let num = length(IntToString(input));
	let digit = num%3;
		descent(i in 0..num) {
			number = number ~ ToString(IntToString(input)[num-i-1]);
			if(num>3) {
				if(i%3 == 0 && i != 0) {
					number = number ~ ",";
				}
			}
		}
	return number;
}
task BossName {
	let objtext = ObjText_Create;
	
	ObjText_SetFontSize(objtext,11);
	ObjText_SetFontColorTop(objtext,255,255,255);
	ObjText_SetFontColorBottom(objtext,0,100,0);
	ObjText_SetFontBorderType(objtext,BORDER_SHADOW);
	ObjText_SetFontBorderWidth(objtext,1);
	ObjText_SetFontBorderColor(objtext,0,0,0);
	ObjText_SetHorizontalAlignment(objtext,ALIGNMENT_LEFT);
	ObjText_SetMaxWidth(objtext,400);
	Obj_SetRenderPriorityI(objtext,65);
	
	let objEnemy = ID_INVALID;
	let objScene = GetEnemyBossSceneObjectID;
	let alpha = 0;
	
	while(!Obj_IsDeleted(objScene)) {
		if(length(GetEnemyBossObjectID)>0) { objEnemy = GetEnemyBossObjectID[0]; }
		ObjRender_SetAlpha(objtext,alpha);
		ObjText_SetText(objtext,Obj_GetValueD(objEnemy,"Boss Name",""));
		if(GetAreaCommonData("Options","LifeBar",true)) { ObjRender_SetPosition(objtext,5,4,0); }
		else { ObjRender_SetPosition(objtext,5,14,0); }
		if(alpha<255 && GetPlayerY>=115) { alpha+=255/30; }
		if(alpha>150 && GetPlayerY<115) { alpha-=255/30; }
		yield;
	}
	Obj_Delete(objtext);
}
task BossLife {
	let path = CSD ~ "IMG/lifebar.png";
	let countVertex = 64;
	
	loop(2) { yield; }
	let objStar = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(objStar,path);
	Obj_SetRenderPriority(objStar, 0.7);
	ObjSpriteList2D_SetSourceRect(objStar, 17, 2, 30, 14);

	let objOutline = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(objOutline, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(objOutline, countVertex);
	ObjRender_SetBlendType(objOutline, BLEND_ALPHA);
	Obj_SetRenderPriority(objOutline, 0.69);
	ObjPrim_SetTexture(objOutline, path);
	
	let objLife = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(objLife, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(objLife, countVertex);
	ObjRender_SetBlendType(objLife, BLEND_ALPHA);
	Obj_SetRenderPriority(objLife, 0.68);
	ObjPrim_SetTexture(objLife, path);
	
	let objLife2 = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(objLife2, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(objLife2, countVertex);
	ObjRender_SetBlendType(objLife2, BLEND_ALPHA);
	Obj_SetRenderPriority(objLife2, 0.68);
	ObjPrim_SetTexture(objLife2, path);
	
	let objEnemy = ID_INVALID;
	let objScene = GetEnemyBossSceneObjectID;
	let alpha = 0;
	let alpha2 = 0;
	let delaycount = 0;
	let LifeRatio = 0;
	let expand = 0;
	let angle = 0;
	let r1 = 58;
	let r2 = 62;
	
	CreateStepInd;
	
	ascent (iVert in 0..countVertex/2){
		let vertex = iVert * 2;
		ObjPrim_SetVertexUVT(objOutline, vertex+0, 0, 0);
		ObjPrim_SetVertexUVT(objOutline, vertex+1, 4, 16);	
		ObjPrim_SetVertexUVT(objLife, vertex+0, 7, 0);
		ObjPrim_SetVertexUVT(objLife, vertex+1, 10, 16);	
		ObjPrim_SetVertexUVT(objLife2, vertex+0, 7, 0);
		ObjPrim_SetVertexUVT(objLife2, vertex+1, 10, 16);
	}
	
	ObjRender_SetScaleXYZ(objOutline, -1.0, 1.0, 1.0);
	ObjRender_SetScaleXYZ(objLife, -1.0, 1.0, 1.0);
	ObjRender_SetScaleXYZ(objLife2, -1.0, 1.0, 1.0);
	
	while(!Obj_IsDeleted(objScene)) {
		if(length(GetEnemyBossObjectID)>0) { objEnemy = GetEnemyBossObjectID[0]; }
		
		if(GetCommonData("DurableSpell",false) || GetCommonData("Lifebar Delay",false)) {
			Obj_SetVisible(objOutline, false);
			Obj_SetVisible(objLife, false);
			Obj_SetVisible(objLife2, false);
		}
		else {
			Obj_SetVisible(objOutline, true);
			Obj_SetVisible(objLife, true);
			Obj_SetVisible(objLife2, true);
		}
		
		ObjRender_SetPosition(objOutline, ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), 0);
		ObjRender_SetPosition(objLife, ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), 0);
		ObjRender_SetPosition(objLife2, ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), 0);
		
		if(alpha2<255 && GetPlayerY>=115) { alpha2+=255/30; }
		if(alpha2>150 && GetPlayerY<115) { alpha2-=255/30; }
		ObjRender_SetAlpha(objStar,alpha2);
		
		ObjSpriteList2D_ClearVertexCount(objStar);
		ascent(i in 0..ObjEnemyBossScene_GetInfo(objScene,INFO_REMAIN_STEP_COUNT)) {
			ObjSpriteList2D_SetDestRect(objStar, 4+i*12, 16, 4+(i+1)*12, 28);
			ObjSpriteList2D_AddVertex(objStar);
		}
		
		ascent (i in 0..countVertex/2){
			let index = i * 2;
			angle = (360 / (countVertex/2 - 1) * i);
			ObjPrim_SetVertexPosition(objLife, index + 0 , r1*cos(angle-90), r1*sin(angle-90), 0);	
			ObjPrim_SetVertexPosition(objLife, index + 1 , (r1+1.5)*cos(angle-90), (r1+1.5)*sin(angle-90), 0);
			angle = (360 / (countVertex/2 - 1) * i);
			ObjPrim_SetVertexPosition(objLife2, index + 0 , r2*cos(angle-90), r2*sin(angle-90), 0);	
			ObjPrim_SetVertexPosition(objLife2, index + 1 , (r2+1.5)*cos(angle-90), (r2+1.5)*sin(angle-90), 0);
			angle = min(360*(LifeRatio), angle);
			ObjPrim_SetVertexPosition(objOutline, index + 0 , r2*cos(angle-90), r2*sin(angle-90), 0);	
			ObjPrim_SetVertexPosition(objOutline, index + 1 , r1*cos(angle-90), r1*sin(angle-90), 0);
		}
		if(expand<1 && delaycount>=45) { expand+=1/50; }
		if(delaycount>=100 && delaycount<120) { alpha+=255/20; }
		LifeRatio = ObjEnemyBossScene_GetInfo(objScene,INFO_ACTIVE_STEP_TOTAL_LIFE)/ObjEnemyBossScene_GetInfo(objScene,INFO_ACTIVE_STEP_TOTAL_MAX_LIFE)*expand;
		if(!GetCommonData("Lifebar Delay",false)) { delaycount++; }
		
		if(ObjEnemyBossScene_GetInfo(objScene,INFO_ACTIVE_STEP_TOTAL_LIFE)<=0) {
			expand = 0;
			delaycount = 0;
			alpha = 0;
			loop(2) { yield; }
			CreateStepInd;
		}
		
		
		yield;
	}
	Obj_Delete(objOutline);
	Obj_Delete(objLife);
	Obj_Delete(objLife2);
	
	task CreateStepInd {
		let listLifeDiv = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_LIFE_RATE_LIST);
		ascent(i in 0 .. length(listLifeDiv)-1){
			let rate = listLifeDiv[i];
			let angle = 360*(rate);
			Separator(angle, rate);
		}
		task Separator(angle, rate){
			let obj = ObjPrim_Create(OBJ_SPRITE_2D);
			ObjRender_SetBlendType(obj, BLEND_ALPHA);
			Obj_SetRenderPriority(obj, 0.69);
			ObjPrim_SetTexture(obj, path);
			ObjSprite2D_SetSourceRect(obj, 10, 0, 15, 8);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetScaleXYZ(obj, 1.3, 1.3, 1);
			ObjRender_SetPosition(obj, ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), 0);
			ObjRender_SetAngleZ(obj, angle);
			yield;
			let life = ObjEnemyBossScene_GetInfo(objScene,INFO_ACTIVE_STEP_TOTAL_LIFE)/ObjEnemyBossScene_GetInfo(objScene,INFO_ACTIVE_STEP_TOTAL_MAX_LIFE);
			while(1-rate<life-0.000001){
				life = ObjEnemyBossScene_GetInfo(objScene,INFO_ACTIVE_STEP_TOTAL_LIFE)/ObjEnemyBossScene_GetInfo(objScene,INFO_ACTIVE_STEP_TOTAL_MAX_LIFE);
				ObjRender_SetPosition(obj, ObjRender_GetX(objEnemy)+(r1-1)*cos(angle-90), ObjRender_GetY(objEnemy)+(r1-1)*sin(angle-90), 0);
				ObjRender_SetAlpha(obj, alpha);
				if(GetCommonData("DurableSpell",false)) { Obj_SetVisible(obj, false); } else { Obj_SetVisible(obj, true); }
				yield;
			}
			Obj_Delete(obj);
		}
	}
}
task BossMagicCircle {
	loop(2) { yield; }
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, CSD ~ "IMG/MC.png");
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj, 37);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
	ObjSprite2D_SetDestCenter(obj);
	
	let objEnemy = ID_INVALID;
	let objScene = GetEnemyBossSceneObjectID;
	let t = 0;
	let scale = 0.7;
	let spin = 0;
	let alpha = 0;
	
	while(!Obj_IsDeleted(objScene)) {
		if(length(GetEnemyBossObjectID)>0) {
			objEnemy = GetEnemyBossObjectID[0];
			ObjRender_SetPosition(obj, ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), 0);
		}
		ObjRender_SetAngleXYZ(obj, 0, 0, spin);
		ObjRender_SetScaleXYZ(obj, scale, scale, 1);
		ObjRender_SetColor(obj, 255*alpha, 255*alpha, 255*alpha);
		scale+=0.0065*sin(3*t);
		spin+=5;
		t++;
		if(alpha<0.5) { alpha+=0.7/30; }
		yield;
	}
	Obj_Delete(obj);
	
}
task CurrentFps {
	let objText = ObjText_Create;
	ObjText_SetFontSize(objText, 14);
	ObjText_SetFontType(objText, "RussellSquare");
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 160, 160, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText, 0, 0, 0);
	ObjText_SetFontBorderWidth(objText, 2);
	ObjText_SetHorizontalAlignment(objText, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(objText, GetScreenWidth - 8);
	Obj_SetRenderPriority(objText, 1);
	ObjRender_SetX(objText, 0);
	ObjRender_SetY(objText, GetScreenHeight - 20);

	loop {
		let fps = GetCurrentFps;
		let text = vtos("1.2f", fps) ~ "fps";
		ObjText_SetText(objText, text);
		yield;
	}
}
task ReplayFps {
	let objText = ObjText_Create;
	ObjText_SetFontSize(objText, 22);
	ObjText_SetFontType(objText, "RussellSquare");
	ObjText_SetFontColorTop(objText,255,255,255);
	ObjText_SetFontColorBottom(objText,150,150,150);
	ObjText_SetFontBorderType(objText,BORDER_SHADOW);
	ObjText_SetFontBorderWidth(objText,1);
	ObjText_SetFontBorderColor(objText,0,0,0);
	ObjText_SetHorizontalAlignment(objText, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(objText, GetScreenWidth - 8);
	Obj_SetRenderPriorityI(objText, 100);
	ObjRender_SetX(objText, -220);
	ObjRender_SetY(objText, GetScreenHeight - 40);
	
	loop {
		let fps = GetReplayFps;
		let text = vtos("02d", fps);
		ObjText_SetText(objText, text);
		yield;
	}
}
task DebugText(text) {
	let objText = ObjText_Create;
	
	ObjText_SetFontSize(objText,12);
	ObjText_SetHorizontalAlignment(objText, ALIGNMENT_LEFT);
	ObjText_SetMaxWidth(objText, 300);
	Obj_SetRenderPriorityI(objText, 60);
	ObjRender_SetPosition(objText, 50, GetStgFrameHeight-30, 0);
	
	loop {
		ObjText_SetText(objText,text);
		yield;
	}
}