let attack = false;

task Attack(frames){
attack = true;
wait(frames);
attack = false;
}

task RenderEllen(tar){
	let move = false;
	let dir = 0;
	let speed = 0;
	let frame = 0;
	let mframe = 0;
	let mframe2 = 0;
	let aframe = 0;
	let bob = 0;
	let x = 45;
	let y = 80;
	
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/ellensprite.png");
	Obj_SetRenderPriorityI(obj, 40);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	while(!Obj_IsDeleted(obj)){	
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetAngleXYZ(obj,0,0,GetCommonData("BossAngle",0));
	ObjRender_SetAlpha(obj,GetCommonData("BossAlpha",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);}
			if(frame >= 16){ObjSprite2D_SetSourceRect(obj,x*2,0,x*3,y);}
			if(frame >= 24){ObjSprite2D_SetSourceRect(obj,x*3,0,x*4,y);}
			mframe = 0;
			aframe = 0;
			}
			if(move == true && attack == false){ mframe2++;
			if(mframe2 <= 3) {ObjSprite2D_SetSourceRect(obj,x*3,y,x*2,y*2);}
			if(mframe2 >= 3) {ObjSprite2D_SetSourceRect(obj,x*2,y,x,y*2);}
			if(mframe2 >= 6) {ObjSprite2D_SetSourceRect(obj,x,y,0,y*2);}
			if(mframe2 >= 9) {move = false; mframe2 = 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);}
		move = true;
        }
		
		else if(cos(dir) < 0) {mframe++;
        if(mframe <= 4) {ObjSprite2D_SetSourceRect(obj,0,y*2,x,y*3);}
		if(mframe >= 4) {ObjSprite2D_SetSourceRect(obj,x,y*2,x*2,y*3);}
		if(mframe >= 8) {ObjSprite2D_SetSourceRect(obj,x*2,y*2,x*3,y*3);}
		if(mframe >= 12) {ObjSprite2D_SetSourceRect(obj,x*3,y*2,x*4,y*3);}
		move = true;
        }	

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

task RenderKana(tar){
	let move = false;
	let dir = 0;
	let speed = 0;
	let frame = 0;
	let mframe = 0;
	let mframe2 = 0;
	let aframe = 0;
	let bob = 0;
	let x = 45;
	let y = 88;
	
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/kanasprite.png");
	Obj_SetRenderPriorityI(obj, 40);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	while(!Obj_IsDeleted(obj)){	
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetAngleXYZ(obj,0,0,GetCommonData("BossAngle",0));
	ObjRender_SetAlpha(obj,GetCommonData("BossAlpha",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);}
			if(frame >= 16){ObjSprite2D_SetSourceRect(obj,x*2,0,x*3,y);}
			if(frame >= 24){ObjSprite2D_SetSourceRect(obj,x*3,0,x*4,y);}
			mframe = 0;
			aframe = 0;
			}
			if(move == true && attack == false){ mframe2++;
			if(mframe2 <= 3) {ObjSprite2D_SetSourceRect(obj,x*3,y,x*2,y*2);}
			if(mframe2 >= 3) {ObjSprite2D_SetSourceRect(obj,x*2,y,x,y*2);}
			if(mframe2 >= 6) {ObjSprite2D_SetSourceRect(obj,x,y,0,y*2);}
			if(mframe2 >= 9) {move = false; mframe2 = 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);}
		move = true;
        }
		
		else if(cos(dir) < 0) {mframe++;
        if(mframe <= 4) {ObjSprite2D_SetSourceRect(obj,0,y*2,x,y*3);}
		if(mframe >= 4) {ObjSprite2D_SetSourceRect(obj,x,y*2,x*2,y*3);}
		if(mframe >= 8) {ObjSprite2D_SetSourceRect(obj,x*2,y*2,x*3,y*3);}
		if(mframe >= 12) {ObjSprite2D_SetSourceRect(obj,x*3,y*2,x*4,y*3);}
		move = true;
        }	

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