
script_enemy_main {
#include_function".\RAINS_Client_Enemy.dnh"
#include_function".\libs_enemy.dnh"

let Csd = GetCurrentScriptDirectory;
let GaugeTex = Csd ~ "LifeGauge.png";

	@Initialize {
		SetX(cx);
		SetY(cy - 120);
		SetLife(3000);
		LoadGraphic("script\img\ExRumia.png");
		LoadGraphic(GaugeTex);
		SetDamageRate(100,100);
		StartMainTask;
	}

	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);
		
		yield;
	}

	@DrawLoop {
	
		SetTexture("script\img\ExRumia.png");
		SetGraphicRect(0, 0, 64, 64);
		DrawGraphic(GetX, GetY);
	}

	@Finalize {
		RAINS_SetItem(GetX, GetY, 1, 4, 0);
		DeleteGraphic("script\img\ExRumia.png");
		DeleteGraphic(GaugeTex);
	}

	task StartMainTask{
		yield;
		AttackAction;
		LifeGauge(3000);
	}
	
	task AttackAction {
		loop{
			loop(15){yield;}
			RAINS_SetItem(GetX, GetY, 0, 2, 150);
			let AngleBase = rand(0, 360);
			ascent(n in 0..18){
				CreateShot01(GetX,GetY,4,AngleBase + (n * 20),RED21,1);
			}
		}
	}
	
	//動きのある筒状エフェクトのサンプル
	task LifeGauge(let MaxLife){
		if(MaxLife <= 0){return;}
		let num = 36;
		let RefleshTimer = 7200;
		
		let obj = NULL;
		let obj1 = NULL;
		let obj2 = NULL;
		
		Create;
		
		let count = 0;
		loop{
			let eX = GetX;
			let eY = GetY;
			
			SetPolygon_Pipe(obj, num, 100, 36, count * 1.3, -count, 360);
			ObjEffect_SetAngle(obj, 0, 0, count);
			Obj_SetPosition(obj, eX, eY);
			
			let percent = GetLife / MaxLife;
			SetPolygon_Pipe(obj1, num, 100, 12, count * 1.3, -count, 360 * percent);
			ObjEffect_SetAngle(obj1, 0, 0, count);
			Obj_SetPosition(obj1, eX, eY);
			
			SetPolygon_Pipe(obj2, num, 100, 12, count * 1.3, -count, 360);
			ObjEffect_SetAngle(obj2, 0, 0, count);
			Obj_SetPosition(obj2, eX, eY);
			
			count += 0.5;
			yield;
			RefleshTimer--;
			if(RefleshTimer <= 0){
				Obj_Delete(obj);
				Obj_Delete(obj1);
				Obj_Delete(obj2);
				RefleshTimer = 7200;
				Create;
			}
		}
		Obj_Delete(obj);
		Obj_Delete(obj1);
		Obj_Delete(obj2);
		
		//エフェクトオブジェクト生成／再生成サブルーチン
		sub Create{
			//下に敷く減算エフェクト
			//明るい背景下での加算エフェクトの飽和（真っ白になり、見えなくなる）を防ぐ
			obj  = MakeEffect(num);
			SetUVmapping01_Ring(obj, num, 0, 48, 256, 24);
			ObjEffect_SetRenderState(obj,SUBTRACT);
			ascent(n in 0..4){ObjEffect_SetVertexColor(obj, n, 150, 255, 255, 255);}
			
			//体力ゲージ本体
			obj1  = MakeEffect(num);
			SetUVmapping01_Ring(obj1, num, 0, 24, 256, 24);
			ObjEffect_SetRenderState(obj1,ADD);
			
			//体力ゲージ枠
			obj2  = MakeEffect(num);
			SetUVmapping01_Ring(obj2, num, 0, 0, 256, 24);
			ObjEffect_SetRenderState(obj2,ADD);
		}
		
		function MakeEffect(let num){
			let objID  = CreateRingEffect(num);
			ObjEffect_SetTexture(objID, GaugeTex);
			ObjEffect_SetLayer(objID,3);
			return objID;
		}
	}
}