#include "./../functions1.txt"
let Spell = false;
let render_x = -128;
let render_y = -128;
let img;

task ObjEnemy_Render
{
	SetCommonData("REI_SPELL",false);
	CreateEnemyIcon(objEnemy);
	img = ObjPrim_Create(OBJ_SPRITE_2D);	
	if(mid == false)
		{
		ObjPrim_SetTexture(img,GetCurrentScriptDirectory ~ "img/Sprite_Boss.png");
		ObjSprite2D_SetDestRect(img,-32,-32,32,32);
		}	
	else
		{
		ObjPrim_SetTexture(img,GetCurrentScriptDirectory ~ "img/Sprite_Midboss.png");
		ObjSprite2D_SetDestRect(img,-28,-28,28,28);
		}
	Obj_SetRenderPriority(img,0.38);
	ObjRender_SetPosition(img,-128,-128,0);

	let anim = 0;
	let spell = 0;
	let declare = 0;
	let spellD = 0;
	
	let count = 1/8;

	while(!Obj_IsDeleted(objEnemy))
		{
		if(spellD != EnemySpell)
			{
			spell = 0;
			}
		spellD = EnemySpell;
		if(ObjMove_GetSpeed(objEnemy) > 0.1)
			{
			anim = 0;
			spell = 0;
			declare = 0;
			render_x = 2;
			render_y = 3;
			if(cos(ObjMove_GetAngle(objEnemy)) > cos(75))
				{
				ObjRender_SetScaleX(img,absolute(ObjRender_GetScaleX(objEnemy)));	
				}
			else if(cos(ObjMove_GetAngle(objEnemy)) < cos(105))
				{
				ObjRender_SetScaleX(img,-absolute(ObjRender_GetScaleX(objEnemy)));	
				}
			}
		else if(EnemySpell == -1 || declare > 0)
			{
			anim = 0;
			spell = 0;
			if(EnemySpell == -1)
				{
				if(declare < 3)
					{
					declare+=count;
					}
				}
			else
				{
				declare-=count;
				}
			if(declare < 2)
				{
				render_x = 2+floor(declare);
				render_y = 0;
				}
			else
				{
				render_x = 3;
				render_y = floor(declare)-1;
				}
			}	
		else if(EnemySpell == 1 || EnemySpell == 2)
			{
			anim = 0;
			declare = 0;
			if(spell < 3)
				{
				spell += count;
				render_x = 2+floor(spell);
				render_y = 0;
				}
			else if(EnemySpell == 1)
				{	
				if(spell < 6)
					{	
					spell += count;
					}
				render_x = 5;
				render_y = floor(spell)-3;
				}
			else
				{	
				if(spell < 5)
					{
					spell += count;
					}
				else
					{	
					spell = 5;
					}
				render_x = 4;
				render_y = floor(spell-3);
				}
			}
		else
			{
			anim+=count;
			spell = 0;
			declare = 0;
			render_y = floor(anim)%3;
			render_x = 0;
			}
		ObjRender_SetPosition(img,EnemyX,EnemyY,0);
		ObjSprite2D_SetSourceRect(img,render_x*128+32,render_y*128+32,(render_x+1)*128-32,(render_y+1)*128-32);
		SetCommonData("REI_SPELL",Spell);
		yield;
		}
	Obj_Delete(img);
}