
script_enemy_main {
	let imglifebar = GetCurrentScriptDirectory~"lifebar_thWW.png";
	@Initialize {
		 LoadGraphic(imglifebar); 
	}
	let f = true;
	@MainLoop {  if(f){
		SetX(GetX); SetY(GetY); CreateLifebar(2);
	f=false;} yield; }
	@Finalize { DeleteGraphic(imglifebar);
	}
task CreateLifebar(type) {
	let initlife = GetLife; yield;
	let sides=80;
	let totalradius=64;
	let repeat=2;
	let Z=-90;
	let IN=0;
	let OUT=8;
	task lifeseparation {
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imglifebar);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexUV(obj, 0, 16, 0);
		ObjEffect_SetVertexUV(obj, 1, 24, 0);
		ObjEffect_SetVertexUV(obj, 2, 24, 11);
		ObjEffect_SetVertexUV(obj, 3, 16, 11);
		ObjEffect_SetVertexXY(obj, 0, -4, -11/2);
		ObjEffect_SetVertexXY(obj, 1, 4, -11/2);
		ObjEffect_SetVertexXY(obj, 2, 4, 11/2);
		ObjEffect_SetVertexXY(obj, 3, -4, 11/2);
		let totalradius_ = totalradius+OUT*3/4;
		ObjEffect_SetScale(obj, 1, 5/4);
		loop { ObjEffect_SetAngle(obj, 0, 0, 90+360*0.15); Obj_SetPosition(obj, GetX+totalradius_*cos(-90-360*0.15), GetY+totalradius_*sin(-90-360*0.15)); yield; }
	}
	let objL = Obj_Create(OBJ_EFFECT);
	let objB = Obj_Create(OBJ_EFFECT);
	if(type == 0 || type == 1) { lifeseparation; }
	ascent(n in 0..2) {
		let d=0;
		let objid = [objB, objL][n];
		Obj_SetX(objid,GetX);
		Obj_SetY(objid,GetY);
		ObjEffect_SetScale(objid,1,1);
		ObjEffect_SetPrimitiveType(objid,PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_SetRenderState(objid,ALPHA);
		ObjEffect_SetTexture(objid,imglifebar);
		ObjEffect_CreateVertex(objid,2+sides*2);
		ascent(i in 0..sides+1){
			ObjEffect_SetVertexUV(objid,i*2,8+8*n,d*repeat/sides);
			ObjEffect_SetVertexUV(objid,i*2+1,8*n,d*repeat/sides);
			d+=-256;
		}
	}
	if(type!=0 && type!=1 && type!=2){type=2}
	let expand = [0, 1, 0, 0][type];
	let this = [0.85, 0.15, 1][type];
	let left = [0.15, 0, 0][type];
	loop {
		Obj_SetPosition(objL, GetX, GetY);
		Obj_SetPosition(objB, GetX, GetY);
		let ratio = GetLife/initlife*this+left; if(expand<1){expand+=1/15;}else if(expand>1){expand=1}
		ascent(i in 0..sides+1){
			let radiusINX=(totalradius+IN)*cos(i*360*ratio*expand/sides+Z);
			let radiusINY=(totalradius+IN)*sin(i*360*ratio*expand/sides+Z);
			let radiusOUTX=(totalradius+OUT)*cos(i*360*ratio*expand/sides+Z);
			let radiusOUTY=(totalradius+OUT)*sin(i*360*ratio*expand/sides+Z);
			ObjEffect_SetVertexXY(objL,i*2,-radiusINX,radiusINY);
			ObjEffect_SetVertexXY(objL,i*2+1,-radiusOUTX,radiusOUTY);
			let radiusINX=(totalradius+IN)*cos(i*360*expand/sides+Z);
			let radiusINY=(totalradius+IN)*sin(i*360*expand/sides+Z);
			let radiusOUTX=(totalradius+OUT)*cos(i*360*expand/sides+Z);
			let radiusOUTY=(totalradius+OUT)*sin(i*360*expand/sides+Z);
			ObjEffect_SetVertexXY(objB,i*2,-radiusINX,radiusINY);
			ObjEffect_SetVertexXY(objB,i*2+1,-radiusOUTX,radiusOUTY);
		}
		yield;
	}
}


}