let difficultyimg = GCSD ~ "difficulty.png";
let diffsel = 1;

task ChooseDifficulty {
	LoadGraphic(difficultyimg);
	ForbidBomb(true);
	ascent(i in 0..4) { DiffSelect(i); }
	ascent(i in 0..2) { DiffSelectHeart(i); }
	DiffSelectTop;
	while(GetKeyState(VK_SHOT)!=KEY_PUSH) {
		if(GetKeyState(VK_UP)==KEY_PUSH) { 
			PlaySE(GetCurrentScriptDirectory ~ "se_menuselect.wav");
			diffsel--; }
		if(GetKeyState(VK_DOWN)==KEY_PUSH) {
				PlaySE(GetCurrentScriptDirectory ~ "se_menuselect.wav");
			diffsel++; }
		while(diffsel < 0) { diffsel+=4; }
		while(diffsel >= 4) { diffsel-=4; }
		SetPlayerY(10000);
	yield; }
	PlaySE(GetCurrentScriptDirectory ~ "se_menuok.wav");
	SetCommonData("Difficulty", diffsel);
	SetCommonData("Chosen Difficulty", true);
	chosediff = true;
	descent(i in 0..30) {
		SetPlayerX(GetCenterX);
		SetPlayerY(GetClipMaxY-64+i*4);
		yield;
	}
	ForbidBomb(false);
	DeleteGraphic(difficultyimg);
}

task DiffSelect(which) {
	let obj = Obj_Create(OBJ_EFFECT);
	Obj_SetPosition(obj, GetCenterX, GetCenterY-80+which*80); ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetLayer(obj, 7); ObjEffect_SetTexture(obj, difficultyimg); ObjEffect_CreateVertex(obj, 4);
	ObjEffect_SetVertexUV(obj, 0, 0, 0+96*which);
	ObjEffect_SetVertexUV(obj, 1, 256, 0+96*which);
	ObjEffect_SetVertexUV(obj, 2, 256, 96+96*which);
	ObjEffect_SetVertexUV(obj, 3, 0, 96+96*which);
	ObjEffect_SetVertexXY(obj, 0, -128, -48);
	ObjEffect_SetVertexXY(obj, 1, 128, -48);
	ObjEffect_SetVertexXY(obj, 2, 128, 48);
	ObjEffect_SetVertexXY(obj, 3, -128, 48);
	task Move {
		while(!chosediff) {
			ascent(i in 0..4) {
				ObjEffect_SetVertexColor(obj, i, [100, 255][diffsel==which], 255,255,255);
			}
			yield;
		}
		ascent(i in 0..10) { ObjEffect_SetScale(obj, 1+i/10, 1-i/10); yield; }
		Obj_Delete(obj);
	}
	Move;
}

task DiffSelectTop {
	let obj = Obj_Create(OBJ_EFFECT);
	Obj_SetPosition(obj, GetCenterX, GetClipMinY+32); ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetLayer(obj, 7); ObjEffect_SetTexture(obj, difficultyimg); ObjEffect_CreateVertex(obj, 4);
	ObjEffect_SetVertexUV(obj, 0, 0, 96*4);
	ObjEffect_SetVertexUV(obj, 1, 256, 96*4);
	ObjEffect_SetVertexUV(obj, 2, 256, 96*4+64);
	ObjEffect_SetVertexUV(obj, 3, 0, 96*4+64);
	ObjEffect_SetVertexXY(obj, 0, -128, 0);
	ObjEffect_SetVertexXY(obj, 1, 128, 0);
	ObjEffect_SetVertexXY(obj, 2, 128, 64);
	ObjEffect_SetVertexXY(obj, 3, -128, 64);
	task Move {
		while(!chosediff) {
			yield;
		}
		ascent(i in 0..10) { ObjEffect_SetScale(obj, 1-i/10, 1); yield; }
		Obj_Delete(obj);
	}
	Move;
}

task DiffSelectHeart(w) {
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetLayer(obj, 7); ObjEffect_SetTexture(obj, difficultyimg); ObjEffect_CreateVertex(obj, 4);
	ObjEffect_SetVertexUV(obj, 0, 0+64*w, 96*4+64);
	ObjEffect_SetVertexUV(obj, 1, 64+64*w, 96*4+64);
	ObjEffect_SetVertexUV(obj, 2, 64+64*w, 96*4+128);
	ObjEffect_SetVertexUV(obj, 3, 0+64*w, 96*4+128);
	ObjEffect_SetVertexXY(obj, 0, -32, -32);
	ObjEffect_SetVertexXY(obj, 1, 32, -32);
	ObjEffect_SetVertexXY(obj, 2, 32, 32);
	ObjEffect_SetVertexXY(obj, 3, -32, 32);
	task Move {
		while(!chosediff) {
			Obj_SetPosition(obj, GetCenterX-((-1)^w)*160, GetCenterY-80+diffsel*80);
			yield;
		}
		ascent(i in 0..10) { ObjEffect_SetScale(obj, 1-i/10, 1); yield; }
		Obj_Delete(obj);
	}
	Move;
}