let leftCutin = ObjEnemy_Create(OBJ_ENEMY);
let rightCutin = ObjEnemy_Create(OBJ_ENEMY);
let seijaC = ObjEnemy_Create(OBJ_ENEMY);

let GetCenterX = GetScreenWidth()-97*2;
let GetCenterY = GetScreenHeight()-1*2;

let GetClipMinX = 97;
let GetClipMinY = 1;
let GetClipMaxX = GetScreenWidth()-97;
let GetClipMaxY = GetScreenHeight()-1;

let leftCutinO = 100;
let rightCutinO = 100;
let csc = 0.9;

InstallFont(GetCurrentScriptDirectory() ~ "./../lib/Fonts/undertale.ttf");

task Start{
	SetForbidPlayerShot(true); SetForbidPlayerSpell(true);
	//let obj = CreateEffectObject(310, GetClipMaxY-60, GetCurrentScriptDirectory ~ "./img/black.png", 0, 0, 460, 100);
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(obj, 4); Obj_SetRenderPriority(obj, 0.51);

	let x = [GetClipMinX, GetClipMaxX]; let y = [GetClipMaxY-100, GetClipMaxY];
	ObjPrim_SetVertexPosition(obj, 0, x[0], y[1], 0);
	ObjPrim_SetVertexPosition(obj, 1, x[1], y[1], 0);
	ObjPrim_SetVertexPosition(obj, 2, x[0], y[0], 0);
	ObjPrim_SetVertexPosition(obj, 3, x[1], y[0], 0);
	ascent(i in 0..4){ObjPrim_SetVertexColor(obj, i, 0, 0, 0);}

	ascent(i in 0..60){
		ObjRender_SetScaleX(obj, 1*i/59);
		ObjRender_SetAlpha(obj, 150*i/59);
		yield;
	}

	while(GetCommonData("end", false) == false){yield;}
	descent(i in 0..30){
		ObjRender_SetScaleX(obj, 1*i/29);
		ObjRender_SetAlpha(obj, 150*i/29);
		yield;
	}

	SetForbidPlayerShot(false); SetForbidPlayerSpell(false);
	Obj_Delete(obj);
}

task CutinPlayer{
	leftCutin = CreateEffectObject(190, GetClipMaxY-(160*csc), GetCurrentScriptDirectory ~ "./img/Tricky.png", 0, 0, 179, 314);
	Obj_SetRenderPriority(leftCutin, 0.5);
	ObjRender_SetAngleY(leftCutin, 0);
	ObjRender_SetScaleXYZ(leftCutin, csc, csc, 0);
	ascent(i in 0..15){
		ObjRender_SetAlpha(leftCutin, 255*i/14);
		yield;
	}

	while(GetCommonData("end", false) == false){yield;}
	descent(i in 0..30){
		ObjRender_SetX(leftCutin, ObjRender_GetX(leftCutin)-1);
		ObjRender_SetAlpha(leftCutin, 255*i/29);
		yield;
	}

	Obj_Delete(leftCutin);
}

task CutinBoss{
	rightCutin = CreateEffectObject(GetClipMaxX-(128*csc)/1.5, GetClipMaxY-(160*csc), GetCurrentScriptDirectory ~ "./img/Drek.png", 0, 0, 197, 419);
	Obj_SetRenderPriority(rightCutin, 0.5);
	ObjRender_SetScaleXYZ(rightCutin, csc, csc, 0);
	ascent(i in 0..15){
		ObjRender_SetAlpha(rightCutin, 255*i/14);
		yield;
	}

	while(GetCommonData("end", false) == false){yield;}
	descent(i in 0..30){
		ObjRender_SetX(rightCutin, ObjRender_GetX(rightCutin)+1);
		ObjRender_SetAlpha(rightCutin, 255*i/29);
		yield;
	}

	Obj_Delete(rightCutin);
}

function Talk(text, character){
	let t = ObjText_Create;
	ObjRender_SetPosition(t, 110, GetClipMaxY-85, 0);
	ObjText_SetText(t, text);
	ObjText_SetFontSize(t, 18); //12
	ObjText_SetFontType(t, "Fixedsys Excelsior 3.01");
	if(character == "Player"){
		ObjText_SetFontColorTop(t, 250, 140, 30);
		ObjText_SetFontColorBottom(t, 142, 77, 11);
		Highlight(leftCutin);
		Downlight(rightCutin);
	}
	if(character == "Boss"){
		ObjText_SetFontColorTop(t, 249, 6, 6);
		ObjText_SetFontColorBottom(t, 150, 3, 3);
		Highlight(rightCutin);
		Downlight(leftCutin);
	}
	if(character == "Sub"){
		ObjText_SetFontSize(t, 16);
		ObjText_SetFontType(t, "Courier New");
		ObjText_SetFontColorTop(t, 153, 255, 153);
		ObjText_SetFontColorBottom(t, 0, 77, 0);
		Downlight(leftCutin);
		Downlight(rightCutin);
	}
	ObjText_SetFontBorderType(t, BORDER_FULL);
	ObjText_SetFontBorderColor(t, 1, 1, 1);
	ObjText_SetFontBorderWidth(t, 1);
	ObjText_SetMaxWidth(t, GetClipMaxX-120); //-24
	Obj_SetRenderPriority(t, 0.52);
	ObjText_SetLinePitch(t, 0);
	ascent(i in 0..10){
		ObjRender_SetScaleY(t, 1*i/9);
		yield;
	}
	while(GetVirtualKeyState(VK_SHOT) != KEY_HOLD){yield;}
	//TPlay(plshot);
	descent(i in 0..10){
		ObjRender_SetScaleY(t, 1*i/9);
		yield;
	}
	Obj_Delete(t);
}

let ne = (((128*csc)/1.5)/2)/8;

task Highlight(obj){
	let n = 0;
	if(obj == leftCutin){n = leftCutinO;}
	if(obj == rightCutin){n = rightCutinO;}
	loop(10){
		if(obj == leftCutin){
			if(ObjRender_GetX(obj) < 190){ObjRender_SetX(obj, ObjRender_GetX(obj)+ne);}
			if(n < 255){
				leftCutinO += 155/9;
				ObjRender_SetColor(leftCutin, leftCutinO, leftCutinO, leftCutinO);
			}
		}
		if(obj == rightCutin){
			if(ObjRender_GetX(obj) > GetClipMaxX-((128*csc)/1.5)){ObjRender_SetX(obj, ObjRender_GetX(obj)-ne);}
			if(n < 255){
				rightCutinO += 155/9;
				ObjRender_SetColor(rightCutin, rightCutinO, rightCutinO, rightCutinO);
			}
		}
		yield;
	}
}

task Downlight(obj){
	let n = 0;
	if(obj == leftCutin){n = leftCutinO;}
	if(obj == rightCutin){n = rightCutinO;}
	loop(10){
		if(obj==leftCutin){
			if(ObjRender_GetX(obj)>(190/2)){ObjRender_SetX(obj,ObjRender_GetX(obj)-ne);}
			if(n>100){
				leftCutinO-=155/9;
				ObjRender_SetColor(leftCutin,leftCutinO,leftCutinO,leftCutinO);
			}
		}
		if(obj==rightCutin){
			if(ObjRender_GetX(obj)<GetClipMaxX-(((128*csc)/1.5)/2)){ObjRender_SetX(obj,ObjRender_GetX(obj)+ne);}
			if(n>100){
				rightCutinO-=155/9;
				ObjRender_SetColor(rightCutin,rightCutinO,rightCutinO,rightCutinO);
			}
		}
		yield;
	}
}

function TalkW(text,r,g,b,time){
	let t = ObjText_Create;
	ObjRender_SetPosition(t,20,GetClipMaxY-100,0);
	ObjText_SetText(t,text);
	ObjText_SetFontSize(t,12); //12
	ObjText_SetFontColorTop(t,255,255,255);
	ObjText_SetFontColorBottom(t,r,g,b);
	ObjText_SetFontBorderType(t,BORDER_FULL);
	ObjText_SetFontBorderColor(t,25,25,25);
	ObjText_SetFontBorderWidth(t,1);
	ObjText_SetMaxWidth(t, GetStgFrameWidth-30); //-24
	Obj_SetRenderPriority(t, 0.51);
	ascent(i in 0..10){
		ObjRender_SetScaleY(t,1*i/9);
		yield;
	}
	wait(time-20);
	descent(i in 0..10){
		ObjRender_SetScaleY(t,1*i/9);
		yield;
	}
	Obj_Delete(t);
}

task title(text,r,g,b){
	let t = ObjText_Create;
	ObjRender_SetPosition(t, 90, GetClipMaxY-125, 0);
	ObjText_SetText(t, text);
	ObjText_SetFontType(t, "Russell Square Regular");
	ObjText_SetFontSize(t, 20); //12
	ObjText_SetFontColorTop(t, r, g, b);
	ObjText_SetFontColorBottom(t, r/2, g/2, b/2);
	ObjText_SetFontBorderType(t, BORDER_FULL);
	ObjText_SetFontBorderColor(t, 0, 0, 0);
	ObjText_SetFontBorderWidth(t, 1);
	ObjText_SetMaxWidth(t, GetStgFrameWidth-30); //-24
	Obj_SetRenderPriority(t, 0.51);
	let re = 2;
	ascent(i in 0..30){
		ObjRender_SetX(t, ObjRender_GetX(t)+re);
		ObjRender_SetAlpha(t, 255*i/29);
		re -= 2/29;
		yield;
	}
	wait(120);
	descent(i in 0..30){
		ObjRender_SetX(t, ObjRender_GetX(t)+re);
		ObjRender_SetAlpha(t, 255*i/29);
		re-=2/29;
		yield;
	}
	Obj_Delete(t);
}

