diff options
author | sanine <sanine.not@pm.me> | 2024-07-07 18:31:39 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2024-07-07 18:31:39 -0500 |
commit | 2c31a91ba27ea48c5db4a06be82476d26d642c7d (patch) | |
tree | 51442315c9d36e175a70fe1437ecc00cf82f0089 | |
parent | 95ee8172ae99c00efbfb1c8c105112f82711ae01 (diff) | |
parent | c6c473e03c7b9a993ccaf28bcff2d87fbdf9c931 (diff) |
add level intro messages & mergemain
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | .levelSelect.js.swo | bin | 0 -> 16384 bytes | |||
-rw-r--r-- | help.html | 40 | ||||
-rw-r--r-- | index.html | 10 | ||||
-rw-r--r-- | level.js | 4 | ||||
-rw-r--r-- | levelSelect.js | 11 | ||||
-rw-r--r-- | main.js | 91 | ||||
-rw-r--r-- | mathjs/LICENSE.md | 9 | ||||
-rw-r--r-- | render.js | 14 | ||||
-rw-r--r-- | style.css | 57 |
10 files changed, 210 insertions, 28 deletions
@@ -1,2 +1,4 @@ # Godot 4+ specific ignores .godot/ +*.swp +*~ diff --git a/.levelSelect.js.swo b/.levelSelect.js.swo Binary files differnew file mode 100644 index 0000000..f59d1f9 --- /dev/null +++ b/.levelSelect.js.swo diff --git a/help.html b/help.html new file mode 100644 index 0000000..a977a2c --- /dev/null +++ b/help.html @@ -0,0 +1,40 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>Hyperspace Navigator - Help</title> + <link rel="preconnect" href="https://fonts.googleapis.com"> + <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> + <link href="https://fonts.googleapis.com/css2?family=VT323&display=swap" rel="stylesheet"> + <link href="style.css" rel="stylesheet"> + </head> + <body style="font-family: Jura;"> + <script>0</script> + <div id="root"> + <h1>hyperspace navigator help</h1> + <p class="normal"> + HYPERSPACE NAVIGATOR is a game about designing trajectories using <a href="https://tutorial.math.lamar.edu/Classes/CalcII/ParametricEqn.aspx">parametric curves</a>. These are curves where <strong>y</strong> is not determined by some function of <strong>x</strong> (e.g. <strong>y = f[x]</strong>), but where both <strong>x</strong> and <strong>y</strong> are determined by a third quantity <strong>t</strong>, 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! + </p> + <p class="normal"> + While defining your parametric curves, you have access to the following operations: + </p> + <ul class="normal"> + <li>Addition (t+2)</li> + <li>Subtraction (2-t)</li> + <li>Multiplication (2t or 2*t)</li> + <li>Division (t/2)</li> + <li>Exponents (t^2)</li> + <li>Modular arithmetic (t mod 2 or t % 2)</li> + <li>Trigonometric functions (tan, sin, cos, acos, asin, atan, atan2)</li> + <li>Miscellaneous extra functions (abs, exp, log, sqrt, ceil, floor, random, round)</li> + <li>Mathematical constants (pi, e)</li> + </ul> + </div> + <div id="footer"> + <a target="_blank" rel="noopener noreferrer" + href="https://sanine.net/git/hyperspace-navigator/tree/?h=main">⌘ source code</a> + </div> + </body> +</html> @@ -27,6 +27,14 @@ <audio preload="auto" id="sfx-listappear" src="sounds/sfx/gui-beep/33775__jobro__1-beep-a.wav"></audio> <div id="root"></div> - <div id="overlay"></div> + <!-- <div id="overlay"></div> --> + <div id="footer"> + <a target="_blank" rel="noopener noreferrer" + href="./help.html">🛈 help</a> + <a id="sound-controls" href="#">♫ sounds</a> + <a target="_blank" rel="noopener noreferrer" + href="https://sanine.net/git/hyperspace-navigator/tree/?h=main">⌘ source code</a> + <a id="fullscreen-toggle" href="#">∷ toggle fullscreen</a> + </div> </body> </html> @@ -6,7 +6,7 @@ const X_START = 't'; 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; @@ -182,7 +182,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/levelSelect.js b/levelSelect.js index 997bbb2..6af87fa 100644 --- a/levelSelect.js +++ b/levelSelect.js @@ -1,3 +1,5 @@ +const DEBUG = true; + import{ setupLevel, setupLevelUi } from './level.js'; @@ -62,6 +64,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) { @@ -69,8 +77,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'); @@ -27,6 +27,16 @@ window.onload = () => setTimeout(() => { start.type = 'button'; start.value = 'connect to AMH'; start.onclick = () => { + // set up fullscreen + document.documentElement.requestFullscreen({ navigationUI: 'hide' }); + document.getElementById('fullscreen-toggle').onclick = () => { + if (document.fullscreenElement === null) { + document.documentElement.requestFullscreen({ navigationUI: 'hide' }); + } 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. @@ -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; @@ -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; +} + +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; @@ -104,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; +} |