let lifebar = CSD ~ "system/hp.png";

let maxLife;

LoadGraphic(lifebar);

// custom life bar for groove

task hpBar{
	let lifebarSize = 0;
	let lifebarReady = 0;
        let enyLife;
	let xhppx;
	let xnhpx;	
        maxLife = GetEnemyLife;

	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj,lifebar);
	Obj_SetPosition(obj,40,30);
	ObjEffect_SetLayer(obj,7);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_CreateVertex(obj, 6);

	while(! Obj_BeDeleted(obj)) {
		
		// requires to be inside loop for update
          	ObjEffect_SetVertexXY(obj, 0, 0, -2);
          	ObjEffect_SetVertexUV(obj, 0, 0, 0);
          	ObjEffect_SetVertexXY(obj, 1, lifebarSize, -2);
          	ObjEffect_SetVertexUV(obj, 1, 128, 0);
          	ObjEffect_SetVertexXY(obj, 2, 0, 2);
          	ObjEffect_SetVertexUV(obj, 2, 0, 32);
          	ObjEffect_SetVertexXY(obj, 3, lifebarSize, 2);
          	ObjEffect_SetVertexUV(obj, 3, 128, 32);

		if(lifebarSize<300 && lifebarReady == 0){ lifebarSize+=5; }	// prepares the lifebar to 300
		if(lifebarSize==300){ lifebarReady = 1;}			// switch
		if(lifebarReady==1){ 						// start animating it
		
			enyLife = GetEnemyLife;
			xhppx = enyLife/maxLife;
			xnhpx = floor(300*xhppx);
			lifebarSize = xnhpx;
		}
		yield;
	}
 
}