function wait(w) { loop(w) { yield; } }

function PlaySound(path){
	let obj=ObjSound_Create;
	ObjSound_Load(obj,path);
	ObjSound_SetSoundDivision(obj,SOUND_SE);
	ObjSound_Play(obj);
}

function CreateEffectObject(px,py,img,blendtype,left,top,right,bottom){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	LoadTexture(img);
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,left,top,right,bottom);
	ObjSprite2D_SetDestCenter(obj);
	if(blendtype=="ALPHA"){
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	}
	if(blendtype=="RGB"){
	ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
	}
	if(blendtype=="ARGB"){
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	}
	ObjRender_SetPosition(obj,px,py,0);
	ObjMove_SetPosition(obj,px,py,);
	SetAutoDeleteObject(true);
	return obj;
}

function GetDistance(x1,y1,x2,y2){
	return(((x2-x1)^2+(y2-y1)^2)^(1/2));
}


task TExplosionA(x, y, dAlpha, dScale){
	let path = GetCurrentScriptDirectory ~ "/Enemy/STAR.jpg";
	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, 0, 0, 60, 60);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj, x, y, 0);
	ObjRender_SetAngleZ(obj,rand(0,360));

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

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

task TExplosionB(x, y, dAlpha, dScale,r,g,b){
	let path = GetCurrentScriptDirectory ~ "/Enemy/CIRCLE.jpg";
	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, 0, 0, 60, 60);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj, x, y, 0);
	ObjRender_SetAngleZ(obj,rand(0,360));
	
	let scale = 0;
	let alpha = 255;
	while(alpha > 0)
	{
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetColor(obj,r,g,b);
		ObjRender_SetScaleXYZ(obj, scale, scale, 0.5);

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

task TChargeEffectEnm(x,y){
	let img=GetCurrentScriptDirectory ~ "/Enemy/Leaf.png";
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,32,32);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
	let angle=rand(0,360);
	let angle2=rand(0,360);
	let sAngle=rand(-5,5);
	let R=125+rand(-25,25);
	let n=45;
	descent(i in 0..n){
		ObjRender_SetPosition(obj,x+R*(i/n)*cos(angle),y+R*(i/n)*sin(angle),0);
		let size=((i/n*4.5)+((i/n*4.5)/5))/0.75;
		ObjRender_SetScaleXYZ(obj,size,size,size);
		ascent(j in 0..4){
			ObjPrim_SetVertexColor(obj,j,(n-i)/n*255,(n-i)/n*255,(n-i)/n*255);
		}
		ObjRender_SetAngleZ(obj,angle2);
		angle2+=sAngle;
		angle2%=360;
		yield;
	}
	Obj_Delete(obj);
}