let imgBoss = GetCurrentScriptDirectory ~ "./img/kanako.png";
let imgBoss2 = GetCurrentScriptDirectory ~ "./img/kanakoinvis.png";

let attack = false;
let invisible = false;
task renderkanako(tar){
	let move = false;
	let dir = 0;
	let speed = 0;
	let frame = 0;
	let mframe = 0;
	let aframe = 0;
	let rframe = 8;
	let bob = 0;
	let x = 64;
	let y = 64;
	let invischeck = invisible;
	
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	
	ObjRender_SetAlpha(obj,255);
	ObjPrim_SetTexture(obj,imgBoss);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	while(!Obj_IsDeleted(obj)){	
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetAngleXYZ(obj,0,0,GetCommonData("BossAngle",0));

	let BossX = ObjMove_GetX(objBoss);
	let BossY = ObjMove_GetY(objBoss);

	if(invisible==true && invischeck!=invisible){ObjPrim_SetTexture(obj,imgBoss2);}
	if(invisible==false && invischeck!=invisible){ObjPrim_SetTexture(obj,imgBoss);}	
	invischeck = invisible;
	
		dir = ObjMove_GetAngle(tar);
		speed = ObjMove_GetSpeed(tar);
		
		if(speed==0){
			if(attack == true) {aframe++;
			if(aframe <= 2) {ObjSprite2D_SetSourceRect(obj,0,y*2,x,y*3);}
			if(aframe >= 2) {ObjSprite2D_SetSourceRect(obj,x,y*2,x*2,y*3);}
			if(aframe >= 4) {ObjSprite2D_SetSourceRect(obj,x*2,y*2,x*3,y*3);}
			if(aframe >= 6) {ObjSprite2D_SetSourceRect(obj,x*3,y*2,x*4,y*3);}
			if(aframe >= 8) {ObjSprite2D_SetSourceRect(obj,0,y*3,x,y*4);}
			if(aframe >= 10) {ObjSprite2D_SetSourceRect(obj,x,y*3,x*2,y*4);}
			if(aframe >= 12) {ObjSprite2D_SetSourceRect(obj,x*2,y*3,x*3,y*4);}
			if(aframe >= 14) {ObjSprite2D_SetSourceRect(obj,x*3,y*3,x*4,y*4);}
			if(aframe >= 16) {aframe-=8;}
			}	
			if(attack == false) {
			if(frame <= 4) {ObjSprite2D_SetSourceRect(obj,0,0,x,y);}
			if(frame >= 4) {ObjSprite2D_SetSourceRect(obj,x,0,x*2,y);}
			if(frame >= 8) {ObjSprite2D_SetSourceRect(obj,x*2,0,x*3,y);}
			if(frame >= 12) {ObjSprite2D_SetSourceRect(obj,x*3,0,x*4,y);}
			mframe=0;
			aframe=0;
			//rframe=0;
			}
			if(move == true && attack == false){ rframe++;
			if(rframe <= 8) {ObjSprite2D_SetSourceRect(obj,x*3,y,x*4,y*2);}
			if(rframe >= 8) {ObjSprite2D_SetSourceRect(obj,x*2,y,x*3,y*2);}
			if(rframe >= 12) {ObjSprite2D_SetSourceRect(obj,x,y,x*2,y*2);}
			if(rframe >= 14) {move = false;}
			}
			if(move==false){rframe=8;}
		}			
		
		else if(cos(dir) > 0) {mframe++;
        if(mframe <= 4) {ObjSprite2D_SetSourceRect(obj,0,y,x,y*2);}
        if(mframe >= 4) {ObjSprite2D_SetSourceRect(obj,x,y,x*2,y*2);}
		if(mframe >= 8) {ObjSprite2D_SetSourceRect(obj,x*2,y,x*3,y*2);}
		move = true;
        }
		
		else if(cos(dir) < 0) {mframe++;
		ObjRender_SetAngleXYZ(obj,0,180,GetCommonData("BossAngle",0));
        if(mframe <= 4) {ObjSprite2D_SetSourceRect(obj,0,y,x,y*2);}
        if(mframe >= 4) {ObjSprite2D_SetSourceRect(obj,x,y,x*2,y*2);}
		if(mframe >= 8) {ObjSprite2D_SetSourceRect(obj,x*2,y,x*3,y*2);}
		move = true;
        }	

		frame++;
		bob++;
		ObjRender_SetPosition(obj,BossX,BossY+2*sin(bob*3),0);
		if(frame==18){frame=0;}
		loop(2){yield;}
	}
}