script_enemy_main{

let starttime=90;

let speakingside=0;
let movecharacter=0;
let characterscroll=0;
let oldside=0;

let i=0;
let j=0;
let letter=0;
let letters=[];
let letterscale=[];
let letterfade=[];
let letterred=[];
let lettergreen=[];
let letterblue=[];

let line="";
let writingtime=0;
let nextline=0;
let newword=0;
let wordsize=0;
let lineypos=0;

let wait=0;
let busywriting=0;
let shortbreak=0;
let skipped=0;
let currentline=1;
let linenumber=1;
let textcolor=[0,0,0];
let newcolor=[textcolor[0],textcolor[1],textcolor[2],0,0,0];
let nameappear=0;

let lastline=12;
let waittime=180;
let enableZ=true;
let enableskip=true;

let GRtextbar=("\script\Images\OtherEffects\Textbar.png");
let GRtext=("\script\Images\OtherEffects\TextDialogue.png");
let GRnames=("\script\Images\OtherEffects\Names.png");

let SEtext=("\script\SoundEffects\text1.wav");

#include_function "script/Functions/PortraitsVariables.txt";

let OBJtextbar=0; let OBJtext=0; let OBJleft=0; let OBJright=0;
let textbarscale=0;

let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let frame=0; let time=0;

@Initialize{
	SetLife(1000);
	SetX(cx);
	SetY(-1000);
	
	LoadPortrait("Masahiro",1);
	LoadPortrait("Tomoko",1);
	LoadPortrait("Setsuko",1);
	LoadPortrait("Shinichi",1);
	
	#include_function "script/Functions/PortraitsLoad.txt";
	
	SetCommonData("InEvent",1);
	SetCommonData("BackgroundStop",1);
	
	SetCommonData("Boss1Move",4);
	SetCommonData("Boss2Move",4);
}
	
@MainLoop{

CollectItems;

if(time==starttime){
	OBJtextbar=(Obj_Create(OBJ_EFFECT));
	ObjEffect_SetLayer(OBJtextbar,6); Obj_SetPosition(OBJtextbar,cx,maxy-70); ObjEffect_SetTexture(OBJtextbar,GRtextbar);
	ObjEffect_SetRenderState(OBJtextbar,ALPHA); ObjEffect_SetScale(OBJtextbar,1,1);
	ObjEffect_SetScale(OBJtextbar,1,0);
	ObjEffect_SetPrimitiveType(OBJtextbar,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(OBJtextbar,4);
	ObjEffect_SetVertexXY(OBJtextbar,0,-190,-50); ObjEffect_SetVertexUV(OBJtextbar,0,0,0);
	ObjEffect_SetVertexXY(OBJtextbar,1,190,-50); ObjEffect_SetVertexUV(OBJtextbar,1,380,0);
	ObjEffect_SetVertexXY(OBJtextbar,2,-190,50); ObjEffect_SetVertexUV(OBJtextbar,2,0,100);
	ObjEffect_SetVertexXY(OBJtextbar,3,190,50); ObjEffect_SetVertexUV(OBJtextbar,3,380,100);
	ObjEffect_SetVertexColor(OBJtextbar,0,200,255,255,255); ObjEffect_SetVertexColor(OBJtextbar,1,200,255,255,255);
	ObjEffect_SetVertexColor(OBJtextbar,2,200,255,255,255); ObjEffect_SetVertexColor(OBJtextbar,3,200,255,255,255);

	OBJleft=(Obj_Create(OBJ_EFFECT));
	ObjEffect_SetLayer(OBJleft,5); Obj_SetPosition(OBJleft,cx-100,cy+60); ObjEffect_SetTexture(OBJleft,CHMasahiroNormal01);
	ObjEffect_SetPrimitiveType(OBJleft,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(OBJleft,4); ObjEffect_SetAngle(OBJleft,0,180,0);
	ObjEffect_SetVertexXY(OBJleft,0,-175,-175); ObjEffect_SetVertexUV(OBJleft,0,0,0);
	ObjEffect_SetVertexXY(OBJleft,1,175,-175); ObjEffect_SetVertexUV(OBJleft,1,350,0);
	ObjEffect_SetVertexXY(OBJleft,2,-175,175); ObjEffect_SetVertexUV(OBJleft,2,0,350);
	ObjEffect_SetVertexXY(OBJleft,3,175,175); ObjEffect_SetVertexUV(OBJleft,3,350,350);
	ObjEffect_SetVertexColor(OBJleft,0,255,255,255,255); ObjEffect_SetVertexColor(OBJleft,1,255,255,255,255);
	ObjEffect_SetVertexColor(OBJleft,2,255,255,255,255); ObjEffect_SetVertexColor(OBJleft,3,255,255,255,255);

	OBJright=(Obj_Create(OBJ_EFFECT));
	ObjEffect_SetLayer(OBJright,5); Obj_SetPosition(OBJright,cx+100,cy+60); ObjEffect_SetTexture(OBJright,CHTomokoNormal06);
	ObjEffect_SetPrimitiveType(OBJright,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(OBJright,4); ObjEffect_SetAngle(OBJright,0,0,0);
	ObjEffect_SetVertexXY(OBJright,0,-175,-175); ObjEffect_SetVertexUV(OBJright,0,0,0);
	ObjEffect_SetVertexXY(OBJright,1,175,-175); ObjEffect_SetVertexUV(OBJright,1,350,0);
	ObjEffect_SetVertexXY(OBJright,2,-175,175); ObjEffect_SetVertexUV(OBJright,2,0,350);
	ObjEffect_SetVertexXY(OBJright,3,175,175); ObjEffect_SetVertexUV(OBJright,3,350,350);
	ObjEffect_SetVertexColor(OBJright,0,255,255,255,255); ObjEffect_SetVertexColor(OBJright,1,255,255,255,255);
	ObjEffect_SetVertexColor(OBJright,2,255,255,255,255); ObjEffect_SetVertexColor(OBJright,3,255,255,255,255);
}
if(time>=starttime){

if(textbarscale<1 && linenumber<lastline){ textbarscale+=0.1; }
if(textbarscale>0 && linenumber==lastline){ textbarscale-=0.1; }
if(textbarscale<0){ Obj_Delete(OBJtextbar); }
ObjEffect_SetScale(OBJtextbar,1,textbarscale);

if(nextline==1){ i=0; j=0; nextline=0; wordsize=0; lineypos=0; wait=0; currentline++; linenumber++; }
if(nextline==2){ i=0; j=0; nextline=0; wordsize=0; lineypos=0; wait=0; currentline=lastline; linenumber=lastline; }


WriteLine(1,"Setsuko","Seems like this isn`t it either.",CHSetsukoNormal01);
WriteLine(2,"Shinichi","Perhaps that really was the same tree as earlier after all.",CHShinichiNormal01);
WriteLine(3,"Masahiro","Hello,% Setsuko and Shinichi.+Did you find the way back to the ryokan yet?",CHMasahiroNormal06);
WriteLine(4,"Setsuko","Oh,% hello.% Unfortunately we didn`t yet.+How about you?",CHSetsukoNormal02);
WriteLine(5,"Masahiro","We`re out of luck too.+When we thought we were getting close,% we lost an important part of the map%.%.%.",CHMasahiroNormal05);
WriteLine(6,"Tomoko","Well,% sorry about that!",CHTomokoNormal07);
WriteLine(7,"Shinichi","You lost the map?+In a crisis such as this,% you lose the only thing that can help you get out?",CHShinichiNormal02);
WriteLine(8,"Masahiro","You`re exaggerating that crisis part a bit%.%.%.",CHMasahiroNormal07);
WriteLine(9,"Setsuko","I think they need a lesson to learn to remember what is important and what is not.",CHSetsukoNormal03);
WriteLine(10,"Shinichi","You spoke my thoughts,% comrade.",CHShinichiNormal03);
WriteLine(11,"Masahiro","Hey,% hold on a minute!",CHMasahiroNormal08);

if(linenumber==1 && i==1){ nameappear=4; }
if(linenumber==2 && i==1){ nameappear=16; }


#include_function "script/Functions/TextWriter.txt";

} //>starttime

if(linenumber==lastline && wait==1){ SetCommonData("PlayMusic",2); }
if(skipped==2 && wait==1){ SetCommonData("PlayMusic",2); }


if(linenumber==lastline && wait==60){
	SetShotColor(255,255,255);

	Obj_Delete(OBJleft);
	Obj_Delete(OBJright);
	Obj_Delete(OBJtextbar);

	SetCommonData("InEvent",0);
//	SetCommonData("BackgroundStop",0);

//	VanishEnemy; SetCommonData("Conversation",2); // end conversation
	SetLife(0); // start battle
}


time++;
frame++;
}

}