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

let attack = false;
let attack2 = false;

task Attack(frame){
attack = true;
wait(frame);
attack = false;
attack2 = true;
wait(frame*1.5);
attack2 = false;
}

task RenderCharacter(tar){
	let blink = 0;
	let blinking = false;
	let dir = 0;
	let speed = 0;
	let frame = 0;
	let mframe = 0;
	let aframe = 0;
	let aframe2 = 0;
	let bob = 0;
	let x = 128;
	let y = 128;
	
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	
	
	ObjPrim_SetTexture(obj,imgBoss);
	ObjRender_SetScaleXYZ(obj,0.8,0.8,0);
	Obj_SetRenderPriorityI(obj, 24);
	while(!Obj_IsDeleted(obj)){	
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetAngleXYZ(obj,0,0,GetCommonData("BossAngle",0));
	ObjRender_SetAlpha(obj,GetCommonData("BossAlpha",0));
	
	let BossX = ObjMove_GetX(tar);
	let BossY = ObjMove_GetY(tar);
	
		dir = ObjMove_GetAngle(tar);
		speed = ObjMove_GetSpeed(tar);
		
		if(speed==0){
			if(attack == true){
			if(aframe <= 2) {ObjSprite2D_SetSourceRect(obj,x*3,0,x*4,y);}
			}	
			if(attack2 == true){aframe2++;
			if(aframe2 >= 2) {ObjSprite2D_SetSourceRect(obj,x,y*2,x*2,y*3);}
			if(aframe2 >= 8) {ObjSprite2D_SetSourceRect(obj,x*2,y*2,x*3,y*3);}
			}	
			if(attack == false && attack2 == false) {
			if(frame <= 4) {ObjSprite2D_SetSourceRect(obj,0,0,x,y);}
			if(frame <= 4 && blinking == true) {ObjSprite2D_SetSourceRect(obj,0,y,x,y*2);}
			mframe = 0;
			aframe2 = 0;
			}
		}			
		
		else if(cos(dir) > 0) {mframe++;
        if(mframe <= 4) {ObjSprite2D_SetSourceRect(obj,x,0,x*2,y);}
		if(mframe <= 4 && blinking == true) {ObjSprite2D_SetSourceRect(obj,x,y,x*2,y*2);}
        }
		
		else if(cos(dir) < 0) {mframe++;
		if(mframe <= 4) {ObjSprite2D_SetSourceRect(obj,x*2,0,x*3,y);}
		if(mframe <= 4 && blinking == true) {ObjSprite2D_SetSourceRect(obj,x*2,y,x*3,y*2);}
        }	

		frame++;
		bob++;
		blink++;
		ObjRender_SetPosition(obj,BossX,BossY+2*sin(bob*2),0);
		if(frame==4){frame=0;}
		if(blink > 180){blinking = true}
		else{blinking = false}
		if(blink > 185) {blink = 0};
		yield;
	}
}