let TextStep=0;
let TalkEndFlag=0;
let TalkTime=0;
let SkipAvailable=0;

task TalkFrame
{
	LoadTexture(GetCurrentScriptDirectory~"img/Frame.png");
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
//	ObjRender_SetBlendType(obj, BLEND_SUBTRACT);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"img/Frame.png");//オブジェクトとテスクチャを関連付け
	ObjRender_SetPosition(obj, 192, 384, 0);
	Obj_SetRenderPriority(obj, 0.31);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 384, 64);
	ObjSprite2D_SetDestRect(obj, -192, -32, 192, 32);
	ObjRender_SetAlpha(obj,150);
	ObjRender_SetColor(obj,255,255,150);
	let Scale=0;
	ObjRender_SetScaleY(obj,Scale);
	loop(10)
	{
		Scale+=1/10;
		ObjRender_SetScaleY(obj,Scale);
		yield;
	}
	while(!TalkEndFlag){yield;}
	loop(10)
	{
		Scale-=1/10;
		ObjRender_SetScaleY(obj,Scale);
		yield;
	}
	Obj_Delete(obj);
}

task CommandStep
{
let Count=0;
loop
{
	if(GetVirtualKeyState(VK_SHOT)==KEY_PUSH && SkipAvailable)
	{
		Count=0;
		TextStep+=1
	}
	if(GetVirtualKeyState(VK_USER1)==KEY_HOLD && SkipAvailable)
	{
		Count=0;
		TextStep+=1
	}
	if(Count>=TalkTime && TalkTime>0)
	{
		Count=0;
		TextStep+=1
	}
	if(TalkEndFlag){break;}
	Count+=1;
yield;
}
}

function EV_wait
{
let TS=TextStep;
while(TextStep==TS){yield;}
}

task EV_DrawText(text,type,my,Delay,Step)
{
	loop(Delay*2){if(TextStep!=Step){break;}yield;}
	ascent(i in 0..floor(length(text)/2))
	{
	EV_DrawLetter(19*i,my,text[i*2..i*2+2]);
	loop(2){if(TextStep!=Step){break;}yield;}
	}

	task EV_DrawLetter(x,y,letter)
	{
	let obj = ObjText_Create();
	ObjText_SetText(obj, letter);
	ObjText_SetFontSize(obj, 18);
	ObjText_SetFontBold(obj, true);
	//ObjText_SetFontColorTop(obj, 196, 196, 255);
	//ObjText_SetFontColorBottom(obj, 128, 128, 255);
	ObjText_SetFontBorderType(obj, BORDER_NONE);
	ObjText_SetFontBorderColor(obj,255, 255, 255);
	ObjText_SetFontBorderWidth(obj, 0);
	Obj_SetRenderPriorityI(obj, 72);
	ObjRender_SetX(obj,16+x);
	ObjRender_SetY(obj, y);
	ObjText_SetFontType(obj,"ＭＳ 明朝");

	ObjText_SetMaxWidth(obj,360);
	if(type==1){ObjRender_SetColor(obj,255,200,200);}
	if(type==-1){ObjRender_SetColor(obj,200,200,255);}
	loop
	{
		if(TextStep!=Step){break;}
		yield;
	}
	let scale=1;
	loop(5)
	{
		ObjRender_SetAlpha(obj,scale*255);
		scale-=1/5;
	//	ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		yield;
	}
	Obj_Delete(obj);
	}
}