let imgBoss = GetCurrentScriptDirectory ~ "./img/Clause.png";
let imgBoss2 = GetCurrentScriptDirectory ~ "./img/ohhellno.png";

task RenderClause(tar){
	let move = false;
	let dir = 0;
	let speed = 0;
	let frame = 0;
	let mframe = 0;
	let aframe = 0;
	let x = 60;
	let y = 90;
	
	

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

		frame++;
		if(frame==16){frame=0;}
		wait(4);
	}
}

function OhHellNo{
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);
RenderOhHellNo(obj);
return(obj);
task RenderOhHellNo(tar){
	let move = false;
	let dir = 0;
	let speed = 0;
	let frame = 0;
	let mframe = 0;
	let aframe = 0;
	let x = 46;
	let y = 86;
	
	

	while(!Obj_IsDeleted(tar)){	
	ObjRender_SetAlpha(tar,255);
	ObjPrim_SetTexture(tar,imgBoss2);
	Obj_SetRenderPriority(tar, 0.27);
	ObjSprite2D_SetDestCenter(tar);	
	ObjRender_SetScaleXYZ(tar,1,1,0);
	ObjRender_SetAngleXYZ(tar,0,0,GetCommonData("BossAngle2",0));
		
		dir = ObjMove_GetAngle(tar);
		speed = ObjMove_GetSpeed(tar);
		
		if(speed==0){
			if(move == false){
			if(frame <= 4) {ObjSprite2D_SetSourceRect(tar,0,0,x,y);}
			if(frame >= 4) {ObjSprite2D_SetSourceRect(tar,x,0,x*2,y);}
			if(frame >= 8) {ObjSprite2D_SetSourceRect(tar,x*2,0,x*3,y);}
			if(frame >= 12) {ObjSprite2D_SetSourceRect(tar,x*3,0,x*4,y);}
			mframe=0;
			aframe=0;
			}
			
			if(move == true){
			if(frame <= 4) {ObjSprite2D_SetSourceRect(tar,x*3,0,x*4,y);}
			if(frame >= 4) {ObjSprite2D_SetSourceRect(tar,x*2,0,x*3,y);}
			if(frame >= 8) {ObjSprite2D_SetSourceRect(tar,x,0,x*2,y);}
			if(frame >= 12) {ObjSprite2D_SetSourceRect(tar,0,0,x,y);}
			if(frame >= 15) {move = false;}
			}
		}			
		
		else if(cos(dir) > 0) {mframe++;
        if(mframe <= 4) {ObjSprite2D_SetSourceRect(tar,0,y,x,y*2);}
        if(mframe >= 4) {ObjSprite2D_SetSourceRect(tar,x,y,x*2,y*2);}
		if(mframe >= 8) {ObjSprite2D_SetSourceRect(tar,x*2,y,x*3,y*2);}
		if(mframe >= 12) {ObjSprite2D_SetSourceRect(tar,x*3,y,x*4,y*2);}
		move = true;
        }
		
		else if(cos(dir) < 0) {mframe++;
        if(mframe <= 4) {ObjSprite2D_SetSourceRect(tar,0,y*2,x,y*3);}
        if(mframe >= 4) {ObjSprite2D_SetSourceRect(tar,x,y*2,x*2,y*3);}
		if(mframe >= 8) {ObjSprite2D_SetSourceRect(tar,x*2,y*2,x*3,y*3);}
		if(mframe >= 12) {ObjSprite2D_SetSourceRect(tar,x*3,y*2,x*4,y*3);}
		move = true;
        }	

		frame++;
		if(frame==16){frame=0;}
		wait(4);
	}
}
}

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);
}
