let boss = GetCurrentScriptDirectory~"myon.png";
let England = GetCurrentScriptDirectory~"boss.png";
let magic = GetCurrentScriptDirectory~"effect.png";
let aura = GetCurrentScriptDirectory~"Default_Glow.png";
let aura2 = GetCurrentScriptDirectory~"Default_Glow2.png";

task PIVItem(x,y,ang,speed){
let n = 0;
let a = 0;
let b;
let obj = ObjPrim_Create(OBJ_SPRITE_2D);
ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "default_system/img/Default_Lives.png");
Obj_SetRenderPriorityI(obj,29);
ObjRender_SetBlendType(obj,BLEND_ALPHA);
ObjRender_SetAlpha(obj,255);
ObjSprite2D_SetSourceRect(obj,0,0,16,16);
ObjSprite2D_SetDestRect(obj,-8,-8,+8,+8);			
	while(!Obj_IsDeleted(obj)){
			if(GetDistance(GetPlayerX,GetPlayerY,ObjRender_GetX(obj),ObjRender_GetY(obj))<=50&&n>30){
				break;
			}
			while(n>600){
				ObjRender_SetAlpha(obj,255-((n-600)*20));
				n++;
				if(n==700){Obj_Delete(obj);}
				yield;
			}
			if(n<30){ObjRender_SetPosition(obj,x+a*cos(ang),y+a*sin(ang),0);}
			ObjRender_SetScaleXYZ(obj,1.2+(sin(ang))/10,1.2+(sin(ang))/10,0.06/(30-n));
			ObjRender_SetAngleXYZ(obj,0,0,n);
			n+=1;
			a+=speed;
			speed-=1/30;
			yield;
		}
	b = 50;
	while(b>16){
		ObjRender_SetPosition(obj,GetPlayerX+(b)*cos(GetAngleToPlayer(obj)-180),GetPlayerY+(b)*sin(GetAngleToPlayer(obj)-180),0);
		b-=5;
		yield;	
	}
		SetCommonData("PIVITEM",GetCommonData("PIVITEM",500)+250);
		AddScore(250);
		CreatePoint(GetPlayerX+(b)*cos(GetAngleToPlayer(obj)-180),GetPlayerY+(b)*sin(GetAngleToPlayer(obj)-180));
		yield;
		Obj_Delete(obj);
	task CreatePoint(xpos,ypos){
		let objTxt = ObjText_Create();
		let c = 0;
		ObjText_SetText(objTxt,"250");
		Obj_SetRenderPriority(objTxt, 0.2);
		ObjText_SetHorizontalAlignment(objTxt,ALIGNMENT_LEFT);
		ObjText_SetFontSize(objTxt,12);
		ObjText_SetFontColorTop(objTxt,200,100,200);
		ObjText_SetFontColorBottom(objTxt,200,100,200);
		ObjText_SetFontBorderType(objTxt,BORDER_FULL);
		ObjText_SetFontBorderColor(objTxt,100,200,100);
		ObjText_SetFontBorderWidth(objTxt,0);
		loop(90){
			ObjRender_SetPosition(objTxt,xpos,ypos-(c/4),0);
			c++;
			yield;
		}
		Obj_Delete(objTxt);
	}
}
task DelaySE(s,w,v){
	loop(w){yield;}
	let SEobj = ObjSound_Create();
	ObjSound_Load(SEobj,s);
	ObjSound_SetSoundDivision(SEobj,"Sound_SE");
	ObjSound_SetLoopEnable(SEobj,false);
	ObjSound_Play(SEobj);				
	ObjSound_SetVolumeRate(SEobj,90+v);	
	}
task FadeDelete(obj,frames){ 
	loop(frames){yield;} 
	ObjShot_FadeDelete(obj);
}
	task Shake(count){
		loop(count){
			Set2DCameraFocusX(GetStgFrameWidth / 2 + rand(-8, 8));
			Set2DCameraFocusY(GetStgFrameHeight / 2 + rand(-8, 8));
			yield;
		}
		Reset2DCamera();
	}

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

function GetAngle(x1,y1,x2,y2){
	return atan2((y2-y1),(x2-x1));
}

function CreateCurvyLaserA1(xpos,ypos,speed,angle,len,width,trailgraphic,delay) {
	let obj = CreateShotA1(xpos,ypos,speed,angle,0,delay);
	ObjShot_SetIntersectionEnable(obj,false);
	LaserTrail;
	return obj;
	
	task LaserTrail {
		let del = len;
		let speed = 0;
		while(!Obj_IsDeleted(obj)) {
			speed = ObjMove_GetSpeed(obj);
			if(absolute(speed)>0) {
				if(round(9/absolute(speed))>=0) {
					FadeLaser(width,del);
					loop(round(9/absolute(speed))) { yield; }
				}
			}
			else { yield; }
		}
	}
	task FadeLaser(initwidth,del) {
		let objTrail = CreateStraightLaserA1(ObjMove_GetX(obj)-40*cos(ObjMove_GetAngle(obj)),ObjMove_GetY(obj)-40*sin(ObjMove_GetAngle(obj)),ObjMove_GetAngle(obj),120,initwidth,1200,trailgraphic,0);
		ObjStLaser_SetSource(objTrail,false);
		
		let initlength = 120;
		let width = initwidth;
		let len = initlength;
		let alpha = 255;
		loop(del) {
			//if(alpha<255) { alpha+=255/8; }
			width-=initwidth/del;
			len-=initlength/del;
			ObjRender_SetColor(objTrail,alpha,alpha,alpha);
			ObjLaser_SetIntersectionWidth(objTrail,width);
			ObjLaser_SetRenderWidth(objTrail,width);
			ObjLaser_SetLength(objTrail,len);
			yield;
		}
		Obj_Delete(objTrail);
	}
}
function CreateCurvyLaserA2(xpos,ypos,speed,angle,len,width,bulletgraphic,trailgraphic,delay) { //The bulletgraphic parameter is the graphic of the head bullet
	let obj = CreateShotA1(xpos,ypos,speed,angle,bulletgraphic,delay);
	LaserTrail;
	return obj;
	
	task LaserTrail {
		let del = len;
		let speed = 0;
		while(!Obj_IsDeleted(obj)) {
			speed = ObjMove_GetSpeed(obj);
			if(absolute(speed)>0) {
				if(round(9/absolute(speed))>=0) {
					FadeLaser(width,del);
					loop(round(9/absolute(speed))) { yield; }
				}
			}
			else { yield; }
		}
	}
	task FadeLaser(initwidth,del) {
		let objTrail = CreateStraightLaserA1(ObjMove_GetX(obj)-40*cos(ObjMove_GetAngle(obj)),ObjMove_GetY(obj)-40*sin(ObjMove_GetAngle(obj)),ObjMove_GetAngle(obj),120,initwidth,1200,trailgraphic,0);
		ObjStLaser_SetSource(objTrail,false);
		
		let initlength = 120;
		let width = initwidth;
		let len = initlength;
		let alpha = 255;
		loop(del) {
			//if(alpha<255) { alpha+=255/8; }
			width-=initwidth/del;
			len-=initlength/del;
			ObjRender_SetColor(objTrail,alpha,alpha,alpha);
			ObjLaser_SetIntersectionWidth(objTrail,width);
			ObjLaser_SetRenderWidth(objTrail,width);
			ObjLaser_SetLength(objTrail,len);
			yield;
		}
		Obj_Delete(objTrail);
	}
}
function CreateCurvyLaserB1(xpos,ypos,speed,angle,len,width,trailgraphic,trailrate,delay) { //The trailrate parameter is the spawn rate of the trail effect
	let obj = CreateShotA1(xpos,ypos,speed,angle,0,delay);
	if(trailrate<1) { RaiseError("The laser trail spawn rate must not be less than 1"); }
	ObjShot_SetIntersectionEnable(obj,false);
	LaserTrail;
	return obj;
	
	task LaserTrail {
		let del = len;
		let speed = 0;
		while(!Obj_IsDeleted(obj)) {
			FadeLaser(width,del);
			loop(trailrate) { yield; }
		}
	}
	task FadeLaser(initwidth,del) {
		let objTrail = CreateStraightLaserA1(ObjMove_GetX(obj)-40*cos(ObjMove_GetAngle(obj)),ObjMove_GetY(obj)-40*sin(ObjMove_GetAngle(obj)),ObjMove_GetAngle(obj),120,initwidth,1200,trailgraphic,0);
		ObjStLaser_SetSource(objTrail,false);
		
		let initlength = 120;
		let width = initwidth;
		let len = initlength;
		let alpha = 255;
		loop(del) {
			//if(alpha<255) { alpha+=255/8; }
			width-=initwidth/del;
			len-=initlength/del;
			ObjRender_SetColor(objTrail,alpha,alpha,alpha);
			ObjLaser_SetIntersectionWidth(objTrail,width);
			ObjLaser_SetRenderWidth(objTrail,width);
			ObjLaser_SetLength(objTrail,len);
			yield;
		}
		Obj_Delete(objTrail);
	}
}
function CreateCurvyLaserB2(xpos,ypos,speed,angle,len,width,bulletgraphic,trailgraphic,trailrate,delay) { //The bulletgraphic parameter is the graphic of the head bullet
	let obj = CreateShotA1(xpos,ypos,speed,angle,bulletgraphic,delay);
	if(trailrate<1) { RaiseError("The laser trail spawn rate must not be less than 1"); }
	LaserTrail;
	return obj;
	
	task LaserTrail {
		let del = len;
		let speed = 0;
		while(!Obj_IsDeleted(obj)) {
			FadeLaser(width,del);
			loop(trailrate) { yield; }
		}
	}
	task FadeLaser(initwidth,del) {
		let objTrail = CreateStraightLaserA1(ObjMove_GetX(obj)-40*cos(ObjMove_GetAngle(obj)),ObjMove_GetY(obj)-40*sin(ObjMove_GetAngle(obj)),ObjMove_GetAngle(obj),120,initwidth,1200,trailgraphic,0);
		ObjStLaser_SetSource(objTrail,false);
		
		let initlength = 120;
		let width = initwidth;
		let len = initlength;
		let alpha = 255;
		loop(del) {
			//if(alpha<255) { alpha+=255/8; }
			width-=initwidth/del;
			len-=initlength/del;
			ObjRender_SetColor(objTrail,alpha,alpha,alpha);
			ObjLaser_SetIntersectionWidth(objTrail,width);
			ObjLaser_SetRenderWidth(objTrail,width);
			ObjLaser_SetLength(objTrail,len);
			yield;
		}
		Obj_Delete(objTrail);
	}
}