#include "./MS_ShotFunctions.txt"
#include "./MS_Effects.txt"

function Cat(x, y){
	let obj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(obj);

	ObjMove_SetPosition(obj, x, y);

	Render(obj);
	return obj;
	
		task Render(tar){
		let dir = 0;
		let speed = 0;
		let frame = 0;
		let mframe = 0;
		let bob = 0;
		let x = 48;
		let y = 48;
		
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/thecat.png");
		Obj_SetRenderPriorityI(obj, 40);
		ObjRender_SetScaleXYZ(obj,1,1,0);
		while(!Obj_IsDeleted(obj)){	
		ObjSprite2D_SetDestCenter(obj);	
		ObjRender_SetAngleXYZ(obj,0,0,GetCommonData("Catangle",0));
		ObjRender_SetAlpha(obj,GetCommonData("Catalpha",255));

		let BossX = ObjMove_GetX(tar);
		let BossY = ObjMove_GetY(tar);
		
			dir = ObjMove_GetAngle(tar);
			speed = ObjMove_GetSpeed(tar);
			
			if(speed==0){
				if(attack == false) {
				if(frame <= 8) {ObjSprite2D_SetSourceRect(obj,0,0,x,y);}
				if(frame >= 8){ObjSprite2D_SetSourceRect(obj,x,0,x*2,y);}
				mframe = 0;
				}	
			}
			
			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);}
			if(mframe >= 12) {ObjSprite2D_SetSourceRect(obj,x*3,y,x*4,y*2);}
			}
			
			else if(cos(dir) < 0) {mframe++;
			ObjRender_SetAngleXYZ(obj, 0, 180, GetCommonData("Catangle",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);}
			if(mframe >= 12) {ObjSprite2D_SetSourceRect(obj,x*3,y,x*4,y*2);}
			}	

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