#ScriptVersion[2]

script_enemy_main {

	//	敵撃墜（時間切れ）したときに出現して、「負けたー」っぽい演出をします

	let Current=GetCurrentScriptDirectory;

	let IMG=Current~"Dot\dot_aya.png";
	let CHAT_IMG = Current~"IMG\CHAT.png";
	let Chat_Back_IMG = Current ~ "IMG\front00.png";
	let Leaf_IMG = Current ~ "..\img\leaf_a.png";
	let Player_Face_IMG = "";
	let Enemy_Face_IMG = "";
	let Down_SE = Current ~ "..\SE\enemy_down00.wav";

	@Initialize {
		SetX(GetCommonData("X"));
		SetY(GetCommonData("Y"));
		Spell_Score = GetCommonData("SPELL_SCORE");
		LoadGraphic(CHAT_IMG);
		LoadGraphic(Chat_Back_IMG);
		LoadGraphic(IMG);
		LoadGraphic(Leaf_IMG);
		LoadSE(Down_SE);
		SetLife(10);
		LoadUserShotData(Current~"DOT\shot_All.pad");
		SetMovePosition03(GetCenterX + 25,GetClipMinY+75,20,10);
		Draw_Aya(IMG,7,5,5,0);
		TMain;
	}

	@MainLoop {
		yield;
	}

	@DrawLoop {
		DrawGraphic(Draw_X,Draw_Y);
	}

	@Finalize {
	}

	task TMain {
		yield;
		PlaySE(Down_SE);
		Set_Spell_Name_End(Current ~ "IMG\Spell_Name.png", 0, 0, 410, 24);
		Draw_Spell_Value_End(ASCII_IMG, 0, 0);
		while(GetSpeedX){ yield; }
		PlaySE(Down_SE);
		loop(45){ Create_Object_Maple_Diffusion(Draw_X, Draw_Y); }
		SetX(-100);
		SetY(-100);
		Face_Work;
		Chat_Work(CHAT_IMG,22, 24);
		VanishEnemy;
	}

	task Face_Work{
		Cange_Face_Enemy(Enemy_Face_IMG, 0, 0, 0, 0);
		Cange_Face_Player(Player_Face_IMG, 0, 0, 0, 0);
	}



	task Create_Object_Maple_Diffusion(let set_x, let set_y){
		let set_angle = rand(0, 360);
		let X;
		let Y;
		let scale;
		let angle=0;
		let add_angle=rand(-10, 10);
		let set_speed;
		X = set_x+rand(0,15)*cos(set_angle);
		Y = set_y+rand(0,15)*sin(set_angle);
		set_speed=rand(3,4);
		scale=rand(0.5,1.5);
		let wh=[0, 0, 75, 70];
		let xy=Cal_XY(wh[0],wh[1],wh[2],wh[3]);
		let uv=Cal_UV(wh[0],wh[1],wh[2],wh[3]);
		let obj;
		obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, Leaf_IMG);
		ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj,ALPHA);
		ObjEffect_CreateVertex(obj,4);
		ObjEffect_SetLayer(obj,2);
		ascent(i in 0..4){
			ObjEffect_SetVertexXY(obj,i,xy[i],xy[i+4]);
			ObjEffect_SetVertexUV(obj,i,uv[i],uv[i+4]);
			ObjEffect_SetVertexColor(obj,i,255,255,255,255)
		}
		Obj_SetPosition(obj,X,Y);
		ObjEffect_SetScale(obj,scale,scale);
		ObjEffect_SetAngle(obj,0,0,set_angle);
		Obj_SetAngle(obj,atan2(set_y-Obj_GetY(obj),set_x-Obj_GetX(obj))+180);
		Obj_SetSpeed(obj,set_speed);
		while(scale>0){
			ObjEffect_SetScale(obj,scale,scale);
			ObjEffect_SetAngle(obj,0,0,set_angle+angle);
			angle+=add_angle;
			yield;
			scale-=0.003;
		}
		Obj_Delete(obj);
	}

	#include_function".\INCLUDE\BOSS_INI.dms";
	#include_function".\DOT\Boss_Graphic.pad";

}