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(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=cenX;let posy=cenY;
	
	let base = Obj_Create(OBJ_EFFECT); //背景
	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]);
	
	let tuning=GetCommonData("Memory_ConfigData");
	if(!tuning[1])
	{
		let r =  [0, 12, 50, 88, 122, 152, 178, 200];
		let r2 = [0, 80, 100, 120, 140, 160, 180, 200];
		let cat= 18 ;//分割数
		let size=7;//画面歪曲の広さ
		let obj = [];
		ascent(i in 0..size){ 
			obj = obj ~ [ [] ] ; //二重配列を作る
			ascent(j in 0..cat){
				let sx=-leng_h/2+posx;
				let sy=-leng_v/2+posy;
				let a = j*(360/cat);
				let t = Obj_Create(OBJ_EFFECT);
				ObjEffect_SetTexture(t,tex);
				ObjEffect_SetPrimitiveType(t,PRIMITIVE_TRIANGLESTRIP);
				ObjEffect_CreateVertex(t,4);
				ObjEffect_SetLayer(t,0);
		
				ObjEffect_SetVertexXY(t, 0, sx+cos(a)*r[i]            , sy+sin(a)*r[i]);
				ObjEffect_SetVertexXY(t, 1, sx+cos(a+(360/cat))*r[i]  , sy+sin(a+(360/cat))*r[i]);
				ObjEffect_SetVertexXY(t, 2, sx+cos(a)*r[i+1]          , sy+sin(a)*r[i+1]);
				ObjEffect_SetVertexXY(t, 3, sx+cos(a+(360/cat))*r[i+1], sy+sin(a+(360/cat))*r[i+1]);
				
				obj[i] = obj[i] ~ [t];
			}
		}
		let tx;
		let ty;
		while(1)
		{
			ascent(i in 0..size)
			{
				ascent(j in 0..cat){
				let angle1=j*(360/cat);
				let angle2=(j+1)*(360/cat);
				tx = trunc(GetEnemyX)+leng_h/2-posx;
				ty = trunc(GetEnemyY)+leng_v/2-posy;
				Obj_SetPosition(obj[i][j], tx, ty);
		
				ObjEffect_SetVertexUV(obj[i][j], 0, tx+cos(angle1)*r2[i]  , ty+sin(angle1)*r2[i]);
				ObjEffect_SetVertexUV(obj[i][j], 1, tx+cos(angle2)*r2[i]  , ty+sin(angle2)*r2[i]);
				ObjEffect_SetVertexUV(obj[i][j], 2, tx+cos(angle1)*r2[i+1], ty+sin(angle1)*r2[i+1]);
				ObjEffect_SetVertexUV(obj[i][j], 3, tx+cos(angle2)*r2[i+1], ty+sin(angle2)*r2[i+1]);
				
				};
			}
			yield;
		}
	}
}



task EnemyBossPositionLine
{
	let rect=[0,96,448,104];
	let obj=SetEffectObject(tex_system,3);
	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;
	}
}
