task BossLife{
	let path = GetCurrentScriptDirectory ~ "img/lifebar.png";
	let countVertex = 80;
	let objScene = ID_INVALID;
	
	let objStar = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(objStar, GetCurrentScriptDirectory ~ "img/frame2.png");
	Obj_SetRenderPriority(objStar, 0.7);
	ObjSpriteList2D_SetSourceRect(objStar, 144, 80, 156, 92);

	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);
	
	ascent (iVert in 0..countVertex/2){
		let vertex = iVert * 2;
		ObjPrim_SetVertexUVT(objOutline, vertex+0, 0, 0);
		ObjPrim_SetVertexUVT(objOutline, vertex+1, 10, 32);	
		ObjPrim_SetVertexUVT(objLife, vertex+0, 10, 0);
		ObjPrim_SetVertexUVT(objLife, vertex+1, 19, 32);			
	}
	
	
	let mx = 0;
	let my = 0;
	let fade = 255;
	let maxRadius = 57;
	
	let lastRemStep = -1;
	let countRemStep = ObjEnemyBossScene_GetInfo(objScene, INFO_REMAIN_STEP_COUNT);
	let lifeRateRender = 0;
	let outlineRender = 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);
	
	let newStep = 1;
	CreateStepInd;
	
	
	ObjRender_SetScaleXYZ(objOutline, -1, 1, 1);
	ObjRender_SetScaleXYZ(objLife, -1, 1, 1);
	ObjRender_SetScaleXYZ(objLife2, -1, 1, 1);
	
	ObjRender_SetPosition(objStar, 0, 12, 0);

	
	while(ObjEnemyBossScene_GetInfo(objScene, INFO_IS_DURABLE_SPELL) == false){
		ObjSpriteList2D_ClearVertexCount(objStar);
		
		
		if(outlineRender<1){
			ObjRender_SetAlpha(objStar, min(255, 255*(outlineRender*3)-510));
		}else{
			if(GetPlayerY < max(96, 26+(truncate(countRemStep/12)*12))){
				fade = max(fade-10, 85);
			}else{fade = min(fade+10, 255);}
			ObjRender_SetAlpha(objStar, fade);
		}
		
		objScene = GetEnemyBossSceneObjectID;
		if(objScene != ID_INVALID){
			let Boss = GetEnemyBossObjectID;
			Boss = Boss ~ [objOutline];
			mx = ObjRender_GetX(Boss[0]);
			my = ObjRender_GetY(Boss[0]);
		}else{
			mx = -400;
			my = -400;
			outlineRender = 0;
			lifeRateRender = 0;
		}
		RefreshVertex(objOutline);
		
		if(GetCommonData("ForceLifebar", 0) != 0){
			outlineRender = 0;
			lifeRateRender = 0;
		}
		
		
		lastRemStep = countRemStep;
		
		yield;
}
	

	task RefreshVertex(objid){
		
		countRemStep = ObjEnemyBossScene_GetInfo(objScene, INFO_REMAIN_STEP_COUNT);
		if(lastRemStep != countRemStep){
			newStep = 1;
			CreateStepInd;
			lifeRateRender = 0;
		}
		ascent(iStep in 0 .. countRemStep){
			let y = truncate((iStep)/12)*12;
			let i = iStep-(12*(y/12));
			ObjSpriteList2D_SetDestRect(objStar, 4 + i * 12, 4+y,
				4 + (i + 1) * 12, 16+y);
			ObjSpriteList2D_AddVertex(objStar);

		}
	
		lifeTotalMax = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_TOTAL_MAX_LIFE);
		lifeTotal = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_TOTAL_LIFE);
		lifeRate = min(lifeTotal / lifeTotalMax, lifeRateRender);
		
		
		
		ascent(iVert in 0..countVertex/2){
			let indexVert = iVert * 2;
			let angle = (360 / (countVertex/2 - 1) * iVert);
			angle = min(360*(outlineRender), angle);
			let x = maxRadius*cos(angle-90);
			let y = maxRadius*sin(angle-90);
			ObjPrim_SetVertexPosition(objLife, indexVert + 0 , x, y, 0);
			x = (maxRadius*1.1)*cos(angle-90);
			y = (maxRadius*1.1)*sin(angle-90);
			ObjPrim_SetVertexPosition(objLife, indexVert + 1 , x, y, 0);
			
			/*x = (maxRadius*1.065)*cos(angle-90);
			y = (maxRadius*1.065)*sin(angle-90);
			ObjPrim_SetVertexPosition(objLife2, indexVert + 0 , x, y, 0);
			x = (maxRadius*1.09)*cos(angle-90);
			y = (maxRadius*1.09)*sin(angle-90);
			ObjPrim_SetVertexPosition(objLife2, indexVert + 1 , x, y, 0);*/
			
			angle = min(360*(lifeRate), angle);
			x = (maxRadius)*cos(angle-90);
			y = (maxRadius)*sin(angle-90);
			ObjPrim_SetVertexPosition(objOutline, indexVert + 0 , x, y, 0);			
			x = (maxRadius*1.1)*cos(angle-90);
			y = (maxRadius*1.1)*sin(angle-90);
			ObjPrim_SetVertexPosition(objOutline, indexVert + 1 , x, y, 0);
		}
		ObjRender_SetPosition(objOutline, mx, my, 0);
		ObjRender_SetPosition(objLife, mx, my, 0);
		ObjRender_SetPosition(objLife2, mx, my, 0);
		
		lifeRateRender = min(1, lifeRateRender+0.02);
		outlineRender = min(1, outlineRender+0.016);
		
	}
	task CreateStepInd{
		let listLifeDiv = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_LIFE_RATE_LIST);
		ascent(iDiv in 0 .. length(listLifeDiv)){
			let rate = listLifeDiv[iDiv];
			let angle = 360*(rate);
			if( angle != 360){CreateKnub(angle, rate);}
		}
		task CreateKnub(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, 23, 0, 31, 11);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetScaleXYZ(obj, 0.5, 0.8, 0.8);
			ObjRender_SetPosition(obj, mx, my, 0);
			ObjRender_SetAngleZ(obj, angle);
			yield;
			newStep = 0;
			let life = (lifeTotal / lifeTotalMax);
			while(newStep == 0 && 1-rate<life-0.000001){
				let x = mx+(maxRadius*1.05)*cos(angle-90);
				let y = my+(maxRadius*1.05)*sin(angle-90);
				life = (lifeTotal / lifeTotalMax);
				ObjRender_SetPosition(obj, x, y, 0);
				ObjRender_SetAlpha(obj, min(255, 255*(outlineRender*3)-510));
				yield;
			}
			Obj_Delete(obj);
		}
	}

}