InstallFont(GetCurrentScriptDirectory ~ "./../Lib/RussoOne-Regular.ttf");

task CutIn(text){
	CutInText(text);
	SetCommonData("Is Spell?",true);
}

task CutInText(text){
	
	let textObj = ObjText_Create;
	ObjText_SetText(textObj,text);
	ObjText_SetFontType(textObj,"Russo One");
	
	ObjText_SetFontSize(textObj,18);
	ObjText_SetFontColorTop(textObj,255,255,255);
	ObjText_SetFontColorBottom(textObj,255,255,255);
	ObjText_SetFontBorderColor(textObj,0,0,0);
	ObjText_SetFontBorderType(textObj,BORDER_FULL);
	ObjText_SetFontBorderWidth(textObj,1);
	ObjRender_SetAlpha(textObj,255);
	
	ObjText_SetMaxWidth(textObj,GetStgFrameWidth-4);
	ObjText_SetHorizontalAlignment(textObj,ALIGNMENT_CENTER);
	ObjRender_SetBlendType(textObj,BLEND_ALPHA);
	Obj_SetRenderPriorityI(textObj,61);
	ObjText_SetAutoTransCenter(textObj,true);
	ObjRender_SetPosition(textObj,-GetStgFrameWidth,GetStgFrameHeight-96,0);
	
	ascent(i in 0..38){
		ObjRender_SetPosition(textObj,ObjRender_GetX(textObj)+18.7-i/2,GetStgFrameHeight-96,0);
		yield;
	}
	ascent(i in 0..100){
		ObjRender_SetPosition(textObj,ObjRender_GetX(textObj)+0.5,GetStgFrameHeight-96,0);
		yield;
	}
	
	ascent(i in 0..38){
		ObjRender_SetPosition(textObj,ObjRender_GetX(textObj)+i/2,GetStgFrameHeight-96,0);
		yield;
	}
	wait(20);
	
	CutInBar;
	ascent(i in 0..64){
		ObjText_SetHorizontalAlignment(textObj,ALIGNMENT_RIGHT);
		ObjRender_SetPosition(textObj,0,32,0);
		ObjRender_SetAlpha(textObj,i*4);
		yield;
	}
	ObjRender_SetAlpha(textObj,255);
	
	while(!Obj_IsDeleted(bossObj) && ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID,INFO_IS_SPELL) == true){
		yield;
	}
	Obj_Delete(textObj);
}

task CutInBar{
	let path = GetCurrentScriptDirectory ~ "./Effects/img/SpellTitleBar.png";
	let spellObj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(spellObj,path);
	
	ObjSprite2D_SetSourceRect(spellObj,0,0,512,512);
	ObjSprite2D_SetDestCenter(spellObj);
	ObjRender_SetBlendType(spellObj,BLEND_ALPHA);
	ObjRender_SetAlpha(spellObj,0);
	ObjRender_SetScaleXYZ(spellObj,0.75,0.75,0);
	Obj_SetRenderPriorityI(spellObj,60);
	
	ascent(i in 0..64){
		ObjRender_SetPosition(spellObj,GetStgFrameWidth/2,36,0);
		ObjRender_SetAlpha(spellObj,i*4);
		yield;
	}
	ObjRender_SetAlpha(spellObj,255);
	
	while(!Obj_IsDeleted(bossObj) && ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID,INFO_IS_SPELL) == true){
		yield;
	}
	Obj_Delete(spellObj);
}

task Timeout{
	yield;
	while(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID,INFO_TIMER) > 10){
		yield;
	}
	loop(5){
		PlaySnd("se_timeout",70);
		wait(60);
	}
	loop(6){
		PlaySnd("se_timeout2",70);
		wait(60);
	}
}

//--------------------------------------------------------------------------------------------------------------------
// THIS IS ALL FAULTY. DO NOT USE.

task go(size,vc,speed,rad){
	let vertexcount = vc; //You're actually not making a circle. You're making a polygon with a ton of sides. This is how many sides. The more sides you have the less blocky it'll look, but the more lag you'll have. MAKE SURE THIS IS AN EVEN NUMBER.
	let texture = CSD ~ "./Effects/img/SpellcardAttack.png";
	 
	let x = GetStgFrameWidth/2; //The x position for the center of your circle.
	let y = GetStgFrameHeight; //The y position for the center of your circle.
	let innerrad = rad; // the inner radius of your circle. If it's 0 it'll be a circle. Anything larger will make a donut-like shape.
	let outerrad = rad/2-128; //the outer radius of your circle.
	 
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP); //This is too much to explain up here*
	ObjPrim_SetTexture(obj,texture); //Obviously "texture" is your texture :V
	ObjPrim_SetVertexCount(obj, vertexcount);
	 
	ascent(i in 0..vertexcount/2){
		let indexvert = i*2;
		let angle = i*360/(vertexcount*0.5-1);
	 
		ObjPrim_SetVertexPosition(obj,indexvert+0,x+innerrad*cos(angle),y+innerrad*sin(angle),0); //sets the position for you "inner circle" (it'll be the center of the circle if innerrad = 0). You're setting the position for each even Point.
		ObjPrim_SetVertexPosition(obj,indexvert+1,x+outerrad*cos(angle),y+outerrad*sin(angle),0); //sets the position for you "outer circle). Now you're setting the position for each odd Point.

		ObjPrim_SetVertexUVT(obj,indexvert+0,i*(size)/(vertexcount*1/2-1),0); //This is also too much to explain up here**
		ObjPrim_SetVertexUVT(obj,indexvert+1,i*(size)/(vertexcount*1/2-1),(256)); //This is also too much to explain up here**
		twist;
		
		task twist{
			let spin = 0;
			loop{
			ObjPrim_SetVertexPosition(obj,indexvert+0,x+innerrad*cos(angle+spin),y+innerrad*sin(angle+spin),0); //sets the position for you "inner circle" (it'll be the center of the circle if innerrad = 0). You're setting the position for each even Point.
			ObjPrim_SetVertexPosition(obj,indexvert+1,x+outerrad*cos(angle+spin),y+outerrad*sin(angle+spin),0); //sets the position for you "outer circle). Now you're setting the position for each odd Point.
			spin+=speed;
			yield;
			}
		}
    }
	
}

function CreateSpellcardObject{
	let path = GetCurrentScriptDirectory ~ "./Effects/img/sc_attack2.png";
	let spellObj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(spellObj,path);
	
	ObjSprite2D_SetSourceRect(spellObj,0,0,256,256);
	ObjSprite2D_SetDestCenter(spellObj);
	ObjRender_SetBlendType(spellObj,BLEND_ALPHA);
	ObjRender_SetAlpha(spellObj,255);
	ObjRender_SetScaleXYZ(spellObj,1,1,0);
	Obj_SetRenderPriorityI(spellObj,60);
	return spellObj;
}

task foo{
	let obj_arr = [];
	
	let base_x = GetStgFrameWidth/2;
	let base_y = GetStgFrameHeight/2;
	let levels = 6;
	
	let base_radius = 0;
	let increment_value = 40;
	let base_angle = 270;

	
	
	ascent(i in 0..levels){
		//create the sprites here and append them to the array via obj_arr = obj_arr ~ [sprite id];
		let obj = CreateSpellcardObject;
		obj_arr = obj_arr ~ [obj];
	}
	
	
	while(1){
		ascent(i in 0..levels){
			let radius = base_radius+ increment_value*i;
			let angle = base_angle*sin(180*i+90);
			ObjRender_SetPosition(obj_arr[i],base_x + radius * cos(angle), base_y + radius * sin(angle),0);
			ObjRender_SetAngleZ(obj_arr[i],base_angle*sin(180*i+90) + 90);
		}
		base_angle++;
		yield;
	}
}