// Boss animation by Awalys. Sprites by KMAP. (Flandre)

let idleFrame = 0;
let moveFrame = 0;
let attackFrame = 0;

let Attack = false;

let img = GetCurrentScriptDirectory ~ "../img/dot_aya.png";

task BossRender{
	let dir;
	let speed; 

    ObjPrim_SetTexture(objBoss, img);
	ObjSprite2D_SetSourceRect(objBoss,0,0,128,128);
	ObjSprite2D_SetDestCenter(objBoss);
	ObjRender_SetScaleXYZ(objBoss, 1, 1, 0); 
	ShaderTask_SetPointFilterMode(objBoss, img);
	
	while(!Obj_IsDeleted(objBoss)) {
	
		dir = ObjMove_GetAngle(objBoss);
		speed = ObjMove_GetSpeed(objBoss);
		
		if(speed == 0){ 
			ObjRender_SetAngleXYZ(objBoss,0,0,0);
			if(idleFrame < 15) { ObjSprite2D_SetSourceRect(objBoss,0,0,128,128); }
			if(idleFrame >= 15 && idleFrame < 30) { ObjSprite2D_SetSourceRect(objBoss,0,128,128,128*2); }
			if(idleFrame >= 30 && idleFrame < 45) { ObjSprite2D_SetSourceRect(objBoss,0,128*2,128,128*3); }
			if(idleFrame >= 45 && idleFrame < 60) { ObjSprite2D_SetSourceRect(objBoss,0,128,128,128*2); }
			if(idleFrame >= 60) { ObjSprite2D_SetSourceRect(objBoss,0,0,128,128); }
			moveFrame = 0;
		}
		else if(cos(dir) > 0){ 
			ObjRender_SetAngleXYZ(objBoss,0,0,0);
			if(moveFrame < 15) { ObjSprite2D_SetSourceRect(objBoss,128*2,128*2,128*3,128*3); }
			if(moveFrame >= 15 && moveFrame < 30) { ObjSprite2D_SetSourceRect(objBoss,128*2,128*2,128*3,128*3); }
			if(moveFrame >= 30 && moveFrame < 45) { ObjSprite2D_SetSourceRect(objBoss,128*2,128*3,128*3,128*4); }
			if(moveFrame >= 45) { ObjSprite2D_SetSourceRect(objBoss,128*2,128*3,128*3,128*4); }
		}
		else if(cos(dir) < 0){ 
			ObjRender_SetAngleXYZ(objBoss,0,0,0);
			if(moveFrame < 15) { ObjSprite2D_SetSourceRect(objBoss,128*2,0,128*3,128); }
			if(moveFrame >= 15 && moveFrame < 30) { ObjSprite2D_SetSourceRect(objBoss,128*2,0,128*3,128); }
			if(moveFrame >= 30 && moveFrame < 45) { ObjSprite2D_SetSourceRect(objBoss,128*2,128,128*3,128*2); }
			if(moveFrame >= 45) { ObjSprite2D_SetSourceRect(objBoss,128*2,128,128*3,128*2); }
		}
		if(Attack){ 
			ObjRender_SetAngleXYZ(objBoss,0,0,0);
			if(attackFrame < 15) { ObjSprite2D_SetSourceRect(objBoss,128*5,0,128*6,128); }
			if(attackFrame >= 15 && attackFrame < 30) { ObjSprite2D_SetSourceRect(objBoss,128*5,128,128*6,128*2); }
			if(attackFrame >= 30 && attackFrame < 45) { ObjSprite2D_SetSourceRect(objBoss,128*5,128*2,128*6,128*3); }
			if(attackFrame >= 45) { ObjSprite2D_SetSourceRect(objBoss,128*5,128*2,128*6,128*3); }
		}
		idleFrame=idleFrame+2;
		moveFrame=moveFrame+2;
		attackFrame=attackFrame+2;
		if(idleFrame > 60) { idleFrame = 0; }
		if(attackFrame > 45) { attackFrame = 30; }
		if(Attack == false) { attackFrame = 0; }
		if(moveFrame > 60) { moveFrame = 45; }
		
		yield;
	}
}