let path = GetCurrentScriptDirectory() ~ "img/eye.png";

task LoadEye{LoadTexture(path);}
function eye(x, y, scale){
	let eye = ObjPrim_Create(OBJ_SPRITE_2D);
	
	ObjPrim_SetTexture(eye, path);
	ObjSprite2D_SetSourceRect(eye, 0, 0, 479, 384);
	ObjSprite2D_SetDestCenter(eye);
	ObjRender_SetScaleXYZ(eye, scale, scale, 0);
	ObjRender_SetAlpha(eye, 80);
	ObjRender_SetPosition(eye, x, y, 0);
	Obj_SetRenderPriorityI(eye, 60);
	ObjRender_SetBlendType(eye, BLEND_ALPHA);
	
	return eye;
}

task blink(olho, time, loops){	
	ascent(j in 0..loops){
		ascent(i in 0..20){
			ObjSprite2D_SetSourceRect(olho, 479*i, 0, 479*(i+1), 384);
			wait(time[0]);
		}
		wait(time[1]);
	}
}

task disappear(olho, time, n){
	ObjRender_SetBlendType(olho, BLEND_ALPHA);
	ascent(i in 0..11){
		ObjSprite2D_SetSourceRect(olho, 479*i, 0, 479*(i+1), 384);
		wait(time);
	}
	
	let o = 0;
	let a; let d = rand(90-15, 90+15);
	//let d = atan2(py - getry(olho), px - getrx(olho));
	
	PlaySFX_V(diss, 62);
	ascent(i in 0..8){ExplodeCircle(getrx(olho), getry(olho), 10+i*5, 255, 51, 204, BLEND_ADD_ARGB);}
	ascent(i in 0..3){
		a = d + 360/3*i;
		
		let x = getrx(olho); let y = getry(olho);
		
		let B = CreateShotA2(x, y, 4, a, 1/8, 6, 870, 3); reflectN(B, 1);
		ascent(c in 0..10){
			ascent(j in -0..1){
				let orient = CreateShotA2(x, y, 4-c/2, a+2*j, 1/8, 6, 539, 3);
				ObjRender_SetBlendType(orient, BLEND_ADD_ARGB);
			}
		}
		
	}
	
	let sc = 0.3;
	descent(i in 0..n+1){
		ObjRender_SetScaleXYZ(olho, sc, sc, 0);
		sc -= 0.3/n;
		wait(time);
	}
	
	Obj_Delete(olho);
}

task ey_unzan(me){
	//{
		let a; //let r = 90;
		let r = atan2(py - getry(me), px - getrx(me));
		let j = 0;
	//}
	
	DelayedPlaySFX_V(laser, 45, 60);
	ascent(i in -3..4){
		a = r + 60*i;
		let x = getrx(me); let y = getry(me);
		
		let B = CreateSTLaser(x, y, a, 789, 60, 9+20*j, [45, 90]);
	}
	
	wait(60*1.5);
	disappear(me, 3, 5);
}