script_enemy_main{

let starttime=120;

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=21;
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",8);
	LoadPortrait("Nanami",1);
	
	#include_function "script/Functions/PortraitsLoad.txt";
	
	SetCommonData("InEvent",1);
	SetCommonData("BackgroundStop",1);

	SetCommonData("Boss1Move",1);
}
	
@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,CHempty);
	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,CHempty);
	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,"Nanami","Waah!% So huge!",CHNanamiNormal01);
WriteLine(2,"Masahiro","It`s nice that you could join us for the remaining days,% Nanami.",CHMasahiroNormal06);
WriteLine(3,"Nanami","Yeah!% It`s a lot of fun here!",CHNanamiNormal02);
WriteLine(4,"Nanami","Hey,% what`s that happening over there,% nee-san?",CHNanamiNormal03);
WriteLine(5,"Tomoko","Over there?+That`s hard to tell%.%.%.+It looks like a contest of some sort.",CHTomokoSpecial01);
WriteLine(6,"Masahiro","Maybe it`s a Miss Beach contest.",CHMasahiroNormal02);
WriteLine(7,"Nanami","Yeah!% There`s a lot of pretty girls over there.+Nee-san should join too!",CHNanamiNormal04);
WriteLine(8,"Tomoko","I don`t think I would stand a chance in such a contest%.%.%.",CHTomokoSpecial02);
WriteLine(9,"Masahiro","I`m sure you would!+You`d get my vote!",CHMasahiroNormal06);
WriteLine(10,"Nanami","And mine too!+So now you can`t lose anymore!",CHNanamiNormal05);
WriteLine(11,"Tomoko","Heh%.%.%.+You`re making it hard to say no%.%.%.",CHTomokoSpecial03);
WriteLine(12,"Tomoko","%.%.%.%%%Okay,% I`ll join.+You two just wait a moment,% okay?",CHTomokoSpecial03);
WriteLine(13,"Nanami","Yay!",CHNanamiNormal02);
WriteLine(14,"Nanami","Say,% Masahiro,% you old people like that danmaku game,% don`t you?",CHNanamiNormal06);
WriteLine(15,"Masahiro","We`re not old%.%.%.",CHMasahiroNormal09);
WriteLine(16,"Masahiro","Ah,% but it`s pretty popular amongst high schoolers.",CHMasahiroNormal06);
WriteLine(17,"Masahiro","(I`ve been playing it a bit too much lately though%.%.%.)",CHMasahiroNormal22);
WriteLine(18,"Nanami","I have some pretty spellcards too.+Can I show you?",CHNanamiNormal05);
WriteLine(19,"Masahiro","Haha,% sure.+Go all out!",CHMasahiroNormal26);
WriteLine(20,"Nanami","Okay,% here I come!",CHNanamiNormal05);

if(linenumber==1 && i==1){ nameappear=17; }

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

} //>starttime

if(skipped==2 && wait==1){  }

if(linenumber==lastline && wait==60){
	Obj_Delete(OBJtextbar);
	Obj_Delete(OBJleft);
	Obj_Delete(OBJright);

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

//	VanishEnemy; // end conversation
	SetLife(0); // start battle
}


time++;
frame++;
}

}