let concen = false;
let spellact = false;
let survivalcard = false;

//wait -- --- -----
function wait(n){loop(n){yield;}}

//Get Center -- --- -----
function GetCenterX(){
    return GetStgFrameWidth() / 2;
}
function GetCenterY(){
    return GetStgFrameHeight() / 2;
}

//Boss Animations -- --- -----
task BossRender {
	let imgBoss = GetCurrentScriptDirectory ~ "img/Ad. Yi Spritesheet.png";
	ObjPrim_SetTexture(bossObj, imgBoss);
	ObjSprite2D_SetSourceRect(bossObj, 0, 0, 128, 128);
	ObjSprite2D_SetDestCenter(bossObj);
	ObjRender_SetScaleXYZ(bossObj, 1.10, 1.10, 0);
	if(survivalcard==true){ObjRender_SetAlpha(bossObj, 10);}
	else{ObjRender_SetAlpha(bossObj, 255);}
	let dir;
	let speed;
	
	// texture the boss, set center as true center.
	ObjPrim_SetTexture(bossObj,imgBoss);
	ObjSprite2D_SetSourceRect(bossObj,0,94,94,188);
	ObjSprite2D_SetDestCenter(bossObj);	
	
	while(!Obj_IsDeleted(bossObj)) {
		
		// update boss speed and direction locally
		dir = ObjMove_GetAngle(bossObj);
		speed = ObjMove_GetSpeed(bossObj);
		
		// if the boss is idle, show this image / note: rect(left, top, right, bottom)
		if(speed == 0) { ObjSprite2D_SetSourceRect(bossObj,0, 0, 94, 94);} 			// IDLE
		else if(cos(dir) < 0) {  ObjSprite2D_SetSourceRect(bossObj,188, 0,282, 94); } 	// LEFT
		else if(cos(dir) > 0) { ObjSprite2D_SetSourceRect(bossObj,94, 0,188, 94); } 	// RIGHT
		//Also, the sprite sheet for Yi mixed the left and right movement sprite. That was my fault.
		yield;
	}
	}//credits to Helepolis' tutorials

task BossSpell(time){
spellact = true;
// note: rect(left, top, right, bottom) 
//Also, Using arthimetic equations because I'm a bit lazy
loop(4){ObjSprite2D_SetSourceRect(bossObj, 0, 94, 94, 94*2); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94, 94, 94*2, 94*2); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94*2, 94, 94*3, 94*2); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94*3, 94, 94*4, 94*2); yield;}
loop(time){ObjSprite2D_SetSourceRect(bossObj, 94*4, 94, 94*5, 94*2); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94*3, 94, 94*4, 94*2); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94*2, 94, 94*3, 94*2); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94, 94, 94*2, 94*2); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 0, 94, 94, 94*2); yield;}
spellact = false;
}

task BossConcentrateA1(timeA,timeB){
 concen = true;
 
// note: rect(left, top, right, bottom) 
loop(4){ObjSprite2D_SetSourceRect(bossObj, 1, 94, 94, 94*2); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94, 94, 94*2, 94*2); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94*2, 94, 94*3, 94*2); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94*3, 94, 94*4, 94*2); yield;}
loop(timeA){ObjSprite2D_SetSourceRect(bossObj, 1, 94*2, 94, 94*3); yield;}
loop(1){ObjSprite2D_SetSourceRect(bossObj, 94, 94*2, 94*2, 94*3); yield;}
loop(1){ObjSprite2D_SetSourceRect(bossObj, 94*2, 94*2, 94*3, 94*3); yield;}
loop(1){ObjSprite2D_SetSourceRect(bossObj, 94*3, 94*2, 94*4, 94*3); yield;}
loop(1){ObjSprite2D_SetSourceRect(bossObj, 94*4, 94*2, 94*5, 94*3); yield;}
loop(timeB){ObjSprite2D_SetSourceRect(bossObj, 94*5, 94*2, 94*6, 94*3); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94, 94*3, 94*2, 94*4); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94*2, 94*3, 94*3, 94*4); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94*3, 94*3, 94*4, 94*4); yield;}
concen = false;
}

task BossConcentrateA2(timeA,timeB){
 concen = true;
// note: rect(left, top, right, bottom) 
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94*3, 94*3, 94*4, 94*4); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94*2, 94*3, 94*3, 94*4); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94, 94*3, 94*2, 94*4); yield;}
loop(timeA){ObjSprite2D_SetSourceRect(bossObj, 94*5, 94*2, 94*6, 94*3); yield;}
loop(1){ObjSprite2D_SetSourceRect(bossObj, 94*4, 94*2, 94*5, 94*3); yield;}
loop(1){ObjSprite2D_SetSourceRect(bossObj, 94*3, 94*2, 94*4, 94*3); yield;}
loop(1){ObjSprite2D_SetSourceRect(bossObj, 94*2, 94*2, 94*3, 94*3); yield;}
loop(1){ObjSprite2D_SetSourceRect(bossObj, 94, 94*2, 94*2, 94*3); yield;}
loop(timeB){ObjSprite2D_SetSourceRect(bossObj, 1, 94*2, 94, 94*3); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94*3, 94, 94*4, 94*2); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94*2, 94, 94*3, 94*2); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94, 94, 94*2, 94*2); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 1, 94, 94, 94*2); yield;}

concen = false;
}

task BossConcentrateB1(timeA){
 concen = true;
// note: rect(left, top, right, bottom) 
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94, 94*4, 94*2, 94*5); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94*2, 94*4, 94*3, 94*5); yield;}
loop(timeA){ObjSprite2D_SetSourceRect(bossObj, 94*3, 94*4, 94*4, 94*5); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94*2, 94*4, 94*3, 94*5); yield;}
loop(4){ObjSprite2D_SetSourceRect(bossObj, 94, 94*4, 94*2, 94*5); yield;}
concen = false;
}

//Stage stuff -- --- -----