let imgBoss = GetCurrentScriptDirectory ~ "./img/Yamasume.png";

let attack = false;
task renderyamame(tar){
	let move = false;
	let dir = 0;
	let speed = 0;
	let frame = 0;
	let mframe = 0;
	let aframe = 0;
	let x = 64;
	let y = 64;
	
	
	ObjRender_SetAlpha(tar,255);
	while(!Obj_IsDeleted(tar)){	
	ObjPrim_SetTexture(tar,imgBoss);
	ObjSprite2D_SetDestCenter(tar);	
	ObjRender_SetScaleXYZ(tar,1,1,0);
	ObjRender_SetAngleXYZ(tar,0,0,GetCommonData("BossAngle",0));
	ObjRender_SetScaleXYZ(tar,1,1,0);
		
		dir = ObjMove_GetAngle(tar);
		speed = ObjMove_GetSpeed(tar);
		
		if(speed==0){
			if(attack == true) {aframe++;
			if(aframe <= 4) {ObjSprite2D_SetSourceRect(tar,0,126+y,x,126+(y*2));}
			if(aframe >= 4) {ObjSprite2D_SetSourceRect(tar,x,126+y,x*2,126+(y*2));}
			if(aframe >= 8) {ObjSprite2D_SetSourceRect(tar,x*2,126+y,x*3,126+(y*2));}
			if(aframe >= 12) {ObjSprite2D_SetSourceRect(tar,x*3,126+y,x*4,126+(y*2));}
			}	
			if(attack == false) {
			if(frame<16){ObjSprite2D_SetSourceRect(tar,0,126,x,y+126);}
			mframe=0;
			aframe=0;
			}
			if(move == true && attack == false){
			if(frame <= 4) {ObjSprite2D_SetSourceRect(tar,x*3,126,x*4,y+126);}
			if(frame >= 4) {ObjSprite2D_SetSourceRect(tar,x*2,126,x*3,y+126);}
			if(frame >= 8) {ObjSprite2D_SetSourceRect(tar,x,126,x*2,y+126);}
			if(frame >= 12) {ObjSprite2D_SetSourceRect(tar,0,126,x,y+126);}
			if(frame >= 15) {move = false;}
			}
		}			
		
		else if(cos(dir) > 0) {mframe++;
        if(mframe <= 4) {ObjSprite2D_SetSourceRect(tar,0,126,x,y+126);}
        if(mframe >= 4) {ObjSprite2D_SetSourceRect(tar,x,126,x*2,y+126);}
		if(mframe >= 8) {ObjSprite2D_SetSourceRect(tar,x*2,126,x*3,y+126);}
		if(mframe >= 12) {ObjSprite2D_SetSourceRect(tar,x*3,126,x*4,y+126);}
		move = true;
        }
		
		else if(cos(dir) < 0) {mframe++;
		ObjRender_SetAngleXYZ(tar,0,180,GetCommonData("BossAngle",0));
        if(mframe <= 4) {ObjSprite2D_SetSourceRect(tar,0,126,x,y+126);}
        if(mframe >= 4) {ObjSprite2D_SetSourceRect(tar,x,126,x*2,y+126);}
		if(mframe >= 8) {ObjSprite2D_SetSourceRect(tar,x*2,126,x*3,y+126);}
		if(mframe >= 12) {ObjSprite2D_SetSourceRect(tar,x*3,126,x*4,y+126);}
		move = true;
        }	

		frame++;
		if(frame==16){frame=0;}
		yield;
	}
}

task renderkisume(tar){
	let dir = 0;
	let speed = 0;
	let frame = 0;
	let mframe = 0;
	let aframe = 0;
	let x = 64;
	let y = 64;
	
	
	ObjRender_SetAlpha(tar,255);
	while(!Obj_IsDeleted(tar)){	
	ObjPrim_SetTexture(tar,imgBoss);
	ObjSprite2D_SetDestCenter(tar);	
	ObjRender_SetScaleXYZ(tar,1,1,0);
	ObjRender_SetAngleXYZ(tar,0,0,0);
	ObjRender_SetScaleXYZ(tar,1,1,0);
		
		dir = ObjMove_GetAngle(tar);
		speed = ObjMove_GetSpeed(tar);
		
			if(frame <= 8) {ObjSprite2D_SetSourceRect(tar,0,0,x,y);}
			if(frame >= 8) {ObjSprite2D_SetSourceRect(tar,x,0,x*2,y);}
			if(frame >= 16) {ObjSprite2D_SetSourceRect(tar,x*2,0,x*3,y);}
			if(frame >= 24) {ObjSprite2D_SetSourceRect(tar,x*3,0,x*4,y);}
			if(frame >= 32) {ObjSprite2D_SetSourceRect(tar,0,y,x,y*2);}
			if(frame >= 40) {ObjSprite2D_SetSourceRect(tar,x,y,x*2,y*2);}
			if(frame >= 48) {ObjSprite2D_SetSourceRect(tar,x*2,y,x*3,y*2);}
			if(frame >= 56) {ObjSprite2D_SetSourceRect(tar,x*3,y,x*4,y*2);}
			
		frame++;
		if(frame==64){frame=0;}
		yield;
	}
}

task Fade{
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,70);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./img/black.png");
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,5,5,5);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj, 0);
	while(!Obj_IsDeleted(obj)){
	ObjRender_SetAlpha(obj, count);
	if(count>=255){break;}
	count+=10;
	yield;
	}
	SetCommonData("Fade", 1);
	wait(60);
	while(!Obj_IsDeleted(obj)){
	ObjRender_SetAlpha(obj, count);
	if(count==0){break;}
	count--;
	yield;
	}
	Obj_Delete(obj);
}


task FadeWhite{
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,70);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./img/white.png");
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,5,5,5);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj, 0);
	while(!Obj_IsDeleted(obj)){
	ObjRender_SetAlpha(obj, count);
	if(count>=255){break;}
	count+=10;
	yield;
	}
	SetCommonData("Fade", 1);
	wait(60);
	while(!Obj_IsDeleted(obj)){
	ObjRender_SetAlpha(obj, count);
	if(count==0){break;}
	count--;
	yield;
	}
	Obj_Delete(obj);
}
