// Boss animation by Awalys. (Patchouli)

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

let Attack = false;

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

task BossRender{
	let dir;
	let speed; 

    ObjPrim_SetTexture(objBoss, img);
	ObjSprite2D_SetSourceRect(objBoss,0,0,32,72);
	ObjSprite2D_SetDestCenter(objBoss);
	ObjRender_SetScaleXYZ(objBoss, 1.25, 1.25, 0);
	
	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,48,32,33+53,68+35); }
			if(idleFrame >= 15 && idleFrame < 30) { ObjSprite2D_SetSourceRect(objBoss,48,32+(127*1),33+53,68+35+(127*1)); }
			if(idleFrame >= 30 && idleFrame < 45) { ObjSprite2D_SetSourceRect(objBoss,48,32+(127*2),33+53,68+35+(127*2)); }
			if(idleFrame >= 45 && idleFrame < 60) { ObjSprite2D_SetSourceRect(objBoss,48,32+(127*1),33+53,68+35+(127*1)); }
			if(idleFrame >= 60) { ObjSprite2D_SetSourceRect(objBoss,48,32,33+53,68+35); }
			moveFrame = 0;
		}
		else if(cos(dir) > 0){ 
			ObjRender_SetAngleXYZ(objBoss,0,0,0);
			if(moveFrame < 15) { ObjSprite2D_SetSourceRect(objBoss,48+(127*1),32,33+53+(127*1),68+35); }
			if(moveFrame >= 15 && moveFrame < 30) { ObjSprite2D_SetSourceRect(objBoss,48+(127*1),32,33+53+(127*1),68+35); }
			if(moveFrame >= 30 && moveFrame < 45) { ObjSprite2D_SetSourceRect(objBoss,48+(127*2),32+(127*2),33+53+(127*2),68+35+(127*2)); }
			if(moveFrame >= 45) { ObjSprite2D_SetSourceRect(objBoss,48+(127*2),32+(127*3),33+53+(127*2),68+35+(127*3)); }
		}
		else if(cos(dir) < 0){ 
			ObjRender_SetAngleXYZ(objBoss,0,0,0);
			if(moveFrame < 15) { ObjSprite2D_SetSourceRect(objBoss,48+(127*1),32,33+53+(127*1),68+35); }
			if(moveFrame >= 15 && moveFrame < 30) { ObjSprite2D_SetSourceRect(objBoss,48+(127*1),32,33+53+(127*1),68+35); }
			if(moveFrame >= 30 && moveFrame < 45) { ObjSprite2D_SetSourceRect(objBoss,48+(127*2),32,33+53+(127*2),68+35); }
			if(moveFrame >= 45) { ObjSprite2D_SetSourceRect(objBoss,48+(127*2),32+(127*1),33+53+(127*2),68+35+(127*1)); }
		}
		if(Attack){ 
			ObjRender_SetAngleXYZ(objBoss,0,0,0);
			if(attackFrame < 15) { ObjSprite2D_SetSourceRect(objBoss,48+(127*4),32+(127*0),33+53+(127*4),68+35+(127*0)); }
			if(attackFrame >= 15 && attackFrame < 30) { ObjSprite2D_SetSourceRect(objBoss,48+(127*4),32+(127*1),33+53+(127*4),68+35+(127*1)); }
			if(attackFrame >= 30 && attackFrame < 45) { ObjSprite2D_SetSourceRect(objBoss,48+(127*4),32+(127*2),33+53+(127*4),68+35+(127*2)); }
			if(attackFrame >= 45) { ObjSprite2D_SetSourceRect(objBoss,48+(127*4),27+(127*3),36+53+(127*4),68+35+(127*3)); }
		}
		idleFrame=idleFrame+1;
		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;
	}
}

task TojikoRender(objTojiko){
	let dir;
	let speed; 
	let img = GetCurrentScriptDirectory ~ "../img/tojikosprite.png";

    ObjPrim_SetTexture(objTojiko, img);
	ObjSprite2D_SetSourceRect(objTojiko,0,0,28,64);
	ObjSprite2D_SetDestCenter(objTojiko);
	ObjRender_SetScaleXYZ(objTojiko, 1.25, 1.25, 0);
	
	while(!Obj_IsDeleted(objTojiko)) {
	
		dir = ObjMove_GetAngle(objTojiko);
		speed = ObjMove_GetSpeed(objTojiko);
		
		if(speed == 0){ 
			ObjRender_SetAngleXYZ(objTojiko,0,0,0);
			if(idleFrame < 15) { ObjSprite2D_SetSourceRect(objTojiko,48,32,28+53,61+35); }
			if(idleFrame >= 15 && idleFrame < 30) { ObjSprite2D_SetSourceRect(objTojiko,48,32+(127*1),28+53,61+35+(127*1)); }
			if(idleFrame >= 30 && idleFrame < 45) { ObjSprite2D_SetSourceRect(objTojiko,48,32+(127*2),28+53,61+35+(127*2)); }
			if(idleFrame >= 45 && idleFrame < 60) { ObjSprite2D_SetSourceRect(objTojiko,48,32+(127*1),28+53,61+35+(127*1)); }
			if(idleFrame >= 60) { ObjSprite2D_SetSourceRect(objTojiko,48,32,28+53,61+35); }
			moveFrame = 0;
		}
		else if(cos(dir) > 0){ 
			ObjRender_SetAngleXYZ(objTojiko,0,0,0);
			if(moveFrame < 15) { ObjSprite2D_SetSourceRect(objTojiko,48+(127*1),32,28+53+(127*1),61+35); }
			if(moveFrame >= 15 && moveFrame < 30) { ObjSprite2D_SetSourceRect(objTojiko,48+(127*1),32,28+53+(127*1),61+35); }
			if(moveFrame >= 30 && moveFrame < 45) { ObjSprite2D_SetSourceRect(objTojiko,48+(127*2),32+(127*2),28+53+(127*2),61+35+(127*2)); }
			if(moveFrame >= 45) { ObjSprite2D_SetSourceRect(objTojiko,48+(127*2),32+(127*3),28+53+(127*2),61+35+(127*3)); }
		}
		else if(cos(dir) < 0){ 
			ObjRender_SetAngleXYZ(objTojiko,0,0,0);
			if(moveFrame < 15) { ObjSprite2D_SetSourceRect(objTojiko,48+(127*1),32,28+53+(127*1),61+35); }
			if(moveFrame >= 15 && moveFrame < 30) { ObjSprite2D_SetSourceRect(objTojiko,48+(127*1),32,28+53+(127*1),61+35); }
			if(moveFrame >= 30 && moveFrame < 45) { ObjSprite2D_SetSourceRect(objTojiko,48+(127*2),32,28+53+(127*2),61+35); }
			if(moveFrame >= 45) { ObjSprite2D_SetSourceRect(objTojiko,48+(127*2),32+(127*1),28+53+(127*2),61+35+(127*1)); }
		}
		idleFrame=idleFrame+1;
		moveFrame=moveFrame+1;
		if(idleFrame > 60) { idleFrame = 0; }
		if(moveFrame > 60) { moveFrame = 45; }
		
		yield;
	}
}

task FutoRender(objFuto){ // Futo didn't get to be animated ;-;
	let dir;
	let speed; 
	let img = GetCurrentScriptDirectory ~ "../img/futosprite.png";

    ObjPrim_SetTexture(objFuto, img);
	ObjSprite2D_SetSourceRect(objFuto,0,0,128,128);
	ObjSprite2D_SetDestCenter(objFuto);
	ObjRender_SetScaleXYZ(objFuto, 1.25, 1.25, 0);
}