// Welcome to a new edition of "How NOT to code special effects"!

let flap = 0;	
let fade = 0;
let flapIn = true;
let flapOut = false;
let fadeIn = true;
let fadeOut = false;

task Aura{ // Aura Effect (Miko)
	Aura1;
	Aura2;
	Aura3;
	PlaySE(PhaseSE2);
}

task AuraFull{ // Full Aura Effect (Miko)
	Aura1;
	Aura2;
	Aura3;
	Aura4;
	Aura5;
	PlaySE(PhaseSE2);
}

task Aura1{
	let eff = CSD ~ "../img/enm6b.png";
	let alpha = 190;

	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, eff);
	ObjSprite2D_SetSourceRect(obj, 0,0,256,256);
	ObjSprite2D_SetDestRect(obj,0,0,256,128);
	Obj_SetRenderPriorityI(obj, 24);
	ObjRender_SetScaleXYZ(obj, 1, 1.7, 0);
	ObjRender_SetColorHSV(obj, 170,200,255);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjRender_SetAlpha(obj, 0);
	
	Flaps;
	Appear(obj, alpha);
	loop(60){
		ObjRender_SetPosition(obj, ObjMove_GetX(objBoss)+45, ObjMove_GetY(objBoss)+95, 0);
		ObjRender_SetAngleXYZ(obj, 0, flap, 160);
		yield;
	}

	while(!Obj_IsDeleted(objBoss)){
		ObjRender_SetPosition(obj, ObjMove_GetX(objBoss)+45, ObjMove_GetY(objBoss)+95, 0);
		ObjRender_SetAngleXYZ(obj, 0, flap, 160);
		ObjRender_SetAlpha(obj, fade);
		yield;
	}	
}

task Aura2{
	let eff = CSD ~ "../img/enm6b.png";
	let alpha = 190;

	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, eff);
	ObjSprite2D_SetSourceRect(obj, 0,0,256,256);
	ObjSprite2D_SetDestRect(obj,0,0,256,128);
	Obj_SetRenderPriorityI(obj, 24);
	ObjRender_SetScaleXYZ(obj, 1, 1.7, 0);
	ObjRender_SetColorHSV(obj, 210,200,255);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjRender_SetAlpha(obj, 0);
	
	Flaps;
	Appear(obj, alpha);
	loop(60){
		ObjRender_SetPosition(obj, ObjMove_GetX(objBoss)+15, ObjMove_GetY(objBoss)-110, 0);
		ObjRender_SetAngleXYZ(obj, 0, -flap, 20);
		yield;
	}

	while(!Obj_IsDeleted(objBoss)){ // update loop runs until enemy object is deleted
		ObjRender_SetPosition(obj, ObjMove_GetX(objBoss)+15, ObjMove_GetY(objBoss)-110, 0);
		ObjRender_SetAngleXYZ(obj, 0, -flap, 20);
		ObjRender_SetAlpha(obj, fade);
		yield;
	}	
}

task Aura3{
	let eff = CSD ~ "../img/enm6b.png";
	let alpha = 190;

	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, eff);
	ObjSprite2D_SetSourceRect(obj, 0,0,256,256);
	ObjSprite2D_SetDestRect(obj,0,0,256,128);
	Obj_SetRenderPriorityI(obj, 24);
	ObjRender_SetScaleXYZ(obj, 1, 1.7, 0);
	ObjRender_SetColorHSV(obj, 90,200,255);
	ObjRender_SetAlpha(obj, 0);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	
	Flaps;
	Appear(obj, alpha);
	loop(60){
		ObjRender_SetPosition(obj, ObjMove_GetX(objBoss)-110, ObjMove_GetY(objBoss)+15, 0);
		ObjRender_SetAngleXYZ(obj, flap, 0, 269);
		yield;
	}
	while(!Obj_IsDeleted(objBoss)){ // update loop runs until enemy object is deleted
		ObjRender_SetPosition(obj, ObjMove_GetX(objBoss)-110, ObjMove_GetY(objBoss)+15, 0);
		ObjRender_SetAlpha(obj, fade);
		ObjRender_SetAngleXYZ(obj, flap, 0, 269);
		yield;
	}	
}

task Aura4{
	let eff = CSD ~ "../img/enm6b.png";
	let alpha = 50;

	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, eff);
	ObjSprite2D_SetSourceRect(obj, 0,0,256,256);
	ObjSprite2D_SetDestRect(obj,0,0,256,128);
	Obj_SetRenderPriorityI(obj, 23);
	ObjRender_SetScaleXYZ(obj, 1, 1.7, 0);
	ObjRender_SetColorHSV(obj, 140,100,200);
	ObjRender_SetAlpha(obj, 0);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	
	Flaps;
	Appear(obj, alpha);
	loop(60){
		ObjRender_SetPosition(obj, ObjMove_GetX(objBoss)-60, ObjMove_GetY(objBoss)+65, 0);
		ObjRender_SetAngleXYZ(obj, 0, flap, 210);
		yield;
	}

	while(!Obj_IsDeleted(objBoss)){ // update loop runs until enemy object is deleted
		ObjRender_SetPosition(obj, ObjMove_GetX(objBoss)-60, ObjMove_GetY(objBoss)+65, 0);
		ObjRender_SetAlpha(obj, fade-80);
		ObjRender_SetAngleXYZ(obj, 0, flap, 210);
		yield;
	}
}

task Aura5{
	let eff = CSD ~ "../img/enm6b.png";
	let alpha = 50;

	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, eff);
	ObjSprite2D_SetSourceRect(obj, 0,0,256,256);
	ObjSprite2D_SetDestRect(obj,0,0,256,128);
	Obj_SetRenderPriorityI(obj, 23);
	ObjRender_SetScaleXYZ(obj, 1, 1.7, 0);
	ObjRender_SetColorHSV(obj, 250,100,200);
	ObjRender_SetAlpha(obj, 0);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	
	Flaps;
	Appear(obj, alpha);
	loop(60){
		ObjRender_SetPosition(obj, ObjMove_GetX(objBoss)-50, ObjMove_GetY(objBoss)-120, 0);
		ObjRender_SetAngleXYZ(obj, 0, -flap, 330);
		yield;
	}
	while(!Obj_IsDeleted(objBoss)){ // update loop runs until enemy object is deleted
		ObjRender_SetPosition(obj, ObjMove_GetX(objBoss)-50, ObjMove_GetY(objBoss)-120, 0);
		ObjRender_SetAlpha(obj, fade);
		ObjRender_SetAngleXYZ(obj, 0, -flap, 330);
		yield;
	}
}

task Appear(obj, alpha){
	let a = 0;
	ObjRender_SetAlpha(obj, 0);
	loop(30){ a += alpha/30; ObjRender_SetAlpha(obj, a); yield; }
}

task Flaps{
	loop{
		flapIn = false;
		flapOut = true;
		fadeIn = false;
		fadeOut = true;
		wait(120);
		flapOut = false;
		flapIn = true;
		fadeOut = false;
		fadeIn = true;
		wait(120);
		
		yield;
	}
}

FlapsInc;

task FlapsInc{
	loop{
		if(flap > -30&&flapIn){
			flap=flap-0.5;
		}
		if(flap < 30&&flapOut){
			flap=flap+0.5;
		}
		if(fade < 190&&fadeIn){
			fade=fade+2;
		}
		if(flap > 5&&fadeOut){
			fade=fade-2;
		}
		yield;
	}
}