From f549c7e2fc520fff17ddfe868267c28ef91bf822 Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 7 Jul 2024 11:59:23 -0500 Subject: add sound controls and fullscreen --- .gitignore | 2 ++ index.html | 10 +++++- main.js | 91 +++++++++++++++++++++++++++++++++++++++++++++++++------ mathjs/LICENSE.md | 9 ++++++ render.js | 14 ++++----- style.css | 37 +++++++++++++++++----- 6 files changed, 139 insertions(+), 24 deletions(-) create mode 100644 mathjs/LICENSE.md diff --git a/.gitignore b/.gitignore index 4709183..d3590e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ # Godot 4+ specific ignores .godot/ +*.swp +*~ diff --git a/index.html b/index.html index ccd16f1..efcf387 100644 --- a/index.html +++ b/index.html @@ -27,6 +27,14 @@
-
+ + diff --git a/main.js b/main.js index 44a0fe3..94c3f31 100644 --- a/main.js +++ b/main.js @@ -27,6 +27,16 @@ window.onload = () => setTimeout(() => { start.type = 'button'; start.value = 'connect to AMH'; start.onclick = () => { + // set up fullscreen + document.documentElement.requestFullscreen(); + document.getElementById('fullscreen-toggle').onclick = () => { + if (document.fullscreenElement === null) { + document.documentElement.requestFullscreen(); + } else { + document.exitFullscreen(); + } + } + root.classList.remove('center'); root.innerText = ''; const audio = new AudioContext(); @@ -55,21 +65,22 @@ window.onload = () => setTimeout(() => { musicList[0].element.play(); const sfx = {}; + const sfxGain = audio.createGain(); sfx.buttonEnterAudio = document.getElementById('sfx-buttonenter'); sfx.buttonClickAudio = document.getElementById('sfx-buttonclick'); sfx.listAppearAudio = document.getElementById('sfx-listappear'); - audio.createMediaElementSource(sfx.buttonEnterAudio).connect(audio.destination); - audio.createMediaElementSource(sfx.buttonClickAudio).connect(audio.destination); - audio.createMediaElementSource(sfx.listAppearAudio).connect(audio.destination); + audio.createMediaElementSource(sfx.buttonEnterAudio).connect(sfxGain).connect(audio.destination); + audio.createMediaElementSource(sfx.buttonClickAudio).connect(sfxGain).connect(audio.destination); + audio.createMediaElementSource(sfx.listAppearAudio).connect(sfxGain).connect(audio.destination); sfx.resourceAudio = document.getElementById('sfx-resource'); - audio.createMediaElementSource(sfx.resourceAudio).connect(audio.destination); + audio.createMediaElementSource(sfx.resourceAudio).connect(sfxGain).connect(audio.destination); sfx.doneAudio = document.getElementById('sfx-done'); - audio.createMediaElementSource(sfx.doneAudio).connect(audio.destination); + audio.createMediaElementSource(sfx.doneAudio).connect(sfxGain).connect(audio.destination); sfx.wrongAudio = document.getElementById('sfx-wrong'); - audio.createMediaElementSource(sfx.wrongAudio).connect(audio.destination); + audio.createMediaElementSource(sfx.wrongAudio).connect(sfxGain).connect(audio.destination); // const level = setupLevel([[2, 2], [3,3]], [7, 7]); // const ui = setupLevelUi(level, root, audio); @@ -77,9 +88,71 @@ window.onload = () => setTimeout(() => { Promise.all([...Object.values(sfx)].map(x => new Promise(resolve => { x.load(); x.addEventListener('canplaythrough', resolve, false); - }))).then( - () => setupLevelSelectUi(root, sfx) - ); + }))).then(() => { + sfx.gain = sfxGain; + document.getElementById('sound-controls').onclick = () => showSoundControls(root, sfx, musicGain); + setupLevelSelectUi(root, sfx) + }); }; root.appendChild(start); }, 200); + + +function showSoundControls(root, sfx, musicGain) { + 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 = 'sound settings'; + div2.appendChild(p); + root.appendChild(div); + + const musicLabel = document.createElement('label'); + musicLabel.innerText = 'music:'; + const musicRange = document.createElement('input'); + musicRange.type = 'range'; + musicRange.min = 0; + musicRange.max = 1; + musicRange.step = 0.1; + musicRange.value = 2*musicGain.gain.value; + musicRange.onchange = e => { + musicGain.gain.value = 0.5*e.target.value; + } + p.appendChild(document.createElement('br')); + p.appendChild(musicLabel); + p.appendChild(musicRange); + + const sfxLabel = document.createElement('label'); + sfxLabel.innerText = 'sfx:'; + const sfxRange = document.createElement('input'); + sfxRange.type = 'range'; + sfxRange.min = 0; + sfxRange.max = 1; + sfxRange.step = 0.1; + sfxRange.value = sfx.gain.gain.value; + sfxRange.onchange = e => { + sfx.gain.gain.value = e.target.value; + } + p.appendChild(document.createElement('br')); + p.appendChild(sfxLabel); + p.appendChild(sfxRange); + + + const button = document.createElement('input'); + button.type = 'button'; + button.value = 'OK'; + button.onmouseenter = () => { + sfx.buttonEnterAudio.currentTime = 0; + sfx.buttonEnterAudio.play(); + } + button.onclick = () => { + sfx.buttonClickAudio.currentTime = 0; + sfx.buttonClickAudio.play(); + root.removeChild(div); + } + p.appendChild(document.createElement('br')); + p.appendChild(button); +} diff --git a/mathjs/LICENSE.md b/mathjs/LICENSE.md new file mode 100644 index 0000000..2163c09 --- /dev/null +++ b/mathjs/LICENSE.md @@ -0,0 +1,9 @@ +The MIT License + +Copyright (c) 2017 Jos de Jong + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/render.js b/render.js index ce31973..66cf32c 100644 --- a/render.js +++ b/render.js @@ -1,5 +1,5 @@ export function render(ctx, level, index) { - ctx.fillStyle = 'white'; + ctx.fillStyle = 'orange'; const [x0, y0] = level.path[index]; const [x1, y1] = level.path[index+1] || level.path[index]; @@ -28,7 +28,7 @@ export function drawShip(ctx, pos, angle) { const [x, y] = pos; ctx.translate(x, y); ctx.rotate(angle); - ctx.fillStyle = 'white'; + ctx.fillStyle = 'orange'; const STEP = 0.4; ctx.beginPath(); ctx.moveTo(0, 0); @@ -43,8 +43,8 @@ export function drawShip(ctx, pos, angle) { export function drawGrid(ctx) { ctx.scale(1, -1); - ctx.strokeStyle = 'white'; - ctx.fillStyle = 'white'; + ctx.strokeStyle = 'orange'; + ctx.fillStyle = 'orange'; const { width, height } = ctx.canvas; ctx.font = `0.4px monospace`; ctx.lineWidth = 4 / Math.max(width, height); @@ -83,7 +83,7 @@ export function drawGrid(ctx) { export function drawPath(ctx, path) { const [ start, ...line ] = path; - ctx.strokeStyle = 'white'; + ctx.strokeStyle = 'orange'; ctx.lineWidth = 0.04; ctx.beginPath(); ctx.moveTo(start[0], start[1]); @@ -93,8 +93,8 @@ export function drawPath(ctx, path) { export function drawMark(ctx, mark, x, y) { - ctx.strokeStyle = 'white'; - ctx.fillStyle = 'white'; + ctx.strokeStyle = 'orange'; + ctx.fillStyle = 'orange'; ctx.font = `0.5px monospace`; ctx.lineWidth = 0.1; diff --git a/style.css b/style.css index 2b3b0fe..2b3b86e 100644 --- a/style.css +++ b/style.css @@ -1,9 +1,10 @@ body { - color: white; + color: orange; background-color: black; font-family: "VT323", monospace; position: relative; overflow-x: hidden; + margin-bottom: 0; } .logo { @@ -29,12 +30,34 @@ body { font-family: "VT323", monospace; width: min(90vw, 800px); margin: auto; - border-left: 1px solid white; - border-right: 1px solid white; + border-left: 1px solid orange; + border-right: 1px solid orange; padding: 8px; min-height: 95vh; } +#footer { + position: sticky; + bottom: 0; + left: 0; + right: 0; + border-top: 1px solid orange; + text-transform: uppercase; + font-family: "VT323", monospace; + font-size: 16px; + background-color: black; + color: orange; + margin: 0; + height: 32px; + overflow: hidden; + text-align: center; + padding-top: 8px; +} + +#footer a { + color: orange; +} + .center-screen-container { position: absolute; top: 0; @@ -52,7 +75,7 @@ body { } .alert-box { - border: 2px solid white; + border: 2px solid orange; background-color: black; padding: 16px; max-width: min(80vw, 600px); @@ -60,7 +83,7 @@ body { } .bordered { - border: 2px solid white; + border: 2px solid orange; } h1 { @@ -82,7 +105,7 @@ p { input { font-family: "VT323", monospace; - color: white; + color: orange; background-color: black; font-size: 16px; padding: 8px; @@ -96,7 +119,7 @@ input[type=button] { } input[type=button]:hover { color: black; - background-color: white; + background-color: orange; } input[type=button]:active { color: black; -- cgit v1.2.1 From 17d13e36a33d16e5242ae3b185e10928f41dd69d Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 7 Jul 2024 12:28:13 -0500 Subject: add help.html --- help.html | 40 ++++++++++++++++++++++++++++++++++++++++ style.css | 22 +++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 help.html diff --git a/help.html b/help.html new file mode 100644 index 0000000..a977a2c --- /dev/null +++ b/help.html @@ -0,0 +1,40 @@ + + + + + + Hyperspace Navigator - Help + + + + + + + +
+

hyperspace navigator help

+

+ HYPERSPACE NAVIGATOR is a game about designing trajectories using parametric curves. These are curves where y is not determined by some function of x (e.g. y = f[x]), but where both x and y are determined by a third quantity t, which we might think of as time. + Parametric curves are capable of producing complex and beautiful shapes from relatively simple definitions, and I encourage you to play with the system to see what you can create! +

+

+ While defining your parametric curves, you have access to the following operations: +

+
    +
  • Addition (t+2)
  • +
  • Subtraction (2-t)
  • +
  • Multiplication (2t or 2*t)
  • +
  • Division (t/2)
  • +
  • Exponents (t^2)
  • +
  • Modular arithmetic (t mod 2 or t % 2)
  • +
  • Trigonometric functions (tan, sin, cos, acos, asin, atan, atan2)
  • +
  • Miscellaneous extra functions (abs, exp, log, sqrt, ceil, floor, random, round)
  • +
  • Mathematical constants (pi, e)
  • +
+
+ + + diff --git a/style.css b/style.css index 2b3b86e..6555b37 100644 --- a/style.css +++ b/style.css @@ -54,7 +54,7 @@ body { padding-top: 8px; } -#footer a { +a { color: orange; } @@ -127,6 +127,26 @@ input[type=button]:active { } +input[type=range] { + accent-color: orange; + margin-bottom: 0; +} + +.alert-box label { + padding-bottom: 16px; +} + + label { text-transform: lowercase; } + + +.normal { + text-transform: none; +} + + +.normal li { + font-size: 24px; +} -- cgit v1.2.1 From 553218a6214b0473f1ac8bad9e832fc5ea84199c Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 7 Jul 2024 12:28:58 -0500 Subject: make debug param nicer --- levelSelect.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/levelSelect.js b/levelSelect.js index 04c65a6..7f0a629 100644 --- a/levelSelect.js +++ b/levelSelect.js @@ -1,3 +1,5 @@ +const DEBUG = false; + import{ setupLevel, setupLevelUi } from './level.js'; @@ -63,8 +65,7 @@ export function setupLevelSelectUi(root, sfx) { const levelPicker = name => { const [ dependencies, level ] = levels[name]; const allDependenciesSatisfied = dependencies.map(x => levels[x][1].completed).reduce((acc, x) => acc && x, true); - // if (allDependenciesSatisfied) { - if (true) { + if (DEBUG || allDependenciesSatisfied) { sfx.listAppearAudio.currentTime = 0; sfx.listAppearAudio.play(); const button = document.createElement('input'); -- cgit v1.2.1 From b648eaffe1f9a33280ef4486474ca0aa52dac9f8 Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 7 Jul 2024 12:47:00 -0500 Subject: update path speed --- level.js | 4 ++-- main.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/level.js b/level.js index 0d62adc..f5aa29c 100644 --- a/level.js +++ b/level.js @@ -6,7 +6,7 @@ const X_START = '0'; const Y_START = 't'; const PATH_LEN = 20; -const PATH_STEP = PATH_LEN/1000; +const PATH_STEP = PATH_LEN/500; const SLOW_RAMP = 1; const FAST_RAMP = 0.01; @@ -177,7 +177,7 @@ function stepLevel(ui, level, index) { render(ui.ctx, level, 0); } else if (level.running && index < level.path.length-1) { const distNext = distance(pos, level.path[index+1] || pos); - setTimeout(() => stepLevel(ui, level, index+1), 50*distNext); + setTimeout(() => stepLevel(ui, level, index+1), distNext); } else { if (index >= level.path.length-1) { finishLevel(ui, level, true); diff --git a/main.js b/main.js index 94c3f31..6b5edc1 100644 --- a/main.js +++ b/main.js @@ -28,10 +28,10 @@ window.onload = () => setTimeout(() => { start.value = 'connect to AMH'; start.onclick = () => { // set up fullscreen - document.documentElement.requestFullscreen(); + document.documentElement.requestFullscreen({ navigationUI: 'hide' }); document.getElementById('fullscreen-toggle').onclick = () => { if (document.fullscreenElement === null) { - document.documentElement.requestFullscreen(); + document.documentElement.requestFullscreen({ navigationUI: 'hide' }); } else { document.exitFullscreen(); } -- cgit v1.2.1 From c6c473e03c7b9a993ccaf28bcff2d87fbdf9c931 Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 7 Jul 2024 14:30:00 -0500 Subject: add lissajous figure level --- .levelSelect.js.swo | Bin 0 -> 16384 bytes levelSelect.js | 8 +++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .levelSelect.js.swo diff --git a/.levelSelect.js.swo b/.levelSelect.js.swo new file mode 100644 index 0000000..f59d1f9 Binary files /dev/null and b/.levelSelect.js.swo differ diff --git a/levelSelect.js b/levelSelect.js index 7f0a629..cdbca2b 100644 --- a/levelSelect.js +++ b/levelSelect.js @@ -1,4 +1,4 @@ -const DEBUG = false; +const DEBUG = true; import{ setupLevel, setupLevelUi } from './level.js'; @@ -58,6 +58,12 @@ const levels = { buildLevel(t => Math.cos(t)*t, t => Math.sin(t)*t, [...Array(8).keys()].map(x => 0.25 * Math.PI * x)), ], + 'lissajous 0': [ + ['orbital'], + buildLevel(t => 8*Math.cos(t), t => 8*Math.sin(2*t), [...Array(8).keys()].map(x => 0.25 * Math.PI * x)), + ], + + }; export function setupLevelSelectUi(root, sfx) { -- cgit v1.2.1