//============================================
//XNvgpCu REMY
//CxgXNvgCu
//============================================


let left_chara_list = [];
let right_chara_list = [];
let default_EventCharaLeftX = GetClipMinX() + 60;
let default_EventCharaRightX = GetClipMaxX() - 60;


//CxgLN^[\
//dir_horizontal:\@_DIR_LEFT, _DIR_RIGHT̂ꂩ
//texture:摜t@C
//rect:摜؂`B[X,Y,EX,EY]̓AS̔z
//off_set:摜̒S_ItZbgB̒lS_B[x,y]̒Q̔zB
function REMY_Event_SetCharacter(let dir_horizontal, let texture, let rect, let off_set)
{
	if(dir_horizontal != _DIR_LEFT && dir_horizontal != _DIR_RIGHT)
	{
		RaiseError(" 1ɂ_DIR_LEFT_DIR_RIGHT\nw肵Ă","ERROR");
	}

	let obj = REMY_CreateEffectObject(texture, 4, 7);
	ObjEffect_SetRenderState(obj, ALPHA);
	REMY_Effect_SetVertexSquare(obj, rect, off_set[0], off_set[1], 0, 255, 255, 255);

	Obj_SetPosition(obj, [GetClipMinX(), GetClipMaxX()][dir_horizontal == _DIR_RIGHT], GetClipMaxY() - (rect[3]-rect[1])/2);
	REMY_Event_LocateCharacter(obj, [default_EventCharaLeftX, default_EventCharaRightX][dir_horizontal == _DIR_RIGHT]);

	if(dir_horizontal == _DIR_LEFT){ left_chara_list = left_chara_list ~ [obj];}
	else{ right_chara_list = right_chara_list ~ [obj]; }
	ascent(i in 0..11)
	{
		let alpha = 128 + 127 * (i/10);
		REMY_Effect_SetColorSquare(obj, [alpha, 255,255,255]);
		yield;
	}
	Obj_SetAngle(obj,1);
	

	return obj;

}//


//LN^̑Oʁ^wʐ؂ւ
//obj:ړIuWFNg
//active:LOʂɒuۂ@_EVENT_BACK, _EVENT_FRONT̂ꂩA邢false/true
task REMY_Event_MoveCharacter(let obj, let active)
{
	
	let x = Obj_GetX(obj);
	let is_left = (x<GetCenterX());
	let is_front = (Obj_GetAngle(obj) != 0);
	
	if((active == _EVENT_BACK && !is_front) || (active == _EVENT_FRONT && is_front) ){return;}
	if(active){Obj_SetAngle(obj,1);}
	else{Obj_SetAngle(obj,0);}
	REMY_Event_LocateCharacter(obj, x + 40 * [-1,1][is_left] * [-1,1][active]);
	ascent(i in 0..21)
	{
		let alpha = 128 + 127 * [(1-i/20),(i/20)][active];
		REMY_Effect_SetColorSquare(obj, [alpha, 255,255,255]);
		yield;
	}

}//

//obj:ړIuWFNg
task REMY_Event_LocateCharacter(let obj, let to_x)
{
	let x = Obj_GetX(obj);
	let dist = (to_x-x);
	ascent(i in 0..20)
	{
		Obj_SetPosition(obj, x + dist * (i/20), Obj_GetY(obj));
		yield;
	}
	Obj_SetPosition(obj, to_x, Obj_GetY(obj));

}//

function REMY_Event_ChangeCharacter(let obj, let path, let rect, let off_set)
{
	ObjEffect_SetTexture(obj, path);
	REMY_Effect_SetVertexSquare(obj, rect, off_set[0], off_set[1], [255,128][(Obj_GetAngle(obj)==0)], 255, 255, 255);
	return;
}//


//CxgI
function REMY_Event_End()
{
	
	ascent(i in 0..length(left_chara_list)){ MoveChar(left_chara_list[i], 180); }
	ascent(i in 0..length(right_chara_list)){ MoveChar(right_chara_list[i], 0); }
	
	task MoveChar(let obj, let angle)
	{
		Obj_SetAngle(obj, angle);
		Obj_SetSpeed(obj, 6);
		descent(i in 0..60){
			REMY_Effect_SetColorSquare(obj, [120 * (i/60), 255, 255, 255]);
			yield;
		}
		Obj_Delete(obj);
	}
	
}//

