let imgBoss = GetCurrentScriptDirectory ~ "./img/Ingame/Shoux2.png";

let attack = false;

task RenderCharacter(tar){
	let move = false;
	let dir = 0;
	let speed = 0;
	let iframe = 0;
	let frame = 0;
	let mframe = 0;
	let aframe = 0;
	let bob = 0;
	let x = 64;
	let y = 112;
	
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	
	
	ObjRender_SetAlpha(obj,255);
	Obj_SetRenderPriorityI(obj, 30);
	while(!Obj_IsDeleted(obj)){	
	ObjPrim_SetTexture(obj,imgBoss);
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetAngleXYZ(obj,0,0,GetCommonData("BossAngle",0));
	ObjRender_SetScaleXYZ(obj,1,1,0);
		
		dir = ObjMove_GetAngle(tar);
		speed = ObjMove_GetSpeed(tar);
		
		if(speed==0){
			if(attack == true) {aframe++;
			if(aframe <= 6) {ObjSprite2D_SetSourceRect(obj,0,y*2,x,y*3);}
			if(aframe >= 6) {ObjSprite2D_SetSourceRect(obj,x,y*2,x*2,y*3);}
			if(aframe >= 12) {ObjSprite2D_SetSourceRect(obj,x*2,y*2,x*3,y*3);}
			if(aframe >= 18) {ObjSprite2D_SetSourceRect(obj,x*3,y*2,x*4,y*3);}
			if(aframe >= 24) {ObjSprite2D_SetSourceRect(obj,0,y*3,x,y*4);}
			if(aframe >= 30) {ObjSprite2D_SetSourceRect(obj,x,y*3,x*2+32,y*4);}
			if(aframe >= 36) {ObjSprite2D_SetSourceRect(obj,x*3-32,y*3,x*4,y*4);}
			if(aframe >= 42) {aframe-=12;}
			}	
			if(attack == false) {
			if(frame<16 && iframe<=8){ObjSprite2D_SetSourceRect(obj,0,0,x,y);}
			if(frame<16 && iframe>=8){ObjSprite2D_SetSourceRect(obj,x,0,x*2,y);}
			if(frame<16 && iframe>=16){ObjSprite2D_SetSourceRect(obj,x*2,0,x*3,y);}
			if(frame<16 && iframe>=24){ObjSprite2D_SetSourceRect(obj,x*3,0,x*4,y);}
			mframe=0;
			aframe=0;
			}
			if(move == true && attack == false){
			if(frame <= 4) {ObjSprite2D_SetSourceRect(obj,x*3,112,x*4,y+112);}
			if(frame >= 4) {ObjSprite2D_SetSourceRect(obj,x*2,112,x*3,y+112);}
			if(frame >= 8) {ObjSprite2D_SetSourceRect(obj,x,112,x*2,y+112);}
			if(frame >= 12) {ObjSprite2D_SetSourceRect(obj,0,112,x,y+112);}
			if(frame >= 15) {move = false;}
			}
		}			
		
		else if(cos(dir) < 0) {mframe++;
        if(mframe <= 4) {ObjSprite2D_SetSourceRect(obj,0,112,x,y+112);}
        if(mframe >= 4) {ObjSprite2D_SetSourceRect(obj,x,112,x*2,y+112);}
		if(mframe >= 8) {ObjSprite2D_SetSourceRect(obj,x*2,112,x*3,y+112);}
		if(mframe >= 12) {ObjSprite2D_SetSourceRect(obj,x*3,112,x*4,y+112);}
		move = true;
        }
		
		else if(cos(dir) > 0) {mframe++;
		ObjRender_SetAngleXYZ(obj,0,180,GetCommonData("BossAngle",0));
        if(mframe <= 4) {ObjSprite2D_SetSourceRect(obj,0,112,x,y+112);}
        if(mframe >= 4) {ObjSprite2D_SetSourceRect(obj,x,112,x*2,y+112);}
		if(mframe >= 8) {ObjSprite2D_SetSourceRect(obj,x*2,112,x*3,y+112);}
		if(mframe >= 12) {ObjSprite2D_SetSourceRect(obj,x*3,112,x*4,y+112);}
		move = true;
        }	
		
		bob++;
		ObjRender_SetPosition(obj,ObjMove_GetX(tar),ObjMove_GetY(tar)+2*sin(bob*2),0);
		frame++; iframe+=1;
		if(frame==16){frame=0;} if(iframe==32){iframe=0;}
		yield;
	}
}