let CSD = GetCurrentScriptDirectory;

SetAutoDeleteObject(true);
#include "./Conc.txt"

task Render{

	Name;
	let f = 0; 
	let f2 = 0;
	let f3 = 0;
	let dir;
	let speed;
	
	let kanako = CSD ~ "img/Kanako.png";
	let imgBoss2 = CSD ~ "img/Aura.png";
		
	//Textures the Boss, Indicates the Boss's True Center and Sets its scale.
	ObjPrim_SetTexture(bossObj,imgBoss);
	ObjSprite2D_SetSourceRect(bossObj,0,0,110,110);
	ObjSprite2D_SetDestCenter(bossObj);
	ObjRender_SetScaleXYZ(bossObj,0.7,0.7,0);
	
	let auraObj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	// While the Boss is NOT(!)Deleted or alive, this loop plays.
	while(!Obj_IsDeleted(bossObj)){
	
	ObjPrim_SetTexture(auraObj,imgBoss2);
	ObjSprite2D_SetSourceRect(auraObj,0,0,256,256);
	ObjSprite2D_SetDestCenter(auraObj);
	Obj_SetRenderPriorityI(auraObj,30);
	ObjRender_SetAlpha(auraObj,rand(64,128));
	ObjRender_SetPosition(auraObj,ObjMove_GetX(bossObj),ObjMove_GetY(bossObj),0);
	
		// Variables update the Speed and Direction of this boss (In this task (renderBoss))
		dir = ObjMove_GetAngle(bossObj);
		speed = ObjMove_GetSpeed(bossObj);
		
		// If the Boss is Idle, It shows this image.
		if( cos(dir) == 0 && speed <= 0){
		ObjRender_SetScaleXYZ(bossObj,1,1,1);
			if(f<5){ObjSprite2D_SetSourceRect(bossObj,0,0,64,64);}
			if(f>=5 && f<10){ObjSprite2D_SetSourceRect(bossObj,64,0,128,64);}
			if(f>=10 && f<15){ObjSprite2D_SetSourceRect(bossObj,128,0,192,64);}
			if(f>=15 && f<20){ObjSprite2D_SetSourceRect(bossObj,192,0,256,64);}
			
			f2=0;
			f3=0;
			f++;
		}
		
		// If the Boss is moving right, It shows this image.
		else if(cos(dir) > 0 && speed > 0){
		ObjRender_SetScaleXYZ(bossObj,1,1,1);
		ObjRender_SetAngleY(bossObj,0);
			if(f2<5){ObjSprite2D_SetSourceRect(bossObj,0,64,64,128);}
			if(f2>=5 && f2<10){ObjSprite2D_SetSourceRect(bossObj,64,64,128,128);}
			if(f2>=10 && f2<15){ObjSprite2D_SetSourceRect(bossObj,128,64,192,128);}
			
			f2++;
			f=0;
			f3=0;
			if(f == 20){
				f = 0;
			}
		}
		
		else if(cos(dir) < 0 && speed > 0){
		ObjRender_SetScaleXYZ(bossObj,1,1,1);
		ObjRender_SetAngleY(bossObj,180);
			if(f3<5){ObjSprite2D_SetSourceRect(bossObj,0,64,64,128);}
			if(f3>=5 && f3<10){ObjSprite2D_SetSourceRect(bossObj,64,64,128,128);}
			if(f3>=10 && f3<15){ObjSprite2D_SetSourceRect(bossObj,128,64,192,128);}
			
			f2=0;
			f=0;
			f3++;
		}
		
		else{
		ObjRender_SetScaleXYZ(bossObj,1,1,1);
			if(f<5){ObjSprite2D_SetSourceRect(bossObj,0,0,64,64);}
			if(f>=5 && f<10){ObjSprite2D_SetSourceRect(bossObj,64,0,128,64);}
			if(f>=10 && f<15){ObjSprite2D_SetSourceRect(bossObj,128,0,192,64);}
			if(f>=15 && f<20){ObjSprite2D_SetSourceRect(bossObj,192,0,256,64);}
			
			f2=0;
			f3=0;
			if(f == 20){
				f = 0;
			}
			f++;
		}
		
		yield;
	}
	Obj_Delete(auraObj);
	Obj_Delete(bossObj);
	
}

task Name{

	let textObj = ObjText_Create;
	let spin = 0;
	let p = 255*sin(spin);
	
	ObjText_SetText(textObj, "Kanako Yasaka");
	ObjText_SetFontSize(textObj, 14);
	Obj_SetRenderPriorityI(textObj,70);
	ObjText_SetFontBorderType(textObj,BORDER_SHADOW);
	ObjText_SetFontBorderWidth(textObj,1);
	ObjText_SetFontBorderColor(textObj,255,255,255);
	ObjText_SetFontColorTop(textObj, 255, 0, 0);
	ObjText_SetFontColorBottom(textObj, 0, 0, 0);
	ObjRender_SetPosition(textObj,32,16,0);
	loop(128){
	spin+=1;
	p = 255*sin(spin);
	ObjRender_SetAlpha(textObj,p);
	yield;
	}
	while(!Obj_IsDeleted(bossObj)){
	yield;
	}
	Obj_Delete(textObj);
}

task CutIn(text){
	let textObj = ObjText_Create;
	let finalx = 374;
	let finaly = 25;
	let spin = 0;
	let e = 255*sin(spin);
	let t = 255*sin(spin);
	
	SCAttack;
	ObjText_SetText(textObj,text);
	ObjText_SetFontSize(textObj,12);
	ObjText_SetFontColorTop(textObj,247,148,29);
	ObjText_SetFontColorBottom(textObj,255,255,255);
	ObjText_SetFontBorderType(textObj,BORDER_SHADOW);
	ObjText_SetFontBorderWidth(textObj,1);
	ObjText_SetFontBorderColor(textObj,200,10,70);
	ObjText_SetHorizontalAlignment(textObj,ALIGNMENT_CENTER);
	ObjText_SetMaxWidth(textObj,300);
	ObjRender_SetBlendType(textObj,BLEND_ALPHA);
	Obj_SetRenderPriorityI(textObj,70);
	ObjText_SetAutoTransCenter(textObj,true);
	
	let spellObj = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(spellObj,69);
	ObjPrim_SetTexture(spellObj,GetCurrentScriptDirectory ~ "IMG/spellbar.png");
	ObjRender_SetBlendType(spellObj,BLEND_ALPHA);
	ObjRender_SetAlpha(spellObj,0);
	ObjSprite2D_SetSourceRect(spellObj,0,0,256,38);
	ObjSprite2D_SetSourceRect(spellObj,0,0,256,38);
	ObjSprite2D_SetDestCenter(spellObj);
	ObjRender_SetScaleXYZ(spellObj,1,1,1);
	
	loop(250){
		spin+=1;
		e = 255*sin(spin);
		ObjRender_SetPosition(spellObj,ObjRender_GetX(textObj)+150,ObjRender_GetY(textObj),0);
		ObjRender_SetPosition(textObj,GetScreenWidth/2-150,GetScreenHeight/2-5,0);
		ObjRender_SetAlpha(textObj,e);
		yield;
	}
	
	loop(128){
		spin+=0.01;
		t = 255*sin(spin*128);
		ObjText_SetHorizontalAlignment(textObj,ALIGNMENT_RIGHT);
		ObjText_SetMaxWidth(textObj,300);
		ObjRender_SetPosition(spellObj,ObjRender_GetX(textObj)+128,ObjRender_GetY(textObj)+1,0);
		ObjRender_SetPosition(textObj,finalx-64,finaly,0);
		ObjRender_SetAlpha(textObj,t);
		ObjRender_SetAlpha(spellObj,t);
		yield;
	}
	
	while(!Obj_IsDeleted(bossObj) && ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID,INFO_IS_SPELL)){
		yield;
	}
	Obj_Delete(textObj);
	Obj_Delete(spellObj);
}

task SCAttack{
	let i = 0;
	let x = 0;
	let dir = 0;
	let spin = 0;
	let a = 8;
	let p = 200*sin(dir);
	let t = 105*sin(dir);
	let spell = CSD ~ "./se/cardcall.wav";
	
	Play(spell);
	
	dark;
	ascent(i in 0..7){
		loop(a){
			scattack(GetScreenWidth/2,GetScreenHeight/2,140+i*60,dir);
			scattack2(GetScreenWidth/2,GetScreenHeight/2,170+i*60,dir);

			x++;
			dir+=360/a;
		}
		dir = 0;
		x = 0;
	}
	
	task scattack(x,y,w,l){
		let scObj = ObjPrim_Create(OBJ_SPRITE_2D);
		
		ObjPrim_SetTexture(scObj,GetCurrentScriptDirectory ~ "img/SCA.png");
		ObjSprite2D_SetDestRect(scObj,0,0,128,16);
		ObjSprite2D_SetSourceRect(scObj,0,0,128,16);
		ObjSprite2D_SetDestCenter(scObj);
		ObjRender_SetBlendType(scObj,BLEND_ALPHA);
		ObjRender_SetAlpha(scObj,155);
		loop(255){
		spin+=0.02;
		dir+=360/a;
		p = 200*sin(spin/1.5);
		ObjRender_SetPosition(scObj,x+w*cos(dir+spin),y+w*sin(dir+spin),0);
		ObjRender_SetAngleXYZ(scObj,0,0,dir+spin+90);
		ObjRender_SetScaleXYZ(scObj,1,1,1);
		ObjRender_SetAlpha(scObj,p);
		yield;
		}
		Obj_Delete(scObj);
	}
	
	task scattack2(x,y,w,l){
		let scObj = ObjPrim_Create(OBJ_SPRITE_2D);
		
		ObjPrim_SetTexture(scObj,GetCurrentScriptDirectory ~ "img/SCA.png");
		ObjSprite2D_SetDestRect(scObj,0,0,128,16);
		ObjSprite2D_SetSourceRect(scObj,0,0,128,16);
		ObjSprite2D_SetDestCenter(scObj);
		ObjRender_SetBlendType(scObj,BLEND_ALPHA);
		ObjRender_SetAlpha(scObj,155);
		loop(255){
		ObjRender_SetPosition(scObj,x+w*cos(dir-spin),y+w*sin(dir-spin),0);
		ObjRender_SetAngleXYZ(scObj,180,180,dir-spin-90);
		ObjRender_SetScaleXYZ(scObj,1,1,1);
		ObjRender_SetAlpha(scObj,p);
		yield;
		}
		Obj_Delete(scObj);
	}
	
	task dark{
		let scObj = ObjPrim_Create(OBJ_SPRITE_2D);
		let scObj2 = ObjPrim_Create(OBJ_SPRITE_2D);
		
		ObjPrim_SetTexture(scObj2,GetCurrentScriptDirectory ~ "img/SCAlay.png");
		ObjSprite2D_SetDestRect(scObj2,0,0,2000,2000);
		ObjSprite2D_SetSourceRect(scObj2,0,0,2000,2000);
		ObjSprite2D_SetDestCenter(scObj2);
		ObjRender_SetBlendType(scObj2,BLEND_ALPHA);
		ObjRender_SetAlpha(scObj2,25);
		
		ObjPrim_SetTexture(scObj,GetCurrentScriptDirectory ~ "img/SCAlay.png");
		ObjSprite2D_SetDestRect(scObj,0,0,2000,2000);
		ObjSprite2D_SetSourceRect(scObj,0,0,2000,2000);
		ObjSprite2D_SetDestCenter(scObj);
		ObjRender_SetBlendType(scObj,BLEND_ALPHA);
		ObjRender_SetAlpha(scObj,25);
		
		loop(510){
		t = 115*sin(spin/1.5);
		ObjRender_SetPosition(scObj,GetScreenWidth/2,GetScreenHeight/2,0);
		ObjSprite2D_SetDestRect(scObj,0,0,2000,2000-spin*2);
		ObjSprite2D_SetSourceRect(scObj,0,0,2000,2000-spin*2);
		ObjSprite2D_SetDestCenter(scObj);
		ObjRender_SetScaleXYZ(scObj,0.4,0.4,0.4);
		ObjRender_SetAlpha(scObj,t);
		
		ObjRender_SetPosition(scObj2,GetScreenWidth/2,GetScreenHeight/2,0);
		ObjRender_SetScaleXYZ(scObj2,0.4,0.4,0.4);
		ObjSprite2D_SetDestRect(scObj2,0,0,2000,2000+spin*2);
		ObjSprite2D_SetSourceRect(scObj2,0,0,2000,2000+spin*2);
		ObjSprite2D_SetDestCenter(scObj2);
		ObjRender_SetAlpha(scObj2,t);
		yield;
		}
		Obj_Delete(scObj);
	}
}

function Play(path){
	LoadSound(path);
	PlaySE(path);
}

// This Function is from Darkness1's Function Library. Thanks!
function RandMove(ObjID, Xdist, Ydist, moveweight, maxispeed, left_bound, top_bound, right_bound, bottom_bound){
let setrand;
let Xdir;
let Ydir;


setrand = rand(0,360);

if( ObjMove_GetX(ObjID)>(right_bound-Xdist) ){
setrand = rand(200,250);}

if( ObjMove_GetX(ObjID)<(left_bound+Xdist) ){
setrand = rand(-70,70);}


Xdir = ObjMove_GetX(ObjID)+cos(setrand)*(Xdist);
Ydir = ObjMove_GetY(ObjID)+sin(setrand)*(Ydist);


if(Xdir>right_bound){Xdir = right_bound;}
if(Xdir<left_bound){Xdir = left_bound;}
if(Ydir>bottom_bound){Ydir = bottom_bound;}
if(Ydir<top_bound){Ydir = top_bound;}



ObjMove_SetDestAtWeight(ObjID, Xdir, Ydir, moveweight, maxispeed);}
