
let GCSD = GetCurrentScriptDirectory~"";
function fam(x,y,life,type,collision){
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	let shot;
	let c = 0;
	ObjEnemy_Regist(obj);
	ObjMove_SetPosition(obj,x,y);
	ObjEnemy_SetLife(obj,life);
	ObjEnemy_SetDamageRate(obj,100,100);
	Control;
	DrawFam(1);
	return obj;
		task Control{	
			//PlaySound("fam",100,0);
			while(!Obj_IsDeleted(obj)){
			c++;
			if(c%20==0){DrawFam(0);}
			if(ObjEnemy_GetInfo(obj,INFO_LIFE) <=0){
			TExplosionA(ObjMove_GetX(obj),ObjMove_GetY(obj),10,0.3);
			Obj_Delete(obj);
			}
			if(ObjMove_GetX(obj)<-64 || ObjMove_GetX(obj)>480 || ObjMove_GetY(obj)<-64 || ObjMove_GetY(obj)>528){
			Obj_Delete(obj);
			}
			if(collision==true){ObjEnemy_SetIntersectionCircleToShot(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),24);
			ObjEnemy_SetIntersectionCircleToPlayer(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),16);}
			yield;
			if(Obj_IsDeleted(objBoss)){Obj_Delete(obj);}
			}
		}
		task DrawFam(p){
			let fam=ObjPrim_Create(OBJ_SPRITE_2D);
			let px = 64;
			let py = 0;
			let img=GCSD~"./../img/Fam.png";
			ObjPrim_SetTexture(fam,img);
			if(type<=3){ObjSprite2D_SetSourceRect(fam,px*type,0,px*(type+1),64);}
			else{ObjSprite2D_SetSourceRect(fam,px*type,64,px*(type+1),128);}
			ObjRender_SetAngleXYZ(fam,0,0,c*2);
			ObjRender_SetPosition(fam,x,y,0);
			ObjRender_SetScaleXYZ(fam,0.8,0.8,0);
			ObjSprite2D_SetDestCenter(fam);
			ObjRender_SetBlendType(fam,BLEND_ADD_ARGB);
			if(p==0){
				ascent(i in 0..25){
				if(Obj_IsDeleted(obj)){Obj_Delete(fam);}
				ObjRender_SetPosition(fam,ObjMove_GetX(obj),ObjMove_GetY(obj),0);
				ObjRender_SetScaleXYZ(fam,0.8+i/40,0.8+i/40,0);
				ObjRender_SetColor(fam,180-i*7.1,180-i*7.1,180-i*7.1);
				yield;
				}
			Obj_Delete(fam);
			}
			if(p==1){
				while(!Obj_IsDeleted(obj)){
				ObjRender_SetPosition(fam,ObjMove_GetX(obj),ObjMove_GetY(obj),0);
				ObjRender_SetAngleXYZ(fam,0,0,c*3);
				yield;
				}
				Obj_Delete(fam);
			}
		}
	}


task TExplosionA(x, y, dAlpha, dScale)
{
	let path = GetCurrentScriptDirectory() ~ "img/Default_Effect.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 0.65);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	ObjSprite2D_SetSourceRect(obj, 1, 1, 63, 63);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj, x, y, 0);

	let scale = 0;
	let alpha = 255;
	while(alpha > 0)
	{
		ObjRender_SetColor(obj, alpha, alpha, alpha);
		ObjRender_SetScaleXYZ(obj, scale, scale, 1);

		scale += dScale;
		alpha -= dAlpha;
		yield;
	}
	Obj_Delete(obj);
}
