function EnemyBossDrawLoop
{
	SetTexture(tex_system);
	Draw_EnemyLifeCount;
	if(GetCommonDataDefault("SpellFlg",false)){Draw_EnemySpellCount;}
}

function Draw_EnemyLifeCount
{
	let rect=[];
	
	let leng=16;
	let pos_x=310;
	let pos_y=58+leng/2;
	let life=GetEnemyLife;
	let lifemax=GetCommonDataDefault("BossLifeMax",0);
	if(lifemax>1)
	{
		if(OnEnemySpell){life*=5;lifemax*=5;}
		SetGraphicScale(1,1);
		
		local
		{
			rect=[448,0,496,16];
			SetGraphicScale(0.75,0.75);
			SetGraphicRect(rect[0],rect[1],rect[2],rect[3]);
			DrawGraphic(pos_x-32,pos_y);
		}
		SetGraphicScale(1,1);
		
		DrawCount(life,pos_x,pos_y);
		local
		{
			rect=[256+160,16];
			SetGraphicRect(rect[0],rect[1],rect[0]+leng,rect[1]+leng);
			DrawGraphic(pos_x+leng*3,pos_y);
		}
		DrawCount(lifemax,pos_x+leng*4,pos_y);
	}
	
	function DrawCount(let num,let pos_x,let pos_y)
	{
		let lp=floor(log10(num))+1;
		let i=lp;
		
		loop(lp)
		{
			let rc=(num%(10^i)-num%(10^(i-1)))/(10^(i-1));
			
			rect=[256+rc*leng,16];
			SetGraphicRect(rect[0],rect[1],rect[0]+leng,rect[1]+leng);
			DrawGraphic(pos_x+(lp-i)*(leng/1.8),pos_y);
			i--;
		}
		if(num==0)
		{
			rect=[256,16];
			SetGraphicRect(rect[0],rect[1],rect[0]+leng,rect[1]+leng);
			DrawGraphic(pos_x,pos_y);
		}
	}
}

function Draw_EnemySpellCount
{
	let rect=[];
	
	let leng=16;
	let pos_x=330;
	let pos_y=68+leng/2;
	let get=spell_getcount;
	let total=spell_totalcount;
	SetGraphicScale(1,1);
	
	local
	{
		rect=[448,16,496,32];
		SetGraphicScale(0.75,0.75);
		SetGraphicRect(rect[0],rect[1],rect[2],rect[3]);
		DrawGraphic(pos_x-32,pos_y);
	}
	SetGraphicScale(1,1);
	
	DrawCount(get,pos_x,pos_y);
	local
	{
		rect=[256+160,16];
		SetGraphicRect(rect[0],rect[1],rect[0]+leng,rect[1]+leng);
		DrawGraphic(pos_x+leng*3,pos_y);
	}
	DrawCount(total,pos_x+leng*4,pos_y);
	
	function DrawCount(let num,let pos_x,let pos_y)
	{
		let lp=floor(log10(num))+1;
		let i=lp;
		
		loop(lp)
		{
			let rc=(num%(10^i)-num%(10^(i-1)))/(10^(i-1));
			
			rect=[256+rc*leng,16];
			SetGraphicRect(rect[0],rect[1],rect[0]+leng,rect[1]+leng);
			DrawGraphic(pos_x+(lp-i)*(leng/1.8),pos_y);
			i--;
		}
		if(num==0)
		{
			rect=[256,16];
			SetGraphicRect(rect[0],rect[1],rect[0]+leng,rect[1]+leng);
			DrawGraphic(pos_x,pos_y);
		}
	}	
}



task Draw_SpellBackGround(let tex,let left,let up,let right,let down)
{
	let texture_rect=[left,up,right,down];
	let leng_h=texture_rect[2]-texture_rect[0];
	let leng_v=texture_rect[3]-texture_rect[1];
	let posx=boss_bgposx;let posy=boss_bgposy;
	
	let base = Obj_Create(OBJ_EFFECT); //”wŒi
	ObjEffect_SetTexture(base,tex);
	ObjEffect_SetPrimitiveType(base,PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_CreateVertex(base,4);
	ObjEffect_SetLayer(base,0);
	Obj_SetPosition(base,posx,posy);

	ObjEffect_SetVertexXY(base,0,-leng_h/2,-leng_v/2);
	ObjEffect_SetVertexXY(base,1, leng_h/2,-leng_v/2);
	ObjEffect_SetVertexXY(base,2,-leng_h/2, leng_v/2);
	ObjEffect_SetVertexXY(base,3, leng_h/2, leng_v/2);
	ObjEffect_SetVertexUV(base,0,texture_rect[0],texture_rect[1]);
	ObjEffect_SetVertexUV(base,1,texture_rect[2],texture_rect[1]);
	ObjEffect_SetVertexUV(base,2,texture_rect[0],texture_rect[3]);
	ObjEffect_SetVertexUV(base,3,texture_rect[2],texture_rect[3]);
	Effect;
	
	while(!Obj_BeDeleted(base))
	{
		let alpha=255;
		let color_r=255;
		let color_g=255;
		let color_b=255;
		if(IsBGStopping)
		{
			color_g=32;
			color_b=32;
		}
		ascent(a in 0..4)
		{
			ObjEffect_SetVertexColor(base,a,alpha,color_r,color_g,color_b);
		}
		yield;
	}
	
	task Effect
	{
		let tuning=GetCommonData("Memory_ConfigData");
		if(!tuning[1])
		{
			let scp=0.01;
			let limit=15;
			loop(30)
			{
				SpellBGEffect(0,40,scp,limit);
				scp+=0.005;
				limit+=1;
				yield;
			}
			/*
			loop
			{
				wait(120);
				let scp=0.01;
				let limit=240;
				local
				{
					SpellBGEffect(1,128,scp,limit);
					wait(2);
				}
			}*/
		}
	}
	
	task SpellBGEffect(let mode,let base,let scp,let limit)
	{
		let obj=SetEffectObject(tex,1);
		SetEffectObjectRect(obj,texture_rect[0],texture_rect[1],texture_rect[2],texture_rect[3]);
		if(mode==0){ObjEffect_SetRenderState(obj,ADD);}
		else{ObjEffect_SetRenderState(obj,ALPHA);}
		
		let scale=1.0;
		let alpha=base;
		while(!Obj_BeDeleted(obj))
		{
			let color=255;
			ascent(a in 0..4)
			{
				ObjEffect_SetVertexColor(obj,a,alpha,color,color,color);
			}
			Obj_SetPosition(obj,posx,posy);
			ObjEffect_SetScale(obj,scale,scale);
			
			alpha-=base/limit;
			scale+=scp;
			if(alpha<=0){Obj_Delete(obj);}
			
			yield;
		}
	}
}



task EnemyBossPositionLine
{
	let rect=[0,96,448,104];
	let obj=SetEffectObject(tex_system,2);
	SetEffectObjectRect(obj,rect[0],rect[1],rect[2],rect[3]);
	ObjEffect_SetRenderState(obj,ADD);
	ObjEffect_SetAngle(obj,0,0,90);
	let alpha=64;
	let count=0;
	while(!Obj_BeDeleted(obj))
	{
		let color=255;
		ascent(a in 0..4)
		{
			ObjEffect_SetVertexColor(obj,a,alpha,color,color,color);
		}
		Obj_SetPosition(obj,GetEnemyX,cenY);
		count++;
		yield;
	}
}
