
let dirCurrent = GetCurrentScriptDirectory();
let pathHealth = dirCurrent ~ "img/lifebar.png";
let objEnemy = GetEnemyBossObjectID;
let quality = 2;
let win = dirCurrent ~ "se/cardget.wav";
let fail = dirCurrent ~ "se/fail.wav";
let extend = dirCurrent ~ "se/extend.wav";
InstallFont(dirCurrent ~ "font/Eurosti.ttf");
InstallFont(dirCurrent ~ "font/THSpatial.ttf");
InstallFont(dirCurrent ~ "font/replay.ttc");

@Initialize
{
	SetPauseScriptPath(dirCurrent ~ "Pause.txt");
	SetEndSceneScriptPath(dirCurrent ~"End.txt");
	TScore();
	TGraze();
	TPlayerLife();
	TPlayerSpell();
	TBossLife;
	TBossTimer;
	TCurrentFps();
	TReplayFps();
	SetStgFrame(0, 0, GetScreenWidth, GetScreenHeight, 20, 80);
	SetPlayerClip(8, 16, GetScreenWidth-8, GetScreenHeight-16);
}

@MainLoop
{
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_START_BOSS_SPELL)
	{
		let path = dirCurrent ~ "MagicCircle.txt";
		let id = LoadScript(path);
		StartScript(id);
	}
	case(EV_GAIN_SPELL)
	{
		let objScene = GetEnemyBossSceneObjectID();
		let score = ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE);
		TGainSpell(score);
		TExtends("BOMB");
		TExtends("LIFE");
	}
	
}

function Play(path)
{
	LoadSound(path);
	PlaySE(path);
}

//----------------------------------------------------
//スコア表示
//----------------------------------------------------
task TScore()
{
	//Score文字列
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, "Score:");
	ObjText_SetFontType(objScore,"Eurostile");
	ObjText_SetFontSize(objScore, 20);
	ObjText_SetFontBold(objScore, true);
	ObjText_SetFontColorTop(objScore, 255, 128, 128);
	ObjText_SetFontColorBottom(objScore, 255, 64, 64);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore,0, 0, 0);
	ObjText_SetFontBorderWidth(objScore, 2);
	Obj_SetRenderPriority(objScore, 0.76);
	ObjRender_SetX(objScore, 8);
	ObjRender_SetY(objScore, 2);

	//得点
	let pathDigit = GetCurrentScriptDirectory() ~ "img/Number.png";
	let count = 12;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.76);
	ObjRender_SetY(obj, 4);
	ObjRender_SetScaleXYZ(obj,0.9,0.9,0.9);

	while(true)
	{
		let score = GetScore();
		score = min(score, 999999999999);
		let listNum = DigitToArray(score, count);

		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 76 + iObj * 12);
			ObjSpriteList2D_SetSourceRect(obj, num * 36, 0, (num + 1) * 36, 32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 24);
			ObjSpriteList2D_AddVertex(obj);
		}
		yield;
	}
}

//----------------------------------------------------
//Graze表示
//----------------------------------------------------
task TGraze()
{
	//Graze文字列
	let objGraze = ObjText_Create();
	ObjText_SetText(objGraze, "Graze:");
	ObjText_SetFontType(objGraze,"Eurostile");
	ObjText_SetFontSize(objGraze, 20);
	ObjText_SetFontBold(objGraze, true);
	ObjText_SetFontColorTop(objGraze, 255, 128, 128);
	ObjText_SetFontColorBottom(objGraze, 255, 64, 64);
	ObjText_SetFontBorderType(objGraze, BORDER_FULL);
	ObjText_SetFontBorderColor(objGraze,0, 0, 0);
	ObjText_SetFontBorderWidth(objGraze, 2);
	Obj_SetRenderPriority(objGraze, 0.76);
	ObjRender_SetX(objGraze, 8);
	ObjRender_SetY(objGraze, 22);

	//得点
	let pathDigit = GetCurrentScriptDirectory() ~ "img/Number.png";
	let count = 5;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.76);
	ObjRender_SetY(obj, 24);
	ObjRender_SetScaleXYZ(obj,0.9,0.9,0.9);

	while(true)
	{
		let graze = GetGraze();
		graze = min(graze, 99999);
		let listNum = DigitToArray(graze, count);

		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 76 + iObj * 12);
			ObjSpriteList2D_SetSourceRect(obj, num * 36, 0, (num + 1) * 36, 32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 24);
			ObjSpriteList2D_AddVertex(obj);
		}
		yield;
	}
}

//----------------------------------------------------
//残機表示
//----------------------------------------------------
task TPlayerLife
{
	//残機
	let pathDigit = GetCurrentScriptDirectory() ~ "img/HUD.png";
	let pathDigit2 = GetCurrentScriptDirectory() ~ "img/HUD On.png";
	let count = 8;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.76);
	ObjRender_SetY(obj, 8);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	
	let obj1 = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj1, pathDigit2);
	ObjRender_SetBlendType(obj1, BLEND_ALPHA);
	Obj_SetRenderPriority(obj1, 0.76);
	ObjRender_SetY(obj1, 8);
	ObjRender_SetScaleXYZ(obj1,1,1,1);

	while(true)
	{
		let point = GetPlayerLife();

		ObjSpriteList2D_ClearVertexCount(obj);
		ObjSpriteList2D_ClearVertexCount(obj1);
		ascent(iObj in 0 .. count)
		{
			ObjRender_SetX(obj, GetScreenWidth-152 + iObj * 16);
			ObjSpriteList2D_SetSourceRect(obj, 16, 0, 32, 16);
			ObjSpriteList2D_SetDestRect(obj, 16, 0, 32, 16);
			ObjSpriteList2D_AddVertex(obj);
		}
			if(point>0){
			ObjRender_SetX(obj1, GetScreenWidth-136);
			ObjSpriteList2D_SetSourceRect(obj1, 0, 0, 16 * point, 16);
			ObjSpriteList2D_SetDestRect(obj1, 0, 0, 16 * point, 16);
			ObjSpriteList2D_AddVertex(obj1);
			}
			
		yield;
	}
}

//----------------------------------------------------
//残スペル表示
//----------------------------------------------------
task TPlayerSpell
{

	let pathDigit = GetCurrentScriptDirectory() ~ "img/HUD.png";
	let pathDigit2 = GetCurrentScriptDirectory() ~ "img/HUD On.png";
	let count = 8;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.76);
	ObjRender_SetY(obj, 9);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	
	let obj1 = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj1, pathDigit2);
	ObjRender_SetBlendType(obj1, BLEND_ALPHA);
	Obj_SetRenderPriority(obj1, 0.76);
	ObjRender_SetY(obj1, 9);
	ObjRender_SetScaleXYZ(obj1,1,1,1);

	while(true)
	{
		let point = GetPlayerSpell();

		ObjSpriteList2D_ClearVertexCount(obj);
		ObjSpriteList2D_ClearVertexCount(obj1);
		ascent(iObj in 0 .. count)
		{
			ObjRender_SetX(obj, GetScreenWidth-152 + iObj * 16);
			ObjSpriteList2D_SetSourceRect(obj, 16, 16, 32, 32);
			ObjSpriteList2D_SetDestRect(obj, 16, 16, 32, 32);
			ObjSpriteList2D_AddVertex(obj);
		}
			if(point>0){
			ObjRender_SetX(obj1, GetScreenWidth-136);
			ObjSpriteList2D_SetSourceRect(obj1, 0, 16, 16 * point, 32);
			ObjSpriteList2D_SetDestRect(obj1, 0, 16, 16 * point, 32);
			ObjSpriteList2D_AddVertex(obj1);
			}
			
		yield;
	}
}

//----------------------------------------------------
//ボスのライフ表示
//----------------------------------------------------
task TBossLife{
	let path = pathHealth;
	let countVertex = 100;
	let objScene = ID_INVALID;
	
	let objStar = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(objStar, GetCurrentScriptDirectory ~ "img/frame2.png");
	Obj_SetRenderPriority(objStar, 0.7);
	ObjSpriteList2D_SetSourceRect(objStar, 144, 80, 156, 92);

	let objLife = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(objLife, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(objLife, countVertex);
	ObjRender_SetBlendType(objLife, BLEND_ALPHA);
	Obj_SetRenderPriority(objLife, 0.69);
	ObjPrim_SetTexture(objLife, path);

	let objOutline = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(objOutline, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(objOutline, countVertex);
	ObjRender_SetBlendType(objOutline, BLEND_ALPHA);
	Obj_SetRenderPriority(objOutline, 0.68);
	ObjPrim_SetTexture(objOutline, path);

	let objKnub = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(objKnub, path);
	Obj_SetRenderPriority(objKnub, 0.69);
	ObjSpriteList2D_SetSourceRect(objKnub, 20, 0, 29, 11);
	ObjSpriteList2D_SetDestRect(objKnub, -2.5, -3, 2.5, 3);

	ascent (iVert in 0..countVertex/2){
		let vertex = iVert * 2;
		ObjPrim_SetVertexUVT(objLife, vertex+0, 0, 0);
		ObjPrim_SetVertexUVT(objLife, vertex+1, 10, 32);
		ObjPrim_SetVertexUVT(objOutline, vertex+0, 10, 0);
		ObjPrim_SetVertexUVT(objOutline, vertex+1, 19, 32);
	}

	let mx = 0;
	let my = 0;
	let fade = 255;
	let fadec = 255;
	let maxRadius = 54;

	let lastRemStep = 0;
	let countRemStep = ObjEnemyBossScene_GetInfo(objScene, INFO_REMAIN_STEP_COUNT);
	let lifeRateRender = 0;
	let outlineRender = 0;

	let lifeTotalMax = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_TOTAL_MAX_LIFE);
	let lifeTotal = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_TOTAL_LIFE);
	let lifeRate = min(lifeTotal / lifeTotalMax, lifeRateRender);



	ObjRender_SetScaleXYZ(objLife, -1, 1, 1);
	ObjRender_SetScaleXYZ(objOutline, -1, 1, 1);

	ObjRender_SetPosition(objStar, GetScreenWidth/2-24, 40, 0);

	while(GetCommonData("quality", 2)==quality){
		ObjSpriteList2D_ClearVertexCount(objStar);
		ObjSpriteList2D_ClearVertexCount(objKnub);


		if(outlineRender<1){
			ObjRender_SetAlpha(objStar, min(255, 255*(outlineRender*3)-510));
		}else{
			if(GetPlayerY < max(96, 26+(truncate(countRemStep/12)*12))){
				fade = max(fade-10, 85);
			}else{fade = min(fade+10, 255);}
			ObjRender_SetAlpha(objStar, fade);
		}


		objScene = GetEnemyBossSceneObjectID;
		if(objScene != ID_INVALID){
			let Boss = GetEnemyBossObjectID;
			Boss = Boss ~ [objLife];
			mx = ObjRender_GetX(Boss[0]);
			my = ObjRender_GetY(Boss[0]);
		}else{
			mx = -400;
			my = -400;
			outlineRender = 0;
			lifeRateRender = 0;
		}
		RefreshVertex(objLife);

		if(GetDistance(GetPlayerX,GetPlayerY,mx,my)<maxRadius*1.75){
			fadec = max(fadec-10, 85);
		}else{fadec = min(fadec+10, 255);}
		ObjRender_SetAlpha(objKnub, (fadec/100)*(lifeRateRender*100));
		ObjRender_SetAlpha(objOutline, fadec);
		ObjRender_SetAlpha(objLife, fadec);

		if(GetCommonData("ForceLifebar", 0) != 0){
			outlineRender = 0;
			lifeRateRender = 0;
		}


		lastRemStep = countRemStep;

		yield;
	}
	Obj_Delete(objStar);
	Obj_Delete(objKnub);
	Obj_Delete(objOutline);
	Obj_Delete(objLife);

	task RefreshVertex(objid){
		countRemStep = ObjEnemyBossScene_GetInfo(objScene, INFO_REMAIN_STEP_COUNT);
		if(lastRemStep != countRemStep){
			lifeRateRender = 0;
		}
		ascent(iStep in 0 .. countRemStep){
			ObjSpriteList2D_SetSourceRect(objStar, 144, 80, 156, 92);
			let y = truncate((iStep)/12)*12;
			let i = iStep-(12*(y/12));
			ObjSpriteList2D_SetDestRect(objStar, 4 + i * 12, 4+y,
				4 + (i + 1) * 12, 16+y);
			ObjSpriteList2D_AddVertex(objStar);
		}

		let listLifeDiv = [0]~ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_LIFE_RATE_LIST);
		ascent(iDiv in 0 .. length(listLifeDiv)){
			let kang = 360*(listLifeDiv[iDiv]);
			let kx = mx+(maxRadius*1.05)*cos(kang-90);
			let ky = my+(maxRadius*1.05)*sin(kang-90);
			if(1-listLifeDiv[iDiv]<lifeTotal / lifeTotalMax-0.000001){
				ObjRender_SetPosition(objKnub, kx, ky, 0);
				ObjRender_SetAngleZ(objKnub, kang);
				ObjSpriteList2D_AddVertex(objKnub);
			}
		}

		lifeTotalMax = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_TOTAL_MAX_LIFE);
		lifeTotal = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_TOTAL_LIFE);
		lifeRate = min(lifeTotal / lifeTotalMax, lifeRateRender);



		ascent(iVert in 0..countVertex/2){
			let indexVert = iVert * 2;
			let angle = (360 / (countVertex/2 - 1) * iVert);
			angle = min(360*(outlineRender), angle);
			let x = (maxRadius)*cos(angle-90);
			let y = (maxRadius)*sin(angle-90);
			ObjPrim_SetVertexPosition(objOutline, indexVert + 0 , x, y, 0);
			x = (maxRadius*1.1)*cos(angle-90);
			y = (maxRadius*1.1)*sin(angle-90);
			ObjPrim_SetVertexPosition(objOutline, indexVert + 1 , x, y, 0);

			angle = min(360*(lifeRate), angle);
			x = (maxRadius)*cos(angle-90);
			y = (maxRadius)*sin(angle-90);
			ObjPrim_SetVertexPosition(objLife, indexVert + 0 , x, y, 0);
			x = (maxRadius*1.1)*cos(angle-90);
			y = (maxRadius*1.1)*sin(angle-90);
			ObjPrim_SetVertexPosition(objLife, indexVert + 1 , x, y, 0);
		}
		ObjRender_SetPosition(objLife, mx, my, 0);
		ObjRender_SetPosition(objOutline, mx, my, 0);

		lifeRateRender = min(1, lifeRateRender+0.02);
		outlineRender = min(1, outlineRender+0.016);
		
	}
}

task TBossTimer{
	let pathDigit = GetCurrentScriptDirectory() ~ "img/Number.png";

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriority(obj, 0.75);
	ObjRender_SetY(obj, 8);
	let count = 2;

	let objScene = ID_INVALID;
	loop
	{
		objScene = GetEnemyBossSceneObjectID();
		ObjSpriteList2D_ClearVertexCount(obj);
		if(objScene != ID_INVALID)
		{
			RenderTimer();
		}
		yield;
	}

	function RenderTimer()
	{
		let timer = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER);
		timer = min(timer, 99);
		let listNum = DigitToArray(timer, count);

		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, GetScreenWidth/2 - 16 + iObj * 16);
			ObjSpriteList2D_SetSourceRect(obj, num * 36, 0, (num + 1) * 36, 32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 24);
			ObjSpriteList2D_AddVertex(obj);
		}
	}

}

task TExtends(type){
	
		if(type=="BOMB"){
			Play(extend);
			SetPlayerSpell(GetPlayerSpell+1);
		}
		
		if(type=="LIFE"){
			Play(extend);
			SetPlayerLife(GetPlayerLife+1);
			let banObj = ObjPrim_Create(OBJ_SPRITE_2D);
			let alpha = 0;
			ObjPrim_SetTexture(banObj,GetCurrentScriptDirectory ~ "img/Bonuses.png");
			ObjSprite2D_SetDestRect(banObj,0,0,256,32);
			ObjSprite2D_SetSourceRect(banObj,0,0,256,32);
			ObjSprite2D_SetDestCenter(banObj);
			ObjRender_SetScaleXYZ(banObj,1.25,1.25,1.25);
			ObjRender_SetAlpha(banObj,0);
			ObjRender_SetPosition(banObj,GetStgFrameWidth/2,GetStgFrameHeight/2-96,0);
			loop(25){
				ObjRender_SetAlpha(banObj,alpha);
				alpha+=10;
				yield;
			}	
			loop(120){yield;}
			loop(25){
				ObjRender_SetAlpha(banObj,alpha);
				alpha-=10;
				yield;
			}
			Obj_Delete(banObj);
		}
}

//----------------------------------------------------
//スペルカード取得表示
//----------------------------------------------------
task TGainSpell(score)
{
	let alpha = 0;
	Play(win);
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,dirCurrent ~ "img/Bonuses.png");
	ObjSprite2D_SetSourceRect(obj,0,32,256,64);
	ObjSprite2D_SetDestRect(obj,-128,32,128,63);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2-192,0);
	ObjRender_SetAlpha(obj,0);

	let strScore = "+" ~ IntToString(score);
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, strScore);
	ObjText_SetFontSize(objScore, 40);
	ObjText_SetFontBold(objScore, true);
	ObjText_SetFontType(objScore, "Russell Square Regular");
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 64, 64, 64);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore,0, 0, 0);
	ObjText_SetFontBorderWidth(objScore, 1);
	Obj_SetRenderPriority(objScore, 0.6);
	ObjRender_SetX(objScore, GetScreenWidth/2-32);
	ObjRender_SetY(objScore, 230);
	ObjRender_SetAlpha(objScore,0);

	loop(50){
		ObjRender_SetAlpha(obj,alpha);
		ObjRender_SetAlpha(objScore,alpha);
		alpha+=5;
		yield;
	}
	loop(120)
	{
		yield;
	}
	loop(50){
		ObjRender_SetAlpha(obj,alpha);
		ObjRender_SetAlpha(objScore,alpha);
		alpha-=5;
		yield;
	}
	Obj_Delete(obj);
	Obj_Delete(objScore);
}
//----------------------------------------------------
//FPS表示
//----------------------------------------------------
task TCurrentFps()
{
	let objText = ObjText_Create();
	ObjText_SetFontSize(objText, 14);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontType(objText, "Meiryo");
	ObjText_SetFontColorTop(objText, 255, 128, 128);
	ObjText_SetFontColorBottom(objText, 255, 64, 64);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,0, 0, 0);
	ObjText_SetFontBorderWidth(objText, 2);
	ObjText_SetHorizontalAlignment(objText, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(objText, GetScreenWidth() - 8);
	Obj_SetRenderPriority(objText, 1.0);
	ObjRender_SetX(objText, 0);
	ObjRender_SetY(objText, GetScreenHeight() - 20);

	loop
	{
		let fps = GetCurrentFps();
		let text = vtos("1.2f", fps) ~ "fps";
		ObjText_SetText(objText, text);
		yield;
	}
}

task TReplayFps()
{
	if(!IsReplay()){return;}

	let objText = ObjText_Create();
	ObjText_SetFontSize(objText, 12);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontType(objText, "Meiryo");
	ObjText_SetFontColorTop(objText, 255, 128, 128);
	ObjText_SetFontColorBottom(objText, 255, 64, 64);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,0, 0, 0);
	ObjText_SetFontBorderWidth(objText, 1);
	Obj_SetRenderPriority(objText, 1.0);

	let px = GetStgFrameLeft() + GetStgFrameWidth() - 18;
	let py = GetStgFrameTop() + GetScreenHeight() - 14;
	ObjRender_SetX(objText, px);
	ObjRender_SetY(objText, py);

	loop
	{
		let fps = GetReplayFps();
		let text = vtos("02d", fps);
		ObjText_SetText(objText, text);
		yield;
	}
}

//----------------------------------------------------
//ユーティリティ
//----------------------------------------------------
function DigitToArray(let digit,let count)
{
	let res = [];
	digit = truncate(digit);

	loop
	{
		let tnum = truncate(digit % 10);
		digit /= 10;
		res = [tnum] ~ res;
		if(truncate(digit) == 0){break;}
	}

	loop(max(0, count - length(res)))
	{
		res = [0] ~ res;
	}

	return res;
}


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

