
task ShieldBreakEffect
{
	loop(60)
	{
		Fragment;
	}

	task Fragment
	{
	let imgWhite = GetCurrentScriptDirectory() ~ "img/White.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgWhite);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(obj, 3);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,20);
	ObjRender_SetAngleZ(obj,0);

	ObjPrim_SetVertexPosition(obj, 0, -16, -16, 0);
	ObjPrim_SetVertexPosition(obj, 1, 16, -16, 0);
	ObjPrim_SetVertexPosition(obj, 2, 16, 16, 0);

	ObjPrim_SetVertexUVT(obj, 0, 0, 0);
	ObjPrim_SetVertexUVT(obj, 1, 16, 0);
	ObjPrim_SetVertexUVT(obj, 2, 16, 16);

	let ox=GetPlayerX;
	let oy=GetPlayerY;
	let Speed=rand(2,12);
	let Angle=rand(0,360);

	let Scale=1;
	let Xangle=rand(0,360);
	let Yangle=rand(0,360);
	let Zangle=rand(0,360);

	let XanglePlus=rand(-10,10);
	let YanglePlus=rand(-10,10);
	let ZanglePlus=rand(-10,10);

	ObjRender_SetPosition(obj,ox,oy,0);

	let Alpha=1;
	ObjRender_SetColor(obj,64,64,128*Alpha);

	loop(60)
	{
		ObjRender_SetPosition(obj,ObjRender_GetX(obj)+Speed*cos(Angle),ObjRender_GetY(obj)+Speed*sin(Angle),0);
		ObjRender_SetAngleXYZ(obj,Xangle,Yangle,Zangle);
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		ObjRender_SetColor(obj,64*Alpha,64*Alpha,255*Alpha);
		Alpha-=1/60;
		Scale-=1/60;
		Xangle+=XanglePlus;
		Yangle+=YanglePlus;
		Zangle+=ZanglePlus;

		let sr=Obj_GetValue(GetPlayerObjectID,"Move_Right");
		let sl=Obj_GetValue(GetPlayerObjectID,"Move_Left");
		let su=Obj_GetValue(GetPlayerObjectID,"Move_Up");
		let sd=Obj_GetValue(GetPlayerObjectID,"Move_Down");
		if(sr!=0)
		{
			ObjRender_SetX(obj, ObjRender_GetX(obj)-sr);
		}
		if(sl!=0)
		{
			ObjRender_SetX(obj, ObjRender_GetX(obj)-sl);
		}
		if(su!=0)
		{
			ObjRender_SetY(obj, ObjRender_GetY(obj)-su);
		}
		if(sd!=0)
		{
			ObjRender_SetY(obj, ObjRender_GetY(obj)-sd);
		}

		yield;
	}

	Obj_Delete(obj);
	}
}

task ShieldRebirthEffect
{
	Ribirth(1);

	task Ribirth(dir)
	{
	let imgWhite = GetCurrentScriptDirectory() ~ "img/effects.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgWhite);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,20);
	ObjRender_SetAngleZ(obj,0);

	ObjPrim_SetVertexPosition(obj, 0, -64, -64, 0);
	ObjPrim_SetVertexPosition(obj, 1, 64, -64, 0);
	ObjPrim_SetVertexPosition(obj, 2, 64, 64, 0);
	ObjPrim_SetVertexPosition(obj, 3,-64, 64, 0);

	ObjPrim_SetVertexUVT(obj, 0, 0, 0);
	ObjPrim_SetVertexUVT(obj, 1, 128, 0);
	ObjPrim_SetVertexUVT(obj, 2, 128, 128);
	ObjPrim_SetVertexUVT(obj, 3, 0, 128);

	let ox=GetPlayerX;
	let oy=GetPlayerY;
	let Speed=rand(2,10);
	let Angle=rand(0,360);

	let Scale=1.5;

	let Xangle=rand(0,360)*0;
	let Yangle=rand(0,360)*0;
	let Zangle=rand(0,360);

	let XanglePlus=rand(-10,10)*0;
	let YanglePlus=rand(-10,10)*0;
	let ZanglePlus=rand(-10,10);

	ObjRender_SetPosition(obj,ox,oy,0);

	let Alpha=0;
	ObjRender_SetColor(obj,64,64,128*Alpha);

	

	loop(30)
	{
		ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
		ObjRender_SetAngleXYZ(obj,Xangle,Yangle,Zangle);
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		ObjRender_SetColor(obj,64*Alpha,64*Alpha,255*Alpha);
		Alpha+=1/30;
		Scale-=2/30;
		Xangle+=XanglePlus;
		Yangle+=YanglePlus;
		Zangle+=ZanglePlus;
		yield;
		if(!PlayerShield){break;}
	}

	loop(90)
	{
		ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
		ObjRender_SetAngleXYZ(obj,Xangle,Yangle,Zangle);
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		ObjRender_SetColor(obj,64*Alpha,64*Alpha,255*Alpha);
		Alpha-=1/90;
	//	Scale-=1/15;
		Xangle+=XanglePlus;
		Yangle+=YanglePlus;
		Zangle+=ZanglePlus;
		if(!PlayerShield){break;}
		yield;
	}
	Obj_Delete(obj);
	}
}