#include "./MS_ScriptTasks.txt"
let attack = false;

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

task RenderCharacter(tar){
	let move = false;
	let dir = 0;
	let speed = 0;
	let frame = 0;
	let mframe = 0;
	let mframe2 = 0;
	let switch = 0;
	let aframe = 0;
	let bob = 0;
	let x = 96;
	let y = 96;
	
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/utsuhosprite.png");
	Obj_SetRenderPriorityI(obj, 29);
	while(!Obj_IsDeleted(obj)){	
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetScaleXYZ(obj,GetCommonData("BossScale",1),GetCommonData("BossScale",1),0);
	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 == true){aframe++;
			if(aframe <= 8) {ObjSprite2D_SetSourceRect(obj,0,y*3,x,y*4);}
			if(aframe >= 8){ObjSprite2D_SetSourceRect(obj,x,y*3,x*2,y*4);}
			if(aframe >= 16){ObjSprite2D_SetSourceRect(obj,x*2,y*3,x*3,y*4);}
			if(aframe >= 16 && switch == 0 && GetCommonData("Flare",0) == 1){BreakSun(tar); switch = 1; SetCommonData("UtsuhoAttack", 1);}
			if(aframe >= 24){ObjSprite2D_SetSourceRect(obj,x*3,y*3,x*4,y*4);}
			if(aframe >= 24){aframe-=8;}
			}	
			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;
			switch = 0;
			SetCommonData("UtsuhoAttack", 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);}
        }
		
		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);}
        }	

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