let attack = false;
let imgBoss = GetCurrentScriptDirectory ~ "./img/rinkaebyou.png";
let imgCat = GetCurrentScriptDirectory ~ "./img/catrin.png";
let cat = false;
let x = 0;
let y = 0;

task renderorin(tar){
	let dir = 0;
	let speed = 0;
	let switch = 0;
	let f = 0;
	let f2 = 0;
	let f3 = 0;
	let af = 0;
	loop{
		let x = 64;
		let y = 64;
		
		while(!Obj_IsDeleted(tar)){	
		ObjPrim_SetTexture(tar,imgBoss);
		ObjSprite2D_SetSourceRect(tar,0,0,x,y);
		ObjSprite2D_SetDestCenter(tar);	
		ObjRender_SetScaleXYZ(tar,1,1,0);
		ObjRender_SetAlpha(tar,255);
		ObjRender_SetAngleXYZ(tar,0,0,0);
		ObjRender_SetScaleXYZ(tar,1.1,1.3,0);
			
			dir = ObjMove_GetAngle(tar);
			speed = ObjMove_GetSpeed(tar);
			
			if(speed==0){ObjRender_SetAngleXYZ(tar,0,0,0);
			if(f<8){ObjSprite2D_SetSourceRect(tar,0,0,x,y);}
			if(f>=8 && f<16){ObjSprite2D_SetSourceRect(tar,x*1,0,x*2,y);}
			if(f>=16 && f<24){ObjSprite2D_SetSourceRect(tar,x*2,0,x*3,y);}
			if(f>=24 && f<32){ObjSprite2D_SetSourceRect(tar,x*3,0,x*4,y);}
			f2=0;}		
			
			else if(cos(dir) < 0) {f2++;
			ObjRender_SetAngleXYZ(tar,0,0,0);
			if(f2 <= 8) {ObjSprite2D_SetSourceRect(tar,0,y*1,x,y*2);}
			if(f2 >= 8) {ObjSprite2D_SetSourceRect(tar,0,y*1,x,y*2);}
			}
			
			else if(cos(dir) > 0) {f3++;
			ObjRender_SetAngleXYZ(tar,0,180,0);
			if(f3 <= 8) {ObjSprite2D_SetSourceRect(tar,0,y*1,x,y*2);}
			if(f3 >= 8) {ObjSprite2D_SetSourceRect(tar,x*1,y*1,x*2,y*2);}
			}	

			if (attack==true){
				af++;
				if(af<8){ObjSprite2D_SetSourceRect(tar,0,y*2,x,y*3);}
				if(af>=8){ObjSprite2D_SetSourceRect(tar,x*1,y*2,x*2,y*3);}
			}	
			
			f++;
			if(f==32){f=0;}
			if(attack==false){af=0;switch=0;}
			if(attack && switch!=1){flashring(tar); switch=1;}
			if(cat==true){break;}
			wait(2);
		}
		x = 48;
		y = 48;
		while(!Obj_IsDeleted(tar)){	
		ObjPrim_SetTexture(tar,imgCat);
		ObjSprite2D_SetSourceRect(tar,0,0,x,y);
		ObjSprite2D_SetDestCenter(tar);	
		ObjRender_SetScaleXYZ(tar,1,1,0);
		ObjRender_SetAlpha(tar,255);
		ObjRender_SetScaleXYZ(tar,1.1,1.3,0);
			
			dir = ObjMove_GetAngle(tar);
			speed = ObjMove_GetSpeed(tar);
			
			if(speed==0){ObjRender_SetAngleXYZ(tar,0,180,0);
			if(f<8){ObjSprite2D_SetSourceRect(tar,0,0,x,y);}
			if(f>8){ObjSprite2D_SetSourceRect(tar,x*1,0,x*2,y);}
			f2=0;}		
			
			else if(cos(dir) < 0) {f2++;
			ObjRender_SetAngleXYZ(tar,0,180,0);
			if(f2 <= 8) {ObjSprite2D_SetSourceRect(tar,0,y*1,x,y*2);}
			if(f2 >= 8) {ObjSprite2D_SetSourceRect(tar,x,y*1,x*2,y*2);}
			if(f2 >= 16) {ObjSprite2D_SetSourceRect(tar,x*2,y*1,x*3,y*2);}
			if(f2 >= 24) {ObjSprite2D_SetSourceRect(tar,x*3,y*1,x*4,y*2);}
			}
			
			else if(cos(dir) > 0) {f2++;
			ObjRender_SetAngleXYZ(tar,0,0,0);
			if(f2 <= 8) {ObjSprite2D_SetSourceRect(tar,0,y*1,x,y*2);}
			if(f2 >= 8) {ObjSprite2D_SetSourceRect(tar,x,y*1,x*2,y*2);}
			if(f2 >= 16) {ObjSprite2D_SetSourceRect(tar,x*2,y*1,x*3,y*2);}
			if(f2 >= 24) {ObjSprite2D_SetSourceRect(tar,x*3,y*1,x*4,y*2);}
			}	
			
			f++;
			if(f==16){f=0;}
			if(attack && switch!=1){flashring(tar); switch=1;}
			if(cat==false){break;}
			wait(2);
		}
	}
	task flashring(tar){
	let alpharing = 0;
	let alphaflash = 0;
	let scale = 0;
	let crazyspin = 0;
	
	let ring = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(ring,imgBoss);
	ObjSprite2D_SetSourceRect(ring,64*2,64*2,64*3,64*3);
	ObjSprite2D_SetDestCenter(ring);	
	
	let flash = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(flash,imgBoss);
	ObjSprite2D_SetSourceRect(flash,64*3,64*2,64*4,64*3);
	ObjSprite2D_SetDestCenter(flash);
	ObjRender_SetColor(flash, 255,0,0);
	
	while(!Obj_IsDeleted(tar)){
	if(cat==true){
	ObjRender_SetPosition(flash,ObjMove_GetX(tar)+14,ObjMove_GetY(tar)-20,0);
	ObjRender_SetPosition(ring,ObjMove_GetX(tar)+14,ObjMove_GetY(tar)-20,0);
	}
	else{
	ObjRender_SetPosition(flash,ObjMove_GetX(tar)+24,ObjMove_GetY(tar)-35,0);
	ObjRender_SetPosition(ring,ObjMove_GetX(tar)+24,ObjMove_GetY(tar)-35,0);
	}
	ObjRender_SetAlpha(flash,alphaflash);
	ObjRender_SetAlpha(ring,alpharing);
	ObjRender_SetScaleXYZ(ring, scale, scale, 0);
	ObjRender_SetAngleZ(flash, crazyspin);
	
	crazyspin += 47;
	if(alpharing<80){alpharing+=2;}
	if(alphaflash<150){alphaflash+=2;}
	if(scale<1.2){scale+=0.020;}
	if(attack==false){Obj_Delete(ring);Obj_Delete(flash);}
	yield;
	}
	}
}
