let csd = GetCurrentScriptDirectory;
let border = csd ~ "img\border.png";
let burst = "seSuperNaturalBorder2.wav";
let onbomb = 0;
let invincible = 0;
let borderangle = 0;
let corealpha = 0;
let LKey = 0;
let RKey = 0;
let UKey = 0;
let DKey = 0;
let SKey = 0;
let BKey = 0;
let SMKey = 0;
let SKKey = 0;
let USKey = 0;

// ボム
task bomb {
	onbomb = 1;
	let x = GetPlayerX;
	let y = GetPlayerY;
	let radius = 0;
	let angle = 0;
	SetPlayerInvincibility(90);
	CollectItems;
	PlaySE(burst);

	let obj = Obj_Create(OBJ_EFFECT);
	Obj_SetPosition(obj, x, y);
	ObjEffect_SetTexture(obj, border);
	ObjEffect_SetRenderState(obj, ADD);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_CreateVertex(obj, 4);

	ObjEffect_SetVertexXY(obj, 0, -32, -32);
	ObjEffect_SetVertexXY(obj, 1, -32, 32);
	ObjEffect_SetVertexXY(obj, 2, 32, -32);
	ObjEffect_SetVertexXY(obj, 3, 32, 32);

	ObjEffect_SetVertexUV(obj, 0, 64, 0);
	ObjEffect_SetVertexUV(obj, 1, 64, 64);
	ObjEffect_SetVertexUV(obj, 2, 128, 0);
	ObjEffect_SetVertexUV(obj, 3, 128, 64);

	loop(60) {
		DeleteEnemyShotToItemInCircle(SHOT, x, y, radius);
		ObjEffect_SetScale(obj, radius * 0.05, radius * 0.05);
		ObjEffect_SetAngle(obj, 0, 0, angle);
		radius += 10;
		angle += 10;

		wait(1);
	}

	Obj_Delete(obj);

	onbomb = 0;
}

// 組み込み描画
sub autodraw {
	SetTexture(border);
	SetGraphicAngle(0, 0, 0);
	SetGraphicScale(0.12, 0.12);
	SetRenderState(ALPHA);
	SetAlpha(corealpha);
	SetGraphicRect(192, 0, 255, 63);

	DrawGraphic(GetPlayerX, GetPlayerY);

	if(GetTimeOfPlayerInvincibility > 0) {
		SetTexture(border);
		SetGraphicAngle(0, 0, borderangle);
		SetGraphicScale(invincible, invincible);
		SetRenderState(ADD);
		SetAlpha(255);
		SetGraphicRect(0, 0, 64, 64);

		DrawGraphic(GetPlayerX, GetPlayerY);
	}

}

// いろいろな数値制御
sub value {
	if(GetTimeOfPlayerInvincibility >= 60) {
		invincible = 2;
	} else {
		invincible = GetTimeOfPlayerInvincibility / 30;
	}

	borderangle += 5;
	if(borderangle >= 360) {
		borderangle = 0;
	}

	if(SMKey == KEY_PUSH || SMKey == KEY_HOLD) {
		if(corealpha < 255) {
			corealpha += 12.75;
		} else {
			corealpha = 255;
		}
	} else {
		if(corealpha > 0) {
			corealpha -= 12.75;
		} else {
			corealpha = 0;
		}
	}
}

// キーチェック
// 上から、左、右、上、下、ショット、ボム、低速、スキップ、ユーザ
sub keycheck {
	LKey = GetKeyState(VK_LEFT);
	RKey = GetKeyState(VK_RIGHT);
	UKey = GetKeyState(VK_UP);
	DKey = GetKeyState(VK_DOWN);
	SKey = GetKeyState(VK_SHOT);
	BKey = GetKeyState(VK_BOMB);
	SMKey = GetKeyState(VK_SLOWMOVE);
	SKKey = GetKeyState(VK_SKIP);
	USKey = GetKeyState(VK_USER);

}

// w フレームだけ待つ
function wait(w) {
	loop(w) { yield; }
}