let boss = GetCurrentScriptDirectory~"myon.png";
let England = GetCurrentScriptDirectory~"boss.png";
let magic = GetCurrentScriptDirectory~"default_system/img/circle.png";
let aura = GetCurrentScriptDirectory~"default_system/img/Default_Glow.png";
let aura2 = GetCurrentScriptDirectory~"default_system/img/Default_Glow2.png";

	let SShot1 = ObjSound_Create();
	let SShot2 = ObjSound_Create();
	let SShot3 = ObjSound_Create();
	let SShot4 = ObjSound_Create();
	let SBoon1 = ObjSound_Create();
	let SBoon2 = ObjSound_Create();
	let SExplode1 = ObjSound_Create();
	let SCharge1 = ObjSound_Create();
	let SCharge2 = ObjSound_Create();
	let SSlash1 = ObjSound_Create();
	let SDead1 = ObjSound_Create();
	let SNote1 = ObjSound_Create();
	let SNote2 = ObjSound_Create();
	let SNote3 = ObjSound_Create();
	let SHeal1 = ObjSound_Create();
	let SLaser1 = ObjSound_Create();
	let SLaser2 = ObjSound_Create();
	let SFam1 = ObjSound_Create();
	ObjSound_Load(SShot1,GetMainStgScriptDirectory~"ZUN/se_kira00.wav");
	ObjSound_Load(SShot2,GetMainStgScriptDirectory~"ZUN/se_tan00.wav");
	ObjSound_Load(SShot3,GetMainStgScriptDirectory~"ZUN/se_tan01.wav");
	ObjSound_Load(SShot4,GetMainStgScriptDirectory~"ZUN/se_tan02.wav");
	ObjSound_Load(SBoon1,GetMainStgScriptDirectory~"ZUN/se_boon01.wav");
	ObjSound_Load(SBoon2,GetMainStgScriptDirectory~"ZUN/se_boon00.wav");
	ObjSound_Load(SExplode1,GetMainStgScriptDirectory~"ZUN/se_enep02.wav");
	ObjSound_Load(SCharge1,GetMainStgScriptDirectory~"ZUN/se_ch02.wav");
	ObjSound_Load(SCharge2,GetMainStgScriptDirectory~"ZUN/se_ch00.wav");
	ObjSound_Load(SSlash1,GetMainStgScriptDirectory~"ZUN/se_slash.wav");
	ObjSound_Load(SDead1,GetMainStgScriptDirectory~"ZUN/se_enep00.wav");
	ObjSound_Load(SNote1,GetMainStgScriptDirectory~"ZUN/se_lgods1.wav");
	ObjSound_Load(SNote2,GetMainStgScriptDirectory~"ZUN/se_lgods2.wav");
	ObjSound_Load(SNote3,GetMainStgScriptDirectory~"ZUN/se_lgods3.wav");
	ObjSound_Load(SHeal1,GetMainStgScriptDirectory~"ZUN/se_heal.wav");
	ObjSound_Load(SLaser1,GetMainStgScriptDirectory~"ZUN/se_lazer02.wav");
	ObjSound_Load(SLaser2,GetMainStgScriptDirectory~"ZUN/se_lazer01.wav");
	ObjSound_Load(SFam1,GetMainStgScriptDirectory~"ZUN/se_option.wav");

function CreateObjShotB1(x, y, xspd, yspd, graph, delay){
	let shot = ObjShot_Create(OBJ_SHOT);
	CreateObjShotBC1(shot, x, y, xspd, yspd, graph, delay);
	return shot;
}

task CreateObjShotBC1(objShot, x, y, xspd, yspd, graph, delay){
	ObjShot_Regist(objShot);
	ObjMove_SetPosition(objShot, x, y);
	let ang = GetAngle(x, y, x+xspd, y+yspd);
	let spd = GetDistance(x, y, x+xspd, y+yspd);
	ObjMove_SetAngle(objShot, ang);
	ObjShot_SetGraphic(objShot, graph);
	
	ObjShot_SetIntersectionEnable(objShot, false);
	let i = 0;
	while(i<delay&&!Obj_IsDeleted(objShot)){
		let alpf = i*(225/delay);
		let scl = (delay-i)*(1.75/delay);
		ObjRender_SetScaleXYZ(objShot, scl+1, scl+1, 1);
		ObjRender_SetAlpha(objShot, min(255, alpf-35));
		i+=1;
		yield;
	}
	ObjShot_SetIntersectionEnable(objShot, true);
	ObjRender_SetScaleXYZ(objShot, 1, 1, 1);
	ObjRender_SetAlpha(objShot, 255);
	ObjMove_SetSpeed(objShot, spd);	
}

function CreateObjShotA1(x, y, spd, ang, graph, delay){
	let shot = ObjShot_Create(OBJ_SHOT);
	CreateObjShotAC1(shot, x, y, spd, ang, graph, delay);
	return shot;
}

task CreateObjShotAC1(objShot, x, y, spd, ang, graph, delay){
	ObjShot_Regist(objShot);
	ObjMove_SetPosition(objShot, x, y);
	ObjMove_SetAngle(objShot, ang);
	ObjShot_SetGraphic(objShot, graph);
	
	ObjShot_SetIntersectionEnable(objShot, false);
	let i = 0;
	while(i<delay&&!Obj_IsDeleted(objShot)){
		let alpf = i*(225/delay);
		let scl = (delay-i)*(1.75/delay);
		ObjRender_SetScaleXYZ(objShot, scl+1, scl+1, 1);
		ObjRender_SetAlpha(objShot, min(255, alpf-35));
		i+=1;
		yield;
	}
	ObjShot_SetIntersectionEnable(objShot, true);
	ObjRender_SetScaleXYZ(objShot, 1, 1, 1);
	ObjRender_SetAlpha(objShot, 255);
	ObjMove_SetSpeed(objShot, spd);	
}

function CreateObjShotA2(x, y, spd, ang, acc, mspd, graph, delay){
	let shot = ObjShot_Create(OBJ_SHOT);
	CreateObjShotAC2(shot, x, y, spd, ang, acc, mspd, graph, delay);
	return shot;
}

task CreateObjShotAC2(objShot, x, y, spd, ang, acc, mspd, graph, delay){
	acc = absolute(acc);
	ObjShot_Regist(objShot);
	ObjMove_SetPosition(objShot, x, y);
	ObjMove_SetAngle(objShot, ang);
	ObjShot_SetGraphic(objShot, graph);
	
	ObjShot_SetIntersectionEnable(objShot, false);
	let i = 0;
	while(i<delay&&!Obj_IsDeleted(objShot)){
		let alpf = i*(225/delay);
		let scl = (delay-i)*(1.75/delay);
		ObjRender_SetScaleXYZ(objShot, scl+1, scl+1, 1);
		ObjRender_SetAlpha(objShot, min(255, alpf-35));
		i+=1;
		yield;
	}
	ObjShot_SetIntersectionEnable(objShot, true);
	ObjRender_SetScaleXYZ(objShot, 1, 1, 1);
	ObjRender_SetAlpha(objShot, 255);
	ObjMove_SetSpeed(objShot, spd);
	if(spd>mspd){
		while(!Obj_IsDeleted(objShot)&&ObjMove_GetSpeed(objShot)>mspd){
			ObjMove_SetSpeed(objShot,ObjMove_GetSpeed(objShot)-acc);
			yield;
		}
	} else if(spd<mspd){
		while(!Obj_IsDeleted(objShot)&&ObjMove_GetSpeed(objShot)<mspd){
			ObjMove_SetSpeed(objShot,ObjMove_GetSpeed(objShot)+acc);
			yield;
		}
	}
}
	task wallBounceSNB(obj){
		while(!Obj_IsDeleted(obj)){
		if(ObjMove_GetX(obj)<0||ObjMove_GetX(obj)>GetStgFrameWidth){
			ObjMove_SetAngle(obj,180-ObjMove_GetAngle(obj));
			return;
		}
		if(ObjMove_GetY(obj)<0){
			ObjMove_SetAngle(obj,360-ObjMove_GetAngle(obj));
			return;
		}
		yield;
		}
	}
	task wallBounceS(obj){
		while(!Obj_IsDeleted(obj)){
		if(ObjMove_GetX(obj)<0||ObjMove_GetX(obj)>GetStgFrameWidth){
			ObjMove_SetAngle(obj,180-ObjMove_GetAngle(obj));
			return;
		}
		if(ObjMove_GetY(obj)<0||ObjMove_GetY(obj)>GetStgFrameHeight){
			ObjMove_SetAngle(obj,360-ObjMove_GetAngle(obj));
			return;
		}
		yield;
		}
	}
task death(x,y,time,R,G,B){
		let dplus = 0;
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		LoadTexture(GetCurrentScriptDirectory~"default_system/img/Default_Effect.png");
		ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"default_system/img/Default_Effect.png");
		ObjPrim_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
		ObjPrim_SetVertexCount(obj,4);
		ObjPrim_SetVertexUVT(obj,0,0,0);
		ObjPrim_SetVertexUVT(obj,1,0,64);
		ObjPrim_SetVertexUVT(obj,2,64,0);
		ObjPrim_SetVertexUVT(obj,3,64,64);
		ObjPrim_SetVertexPosition(obj,0,-32,-32,0);
		ObjPrim_SetVertexPosition(obj,1,-32,32,0);
		ObjPrim_SetVertexPosition(obj,2,32,-32,0);
		ObjPrim_SetVertexPosition(obj,3,32,32,0);
		Obj_SetRenderPriorityI(obj,24);
		ObjRender_SetColor(obj,R,G,B);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjRender_SetAlpha(obj,100);
		ObjRender_SetPosition(obj,x,y,0);
		loop(10){
			ObjRender_SetScaleXYZ(obj,rand(0,0.5)-dplus,rand(0,0.5)-dplus,rand(0,0.5)-dplus);
			dplus-=1/10;
			yield;
			}
		Obj_Delete(obj);
		}
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 LargePIVItem(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,3+(sin(ang))/10,3+(sin(ang))/10,0.06/(30-n));
			ObjRender_SetAngleXYZ(obj,0,0,0);
			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)+100000);
		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,"100000");
		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(SEobj,w,v,p){
	loop(w){yield;}
	ObjSound_SetSoundDivision(SEobj,"Sound_SE");
	ObjSound_SetLoopEnable(SEobj,false);
	ObjSound_Play(SEobj);				
	ObjSound_SetVolumeRate(SEobj,90+v);	
	ObjSound_SetPanRate(SEobj,p);
	}
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 GetObjDistance(objA,objB){
	let x1 = ObjMove_GetX(objA);
	let x2 = ObjMove_GetX(objB);
	let y1 = ObjMove_GetX(objA);
	let y2 = ObjMove_GetX(objB);
	return ((x2-x1)^2 + (y1-y2)^2)^(1/2);
}

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

function GetObjAngle(objA,objB){
	let x1 = ObjMove_GetX(objA);
	let x2 = ObjMove_GetX(objB);
	let y1 = ObjMove_GetX(objA);
	let y2 = ObjMove_GetX(objB);
	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);
	}
}