From 0c6831d63cfb6b98107826524183d444eee2e4bd Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 6 Jul 2024 18:41:43 -0500 Subject: add alerts --- level.js | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'level.js') diff --git a/level.js b/level.js index ba1032f..5a20ef5 100644 --- a/level.js +++ b/level.js @@ -32,7 +32,7 @@ export function setupLevel(resources, home) { export function setupLevelUi(level, root, sfx) { - const ui = { sfx }; + const ui = { root, sfx }; root.classList.add('center'); ui.launchButton = document.createElement('input'); @@ -187,16 +187,48 @@ function finishLevel(ui, level, fail) { if (fail) { ui.sfx.wrongAudio.currentTime = 0; ui.sfx.wrongAudio.play(); - ui.message.innerText = 'did not arrive at destination'; + showAlert(ui, 'trajectory does not reach AMH processor'); + // ui.message.innerText = 'did not arrive at destination'; } else if (uncollected > 0) { ui.sfx.wrongAudio.currentTime = 0; ui.sfx.wrongAudio.play(); - ui.message.innerText = 'resources remaining!'; + showAlert(ui, 'monopole harvesting failure'); + // ui.message.innerText = 'resources remaining!'; } else { ui.sfx.doneAudio.currentTime = 0; ui.sfx.doneAudio.play(); - ui.message.innerText = 'mission complete!'; + showAlert(ui, 'navigation successful: contract complete'); + // ui.message.innerText = 'mission complete!'; level.completed = true; } level.resources.forEach(x => x.collected = false); } + + +function showAlert(ui, text) { + const div = document.createElement('div'); + div.classList.add('center-screen-container'); + const div2 = document.createElement('div'); + div2.classList.add('center-screen'); + div.appendChild(div2); + const p = document.createElement('p'); + p.classList.add('alert-box'); + p.innerText = text; + div2.appendChild(p); + ui.root.appendChild(div); + + const button = document.createElement('input'); + button.type = 'button'; + button.value = 'OK'; + button.onmouseenter = () => { + ui.sfx.buttonEnterAudio.currentTime = 0; + ui.sfx.buttonEnterAudio.play(); + } + button.onclick = () => { + ui.sfx.buttonClickAudio.currentTime = 0; + ui.sfx.buttonClickAudio.play(); + ui.root.removeChild(div); + } + p.appendChild(document.createElement('br')); + p.appendChild(button); +} -- cgit v1.2.1