task DelayCloudBulletA1(x,y,speed,angle,graphic,delay){
	let bullet = CreateShotA1(x,y,speed,angle,graphic,delay);
	let saveSpeed = speed;
	let i = 0;
	ObjMove_SetSpeed(bullet, 0);
	while(i<=10){
		i+=1;
		ObjShot_SetIntersectionEnable(bullet, false);
		ObjRender_SetScaleXYZ(bullet, 2 - 1/10*i, 2-1/10*i,0);
		ObjRender_SetAlpha(bullet, 255/10*i);
		yield;
	}
	ObjShot_SetIntersectionEnable(bullet, true);
	ObjMove_SetSpeed(bullet, saveSpeed);
}

task DelayCloudBulletA1AngVel(x,y,speed,angle,graphic,delay,angvel,stop){
	let bullet = CreateShotA1(x,y,speed,angle,graphic,delay);
	let saveSpeed = speed;
	let i = 0;
	ObjMove_SetSpeed(bullet, 0);
	while(i<=10){
		i+=1;
		ObjShot_SetIntersectionEnable(bullet, false);
		ObjRender_SetScaleXYZ(bullet, 2 - 1/10*i, 2-1/10*i,0);
		ObjRender_SetAlpha(bullet, 255/10*i);
		yield;
	}
	ObjShot_SetIntersectionEnable(bullet, true);
	ObjMove_SetSpeed(bullet, saveSpeed);
	i = 0;
	while(!Obj_IsDeleted(bullet)){
		ObjMove_SetAngularVelocity(bullet, angvel);
		i++;
		if(i>stop){
		ObjMove_SetAngularVelocity(bullet, 0);
		}
		yield;
	}
}

task PlaySound(soundID){
let dir = GetCurrentScriptDirectory;
let objSound = ObjSound_Create();
ObjSound_Load(objSound, dir~"sfx/"~soundID~".wav");
ObjSound_SetVolumeRate(objSound, 90);
ObjSound_Play(objSound);
yield;
}

task Circle(object){
	let objx = ObjMove_GetX(object);
	let objy = ObjMove_GetY(object);
	let texture = GetCurrentScriptDirectory~"/img/img_circle.png";
	let objCircle = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriority(objCircle, 0.23);
	ObjPrim_SetTexture(objCircle, texture);
	ObjSprite2D_SetSourceRect(objCircle,0,0,256,256);
	ObjSprite2D_SetDestCenter(objCircle);
	let ct = 0;
	while(!Obj_IsDeleted(object)){
		objx = ObjMove_GetX(object);
		objy = ObjMove_GetY(object);
		ObjRender_SetPosition(objCircle, objx, objy, 0);
		ObjRender_SetScaleXYZ(objCircle, 1.5+0.25*sin(ct*2), 1.5+0.25*sin(ct*2), 0);
		ObjRender_SetAngleXYZ(objCircle, 0, 0, ct*4);
		ct++;
		yield;
	}
	Obj_Delete(objCircle);
}

task Explode(object){
	let objx = ObjMove_GetX(object);
	let objy = ObjMove_GetY(object);

	loop(20){light1(rand(0,360),rand(2,4),rand(0.6,1.2));}
	boom1(0,3,1);
	yield;

	task light1(angle, speed,scale){
		let texture = GetCurrentScriptDirectory~"img_light.png";
		let light = ObjPrim_Create(OBJ_SPRITE_2D);
		let alpha = 255;
		let rendang = rand(0,360);
		let count = 0;
		let pos = 0;
		let decel=-0.05;
		ObjPrim_SetTexture(light, texture);
		ObjRender_SetScaleXYZ(light,scale,scale,scale);
		ObjSprite2D_SetSourceRect(light,0,0,32,32);
		ObjSprite2D_SetDestCenter(light);
		ObjRender_SetPosition(light, objx, objy, 0);
		ObjRender_SetAngleXYZ(light,0,0,0);
		ObjMove_SetPosition(light, objx, objy);
		ObjMove_SetAngle(light, angle);
		ObjMove_SetSpeed(light, speed);
		ObjMove_SetAcceleration(light, -0.005);
		while(!Obj_IsDeleted(light)){
			count+=1;
			ObjRender_SetAlpha(light, 255-count*5.67);
			ObjRender_SetAngleXYZ(light, rendang+count, rendang-count, rendang-count);
			ObjRender_SetPosition(light,objx+pos*cos(angle),objy+pos*sin(angle),0);
			pos+=speed;
			speed+=decel;
			if(count==45){Obj_Delete(light);}
			yield;
		}
		yield;
	}

	task boom1(angle, speed,scale){
		let texture = GetCurrentScriptDirectory~"img_boom1.png";
		let light = ObjPrim_Create(OBJ_SPRITE_2D);
		let alpha = 255;		
		let count = 0;
		let pos = 0;
		let decel=-0.05;
		ObjPrim_SetTexture(light, texture);
		ObjRender_SetScaleXYZ(light,scale,scale,scale);
		ObjSprite2D_SetSourceRect(light,0,0,64,64);
		ObjSprite2D_SetDestCenter(light);
		ObjRender_SetPosition(light, objx, objy, 0);
		ObjRender_SetAngleXYZ(light,0,0,0);
		ObjMove_SetPosition(light, objx, objy);
		ObjMove_SetAngle(light, angle);
		ObjMove_SetSpeed(light, speed);
		ObjMove_SetAcceleration(light, -0.005);
		while(!Obj_IsDeleted(light)){
			count+=1;
			ObjRender_SetAlpha(light, 255-count*8.5);
			ObjRender_SetScaleXYZ(light,1.5*scale*sin(count*3),1.5*scale*sin(count*3),1.5*scale*sin(count*3));
			pos+=speed;
			speed+=decel;
			if(count==30){Obj_Delete(light);}
			yield;
		}
		yield;
	}
}