let imgBoss = GetCurrentScriptDirectory ~ "./img/Nue.png";
let ufo = GetCurrentScriptDirectory ~ "./img/UFO.png";

let attack = false;
task rendernue(tar){
	let dir = 0;
	let speed = 0;
	let frame = 0;
	let mframe = 0;
	let aframe = 0;
	let x = 96;
	let y = 112;
	
	
	ObjRender_SetAlpha(tar,255);
	while(!Obj_IsDeleted(tar)){	
	ObjPrim_SetTexture(tar,imgBoss);
	ObjSprite2D_SetSourceRect(tar,0,0,x,y);
	ObjSprite2D_SetDestCenter(tar);	
	ObjRender_SetScaleXYZ(tar,1,1,0);
	ObjRender_SetAngleXYZ(tar,0,0,0);
	ObjRender_SetScaleXYZ(tar,1,1,0);
		
		dir = ObjMove_GetAngle(tar);
		speed = ObjMove_GetSpeed(tar);
		
		if(speed==0){
			if(attack == true) {aframe++;
			if(aframe <= 4) {ObjSprite2D_SetSourceRect(tar,0,y*3,x,y*4);}
			if(aframe >= 4) {ObjSprite2D_SetSourceRect(tar,x,y*3,x*2,y*4);}
			if(aframe >= 8) {ObjSprite2D_SetSourceRect(tar,x*2,y*3,x*3,y*4);}
			if(aframe >= 12) {ObjSprite2D_SetSourceRect(tar,x*3,y*3,x*4,y*4);}
			if(aframe >= 16) {ObjSprite2D_SetSourceRect(tar,x*4,y*3,x*5,y*4);}
			if(aframe > 20){aframe-=(4*2);}		
			}	
			if(attack == false) {
			ObjRender_SetAngleXYZ(tar,0,0,0);
			if(frame<8){ObjSprite2D_SetSourceRect(tar,0,0,x,y);}
			if(frame>=8 && frame<16){ObjSprite2D_SetSourceRect(tar,x*1,0,x*2,y);}
			if(frame>=16 && frame<24){ObjSprite2D_SetSourceRect(tar,x*2,0,x*3,y);}
			if(frame>=24 && frame<32){ObjSprite2D_SetSourceRect(tar,x*3,0,x*4,y);}
			mframe=0;
			aframe=0;
			}
		}			
		
		else if(cos(dir) > 0) {mframe++;
        if(mframe <= 4) {ObjSprite2D_SetSourceRect(tar,0,y*1,x,y*2);}
        if(mframe >= 4) {ObjSprite2D_SetSourceRect(tar,x,y*1,x*2,y*2);}
		if(mframe >= 8) {ObjSprite2D_SetSourceRect(tar,x*2,y*1,x*3,y*2);}
		if(mframe >= 12) {ObjSprite2D_SetSourceRect(tar,x*3,y*1,x*4,y*2);}
        }
		
		else if(cos(dir) < 0) {mframe++;
        if(mframe <= 4) {ObjSprite2D_SetSourceRect(tar,0,y*2,x,y*3);}
        if(mframe >= 4) {ObjSprite2D_SetSourceRect(tar,x,y*2,x*2,y*3);}
		if(mframe >= 8) {ObjSprite2D_SetSourceRect(tar,x*2,y*2,x*3,y*3);}
		if(mframe >= 12) {ObjSprite2D_SetSourceRect(tar,x*3,y*2,x*4,y*3);}
        }	

		frame++;
		if(frame==32){frame=0;}
		yield;
	}
}

task whiteUFO(tar){
	let dir = 0;
	let speed = 0;
	let frame = 0;
	
	while(!Obj_IsDeleted(tar)){	
	ObjPrim_SetTexture(tar,ufo);
	ObjSprite2D_SetSourceRect(tar,0,0,64,64);
	ObjSprite2D_SetDestCenter(tar);	
	ObjRender_SetScaleXYZ(tar,1,1,0);
	ObjRender_SetAlpha(tar,255);
	ObjRender_SetAngleXYZ(tar,0,0,0);
	ObjRender_SetScaleXYZ(tar,1,1,0);
		
		dir = ObjMove_GetAngle(tar);
		speed = ObjMove_GetSpeed(tar);
		
		if(true){
			if(frame <= 8) {ObjSprite2D_SetSourceRect(tar,0,256,64,320);}
			if(frame >= 8) {ObjSprite2D_SetSourceRect(tar,64,256,64*2,320);}
			if(frame >= 12) {ObjSprite2D_SetSourceRect(tar,64*2,256,64*3,320);}
			if(frame >= 20) {ObjSprite2D_SetSourceRect(tar,64*3,256,64*4,320);}
		}		

		frame++;
		if(frame==20){frame=0;}
		yield;
		}
	}
	
let dissapear = false;

task DialogueBox{
let alpha = 0;
let mult = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/dialoguebox.png");
	ObjSprite2D_SetSourceRect(obj,1, 0, 350, 48);
	ObjRender_SetScaleXYZ(obj,1,1.1,1);
	Obj_SetRenderPriorityI(obj,60);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2,350,0);
	loop(30){
	ObjRender_SetAlpha(obj,alpha);	
	mult+=1;
	alpha+=mult/3;
	yield;
	}
	loop{
	if(dissapear == true){Obj_Delete(obj);}
	yield;
	}
}

task Dialogue(text, character){
let alpha = 255;
	let char = 0;
	if(character=="Player"){char=0;}
	if(character=="Nue"){char=1;}
	if(character=="Junko"){char=2;}
	let fontColor = [[0,200,0],[160,160,160],[190, 65, 164]];
	let fontType = ["Verdana","Eurostile","Eurostile"];
	
	let currentType = fontType[char];	
	let currentColor = fontColor[char];	
	
	
    let obj = ObjText_Create();
    ObjText_SetText(obj, text);
	Obj_SetRenderPriorityI(obj,61);
    ObjText_SetFontSize(obj, 16);
    ObjText_SetFontType(obj, currentType);
    ObjText_SetFontBold(obj, false);
    ObjText_SetFontColorTop(obj, 255, 255, 255);
    ObjText_SetFontColorBottom(obj, 255, 255, 255);
    ObjText_SetFontBorderType(obj, BORDER_FULL);
    ObjText_SetFontBorderColor(obj, currentColor[0], currentColor[1], currentColor[2]);
    ObjText_SetFontBorderWidth(obj, 1);
	ObjRender_SetPosition(obj,40,330,0);
	
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	loop(5){
		alpha-=255/5;
		ObjRender_SetAlpha(obj,alpha);
	yield;}
	Obj_Delete(obj);
}

task TimedDialogue(text, character, time){
let alpha = 255;
	let char = 0;
	if(character=="Player"){char=0;}
	if(character=="Nue"){char=1;}
	if(character=="Junko"){char=2;}
	let fontColor = [[0,200,0],[160,160,160],[190, 65, 164]];
	let fontType = ["Verdana","Eurostile","Eurostile"];
	
	let currentType = fontType[char];	
	let currentColor = fontColor[char];	
	
	
    let obj = ObjText_Create();
    ObjText_SetText(obj, text);
	Obj_SetRenderPriorityI(obj,61);
    ObjText_SetFontSize(obj, 16);
    ObjText_SetFontType(obj, currentType);
    ObjText_SetFontBold(obj, false);
    ObjText_SetFontColorTop(obj, 255, 255, 255);
    ObjText_SetFontColorBottom(obj, 255, 255, 255);
    ObjText_SetFontBorderType(obj, BORDER_FULL);
    ObjText_SetFontBorderColor(obj, currentColor[0], currentColor[1], currentColor[2]);
    ObjText_SetFontBorderWidth(obj, 1);
	ObjRender_SetPosition(obj,40,330,0);
	
	loop(time){yield;}
	loop(5){
		alpha-=255/5;
		ObjRender_SetAlpha(obj,alpha);
	yield;}
	Obj_Delete(obj);
}

let Playertalking = true;
let Nuetalking = false;
let Junkotalking = false;

task NueTalk{
	Playertalking = false;
	Nuetalking = true;
	Junkotalking = false;
}

task PlayerTalk{
	Playertalking = true;
	Nuetalking = false;
	Junkotalking = false;
}

task JunkoTalk{
	Playertalking = false;
	Nuetalking = false;
	Junkotalking = true;
}



let EmoWhat = false;
let EmoRegular = false;
let EmoAngry = false;
let EmoRight = false;
let EmoEx = false;
task PlayerSetEmotion(emo){ //<w<
	if(emo=="Regular"){EmoRegular=true;EmoWhat=false;EmoAngry=false;EmoRight=false;EmoEx=false;}
	if(emo=="What"){EmoRegular=false;EmoWhat=true;EmoAngry=false;EmoRight=false;EmoEx=false;}
	if(emo=="Angry"){EmoRegular=false;EmoWhat=false;EmoAngry=true;EmoRight=false;EmoEx=false;}
	if(emo=="Right"){EmoRegular=false;EmoWhat=false;EmoAngry=false;EmoRight=true;EmoEx=false;}
	if(emo=="Ex"){EmoRegular=false;EmoWhat=false;EmoAngry=false;EmoRight=false;EmoEx=true;}
}

let EmoHehN = false;
let EmoOkeN = false;
let EmoRegularN = false;
task NueSetEmotion(emo){ //<w<
	if(emo=="Regular"){EmoRegularN=true;EmoHehN=false;EmoOkeN=false;}
	if(emo=="Heh"){EmoRegularN=false;EmoHehN=true;EmoOkeN=false;}
	if(emo=="Oke"){EmoRegularN=false;EmoHehN=false;EmoOkeN=true;}
}

task PlayerPortait{
let alpha = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/Emotions/When.png");
	ObjSprite2D_SetSourceRect(obj,0, 0, 411, 500);
	ObjRender_SetScaleXYZ(obj,0.7,0.7,1);
	Obj_SetRenderPriorityI(obj,55);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj,90,300,0);
	loop(5){
	alpha+=255/5;
	ObjRender_SetAlpha(obj,alpha);
	yield;
	}
	loop{
	if(dissapear == true || cutscene == true){Obj_Delete(obj);}
	if(Playertalking==true){ObjRender_SetAlpha(obj,255);}
	if(Playertalking==false){ObjRender_SetAlpha(obj,155);}
	if(EmoRegular==true){ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/Emotions/When.png")}
	if(EmoAngry==true){ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/Emotions/Where.png")}
	if(EmoRight==true){ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/Emotions/Why.png")}
	if(EmoWhat==true){ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/Emotions/Wat.png")}
	if(EmoEx==true){ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/Emotions/Who.png")}
	if(cutscene==true){Obj_Delete(obj);}
	yield;
	}
}

task NuePortrait{
let alpha = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/Emotions/Nue1.png");
	ObjSprite2D_SetSourceRect(obj,0, 0, 402, 320);
	ObjRender_SetScaleXYZ(obj,0.7,0.7,1);
	Obj_SetRenderPriorityI(obj,55);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj,300,208,0);
	loop(5){
	alpha+=255/5;
	ObjRender_SetAlpha(obj,alpha);
	yield;
	}
	loop{
	if(dissapear == true || cutscene == true){Obj_Delete(obj);}
	if(Nuetalking==true){ObjRender_SetAlpha(obj,255);}
	if(Nuetalking==false){ObjRender_SetAlpha(obj,155);}
	if(EmoRegularN==true){ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/Emotions/Nue1.png")}
	if(EmoHehN==true){ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/Emotions/Nue2.png")}
	if(EmoOkeN==true){ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/Emotions/Nue3.png")}
	yield;
	}
}

task JunkoPortrait{
let alpha = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/Emotions/PURIFY.png");
	ObjSprite2D_SetSourceRect(obj,0, 1, 1000, 1024);
	ObjRender_SetScaleXYZ(obj,0.25,0.25,1);
	Obj_SetRenderPriorityI(obj, 65);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj,270,195,0);
	loop(5){
	alpha+=255/5;
	ObjRender_SetAlpha(obj,alpha);
	yield;
	}
	loop{
	if(dissapear == true || cutscene == false){Obj_Delete(obj);}
	if(Junkotalking==true){ObjRender_SetAlpha(obj,255);}
	if(Junkotalking==false){ObjRender_SetAlpha(obj,155);}
	yield;
	}
}

let kill = false;

task Fade{
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,70);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./img/black.png");
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,5,5,5);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj, 0);
	while(!Obj_IsDeleted(obj)){
	ObjRender_SetAlpha(obj, count);
	if(count==255){break;}
	count++;
	yield;
	}
	while(!Obj_IsDeleted(obj)){
	ObjRender_SetAlpha(obj, count*2);
	if(count==0){break;}
	count--;
	yield;
	}
	Obj_Delete(obj);
}

function Junko{
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);
Render(obj);
return(obj);
	task Render(obj){
	let texture = GetCurrentScriptDirectory ~ "./img/PURE.png";
	let count = 0;
	let X = 96;
	let Y = 132;
	ObjPrim_SetTexture(obj, texture);
	Obj_SetRenderPriorityI(obj, 69); //hue
	ObjSprite2D_SetSourceRect(obj,0,0,X,Y);
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetAlpha(obj,255);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetPosition(obj, ObjMove_GetX(obj), ObjMove_GetX(obj), 0);
		loop{
		ObjRender_SetAngleXYZ(obj,0,0,count*7);
		count++;
		yield;
		}
	}
}

let cutscene = false;
task CutsceneBackground{
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,50);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "./img/ground.png");
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,1.5);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
	while( !Obj_IsDeleted(obj)){
	count++;
	ObjSprite2D_SetSourceRect(obj,0,-count,512,512+(-count));
	if(cutscene == false){break;}
	yield;
	}
	Obj_Delete(obj);
}