let left = true;
let right = true;
let textbox = -1;
let leftimage = -1;
let rightimage = -1;
let rightimagedeleted = true;
let leftimagedeleted = true;
#include"./../Spells/LoadGraphics.txt"


function CreateTextBox{
	textbox = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(textbox,box);
	ObjRender_SetBlendType(textbox,BLEND_ALPHA);
	ObjSprite2D_SetSourceRect(textbox,0,0,256,256);
	ObjRender_SetAlpha(textbox,255);
	Obj_SetRenderPriority(textbox,0.8);
	ascent(a in 0..60){
		ObjRender_SetAlpha(textbox,a*255/60);
		ObjSprite2D_SetDestRect(textbox,10,height-10-60,width-10,height-10-60+a);
		yield;}}

task DeleteTextBox{
	ascent(a in 0..60){
		ObjRender_SetAlpha(textbox,255-a*255/60);
		yield;}
	Obj_Delete(textbox);}

function MakeText(text,r,g,b){
	let obj = ObjText_Create;
	ObjText_SetText(obj, text);
	ObjText_SetFontSize(obj, 14);
	ObjText_SetFontBold(obj, true);
	ObjText_SetFontColorTop(obj, r, g, b);
	ObjText_SetFontColorBottom(obj, r-20, g-20, b-20);
	Obj_SetRenderPriorityI(obj, 100);
	ObjRender_SetX(obj, 50);
	ObjRender_SetY(obj, 405);
	return obj;}

task SetLeftImage(img, left, top, right, bottom, l, h) {
	Obj_Delete(leftimage);let move = 0;let alpha = 0;
	leftimage = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(leftimage, img);
	Obj_SetRenderPriorityI(leftimage, 38);
	ObjSprite2D_SetSourceRect(leftimage, left, top, right, bottom);
	if(leftimagedeleted){
	loop(20){
		ObjRender_SetAlpha(leftimage,alpha);
		ObjSprite2D_SetDestRect(leftimage, -(right-l)-50+move, height-h+50-move, l-50+move, height+(bottom-h)+50-move);
		move+=50/20;alpha+=255/20;yield;}}
		ObjSprite2D_SetDestRect(leftimage,-(right-l),height-h, l, height+(bottom-h));
	leftimagedeleted = false;}

task SetRightImage(img, left, top, right, bottom, l, h){
	Obj_Delete(rightimage);let move2 = 0;let alpha2 = 0;
	rightimage = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(rightimage, img);
	Obj_SetRenderPriorityI(rightimage, 38);
	ObjSprite2D_SetSourceRect(rightimage, left, top, right, bottom);
	if(rightimagedeleted){
	loop(20){
		ObjRender_SetAlpha(rightimage,alpha2);
		ObjSprite2D_SetDestRect(rightimage, width-l+50-move2, height-h+50-move2, width+(right-left-l)+50-move2, height+(bottom-h)+50-move2);
		move2+=50/20;alpha2+=255/20;yield;}}
	ObjSprite2D_SetDestRect(rightimage, width-l, height-h, width+(right-left-l), height+(bottom-h));
	rightimagedeleted = false;}

task DeleteLeftImage{let alpha=255;
	ObjMove_Special(leftimage,ObjRender_GetX(leftimage),ObjRender_GetY(leftimage),2,135);
		loop(50){
			ObjRender_SetAlpha(leftimage,alpha);
			alpha-=255/50;yield;}
	Obj_Delete(leftimage);
	leftimagedeleted = true;}

task DeleteRightImage{let alpha=255;
	ObjMove_Special(rightimage,ObjRender_GetX(rightimage),ObjRender_GetY(rightimage),2,45);
		loop(50){
			ObjRender_SetAlpha(rightimage,alpha);
			alpha-=255/50;yield;}
	Obj_Delete(rightimage);
	rightimagedeleted = true;}

//by Helepolis
task ObjMove_Special(obj,x,y,v,dir){
	let vx = v * cos(dir);
	let vy = v * sin(dir);
	loop(15){
		ObjRender_SetPosition(obj,x,y,0);
		yield;
		x+=vx;
		y+=vy;}}

function TalkLeft{
	ObjMove_Special(leftimage,ObjRender_GetX(leftimage),ObjRender_GetY(leftimage)+20,2,315);
	ObjMove_Special(rightimage,ObjRender_GetX(rightimage),ObjRender_GetY(rightimage),2,45);}

function TalkRight{
	ObjMove_Special(leftimage,ObjRender_GetX(leftimage),ObjRender_GetY(leftimage),2,135);
	ObjMove_Special(rightimage,ObjRender_GetX(rightimage),ObjRender_GetY(rightimage)+20,2,225);}

function TextLeftA(text,r,g,b){
	if(leftimagedeleted){loop(20){yield;}}
	ObjRender_SetAlpha(leftimage, 255);
	ObjRender_SetAlpha(rightimage, 100);
	Obj_SetRenderPriorityI(leftimage, 38);
	Obj_SetRenderPriorityI(rightimage, 37);
	let obj = MakeText(text,r,g,b);
	WaitPress;
	Obj_Delete(obj);}

function TextRightA(text,r,g,b){
	if(rightimagedeleted){loop(20){yield;}}
	ObjRender_SetAlpha(rightimage, 255);
	ObjRender_SetAlpha(leftimage, 100);
	Obj_SetRenderPriorityI(rightimage, 38);
	Obj_SetRenderPriorityI(leftimage, 37);
	let obj = MakeText(text,r,g,b);
	WaitPress;
	Obj_Delete(obj);}

function TextLeftB(text, time,r,g,b) {
	if(leftimagedeleted){loop(20){yield;}}
	ObjRender_SetAlpha(leftimage, 255);
	ObjRender_SetAlpha(rightimage, 100);
	Obj_SetRenderPriorityI(leftimage, 38);
	Obj_SetRenderPriorityI(rightimage, 37);
	let obj = MakeText(text,r,g,b);
	loop(time){yield;}
	Obj_Delete(obj);}

function TextRightB(text, time,r,g,b) {
	if(rightimagedeleted){loop(20){yield;}}
	ObjRender_SetAlpha(rightimage, 255);
	ObjRender_SetAlpha(leftimage, 100);
	Obj_SetRenderPriorityI(rightimage, 38);
	Obj_SetRenderPriorityI(leftimage, 37);
	let obj = MakeText(text,r,g,b);
	loop(time){yield;}
	Obj_Delete(obj);}

function WaitPress{
	while (GetVirtualKeyState(VK_SHOT) != KEY_PUSH) {yield;}
	yield;}

function width{return GetStgFrameWidth;}
function height{return GetStgFrameHeight;}