This commit is contained in:
John Gatward
2026-03-18 15:24:08 +00:00
parent 213cf5f535
commit 3cb8d5a14e
17 changed files with 1525 additions and 331 deletions

View File

@@ -1,32 +1,30 @@
const statusElement = document.getElementById("status");
const progressElement = document.getElementById("progress");
const spinnerElement = document.getElementById("spinner");
const canvasElement = document.getElementById("canvas");
const outputElement = document.getElementById("output");
const statusElement = document.getElementById('status');
const progressElement = document.getElementById('progress');
const canvasElement = document.getElementById('canvas');
const outputElement = document.getElementById('output');
const fullscreenButton = document.getElementById('fullscreenButton');
const resizeCheckbox = document.getElementById('resize');
const pointerLockCheckbox = document.getElementById('pointerLock');
if (outputElement) {
outputElement.value = "";
outputElement.value = '';
}
canvasElement.addEventListener(
"webglcontextlost",
(event) => {
alert("WebGL context lost. You will need to reload the page.");
event.preventDefault();
},
false
);
canvasElement.addEventListener('webglcontextlost', (event) => {
event.preventDefault();
setStatus('WebGL context lost. Reload the page to restart the game.');
}, false);
function setStatus(text) {
if (!setStatus.last) {
setStatus.last = { time: Date.now(), text: "" };
setStatus.last = { time: Date.now(), text: '' };
}
if (text === setStatus.last.text) {
return;
}
const match = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
const match = text?.match(/([^(]+)\((\d+(?:\.\d+)?)\/(\d+)\)/);
const now = Date.now();
if (match && now - setStatus.last.time < 30) {
@@ -37,58 +35,55 @@ function setStatus(text) {
setStatus.last.text = text;
if (match) {
statusElement.innerHTML = match[1].trim();
progressElement.value = 100 * parseInt(match[2], 10);
progressElement.max = 100 * parseInt(match[4], 10);
statusElement.textContent = match[1].trim();
progressElement.value = Number.parseInt(match[2], 10) * 100;
progressElement.max = Number.parseInt(match[3], 10) * 100;
progressElement.hidden = false;
spinnerElement.hidden = false;
} else {
statusElement.innerHTML = text;
progressElement.value = null;
progressElement.max = null;
progressElement.hidden = true;
statusElement.textContent = text || '';
progressElement.hidden = !text;
if (!text) {
spinnerElement.style.display = "none";
progressElement.removeAttribute('value');
}
}
}
var Module = window.Module || {};
Module.print = (...args) => {
globalThis.Module = globalThis.Module || {};
globalThis.Module.canvas = canvasElement;
globalThis.Module.print = (...args) => {
console.log(...args);
if (!outputElement) {
return;
}
const text = args.join(" ");
outputElement.value += text + "\n";
outputElement.value += `${args.join(' ')}\n`;
outputElement.scrollTop = outputElement.scrollHeight;
};
Module.canvas = canvasElement;
Module.setStatus = setStatus;
Module.totalDependencies = 0;
Module.monitorRunDependencies = function (left) {
globalThis.Module.printErr = (...args) => {
console.error(...args);
if (!outputElement) {
return;
}
outputElement.value += `[err] ${args.join(' ')}\n`;
outputElement.scrollTop = outputElement.scrollHeight;
};
globalThis.Module.setStatus = setStatus;
globalThis.Module.totalDependencies = 0;
globalThis.Module.monitorRunDependencies = function (left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
setStatus(
left
? "Preparing... (" + (this.totalDependencies - left) + "/" + this.totalDependencies + ")"
: "All downloads complete."
);
setStatus(left ? `Preparing... (${this.totalDependencies - left}/${this.totalDependencies})` : 'Running...');
if (!left) {
setTimeout(() => setStatus(''), 250);
}
};
setStatus("Downloading...");
fullscreenButton.addEventListener('click', () => {
if (typeof globalThis.Module.requestFullscreen === 'function') {
globalThis.Module.requestFullscreen(pointerLockCheckbox.checked, resizeCheckbox.checked);
}
});
window.onerror = (message) => {
setStatus("Exception thrown, see JavaScript console");
spinnerElement.style.display = "none";
setStatus = (text) => {
if (text) {
console.error("[post-exception status] " + text);
}
};
return message;
setStatus('Downloading...');
globalThis.onerror = () => {
setStatus('Exception thrown, see JavaScript console');
};
window.Module = Module;

View File

@@ -1,295 +1,259 @@
:root {
--bg-0: #0b1220;
--bg-1: #13213a;
--bg-2: #1b2f4d;
--ice: #cfeeff;
--snow: #f5fbff;
--accent: #7fd8ff;
--accent-2: #a7e8ff;
--text: #e9f2ff;
--muted: #b6c8df;
--ok: #9cf0b4;
--warn: #ffd47e;
--shadow: rgba(0, 0, 0, 0.35);
--card: rgba(255, 255, 255, 0.06);
--card-border: rgba(255, 255, 255, 0.15);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
:root {
--bg: #fffdf7;
--text: #0f172a;
--muted: #475569;
--border: #0f172a;
--panel: #dff4ff;
--panel-2: #ffffff;
--accent: #00a6fb;
--accent-strong: #0077b6;
--highlight: #ffd23f;
--danger: #ff5d73;
}
body {
margin: 0;
min-height: 100%;
background: var(--bg);
color: var(--text);
background: radial-gradient(circle at 15% 10%, #223a5f 0%, var(--bg-1) 28%, var(--bg-0) 100%);
font-family: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
image-rendering: pixelated;
font-family: Arial, Helvetica, sans-serif;
font-size: 18px;
line-height: 1.6;
padding: 20px;
}
body {
display: flex;
justify-content: center;
padding: 2rem 1rem 3rem;
position: relative;
overflow-x: hidden;
.container {
max-width: 920px;
margin: 0 auto;
}
body::before,
body::after {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
z-index: 0;
header {
text-align: center;
margin-bottom: 30px;
border-bottom: 3px solid var(--border);
padding-bottom: 20px;
}
body::before {
background-image:
radial-gradient(2px 2px at 15% 20%, rgba(255, 255, 255, 0.7) 50%, transparent 51%),
radial-gradient(2px 2px at 35% 40%, rgba(255, 255, 255, 0.5) 50%, transparent 51%),
radial-gradient(2px 2px at 65% 15%, rgba(255, 255, 255, 0.6) 50%, transparent 51%),
radial-gradient(2px 2px at 80% 75%, rgba(255, 255, 255, 0.7) 50%, transparent 51%),
radial-gradient(2px 2px at 25% 85%, rgba(255, 255, 255, 0.55) 50%, transparent 51%);
opacity: 0.35;
}
body::after {
background: linear-gradient(180deg, transparent 0%, rgba(181, 227, 255, 0.08) 100%);
}
.page {
width: min(1100px, 100%);
position: relative;
z-index: 1;
display: grid;
gap: 1rem;
}
.hero,
.panel {
background: var(--card);
border: 1px solid var(--card-border);
border-radius: 14px;
box-shadow: 0 10px 35px var(--shadow);
backdrop-filter: blur(3px);
}
.hero {
padding: 1rem 1.25rem;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 0.75rem 1rem;
}
.title-group h1 {
margin: 0;
font-size: clamp(1.5rem, 2.3vw, 2rem);
h1,
h2,
h3,
button,
summary,
.back-button {
font-family: "Arial Black", Arial, Helvetica, sans-serif;
font-weight: 900;
letter-spacing: 0.02em;
}
.title-group p {
margin: 0.3rem 0 0;
color: var(--muted);
max-width: 60ch;
font-size: 0.95rem;
line-height: 1.4;
h1 {
font-size: clamp(2.4rem, 5vw, 3.6rem);
margin-bottom: 10px;
line-height: 1;
text-transform: uppercase;
}
.pill-row {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}
.pill {
border: 1px solid rgba(167, 232, 255, 0.35);
background: rgba(127, 216, 255, 0.12);
color: var(--snow);
padding: 0.35rem 0.55rem;
border-radius: 999px;
font-size: 0.8rem;
white-space: nowrap;
}
.layout {
display: grid;
grid-template-columns: 2fr 1fr;
gap: 1rem;
}
.game-shell {
padding: 1rem;
display: grid;
gap: 0.8rem;
}
.status-row {
display: grid;
gap: 0.5rem;
}
.loading {
h2 {
font-size: 1.8rem;
margin: 0 0 16px;
}
h3 {
font-size: 1.35rem;
margin: 0 0 14px;
}
p,
ul {
margin-bottom: 16px;
}
.subtitle {
color: var(--accent-strong);
font-size: 1rem;
}
.back-button {
display: inline-block;
margin-bottom: 20px;
padding: 10px 15px;
background: var(--highlight);
color: var(--text);
text-decoration: none;
border: 3px solid var(--border);
}
.back-button:hover,
.action-button:hover {
background: var(--text);
color: #fff;
}
.info-box {
background: var(--highlight);
border: 3px solid var(--border);
padding: 16px;
margin: 20px 0;
}
.canvas-container {
background: var(--panel);
border: 3px solid var(--border);
padding: 20px;
margin: 30px 0;
}
.canvas-toolbar {
display: flex;
justify-content: space-between;
align-items: center;
gap: 0.55rem;
gap: 12px;
margin-bottom: 15px;
flex-wrap: wrap;
}
.canvas-toolbar p {
margin: 0;
color: var(--muted);
font-size: 0.9rem;
min-height: 1.1rem;
font-size: 0.95rem;
text-transform: uppercase;
}
.spinner {
width: 14px;
height: 14px;
border: 2px solid rgba(255, 255, 255, 0.3);
border-top-color: var(--accent-2);
border-radius: 50%;
animation: spin 0.8s linear infinite;
flex: 0 0 auto;
.action-button {
padding: 10px 14px;
background: var(--danger);
color: white;
border: 3px solid var(--border);
cursor: pointer;
font: inherit;
}
#status {
font-weight: 600;
color: var(--ice);
}
#progress {
width: 100%;
height: 12px;
border: 0;
border-radius: 999px;
overflow: hidden;
background: rgba(255, 255, 255, 0.15);
}
#progress::-webkit-progress-bar {
background: rgba(255, 255, 255, 0.15);
}
#progress::-webkit-progress-value {
background: linear-gradient(90deg, #95dfff, #d8f4ff);
}
#progress::-moz-progress-bar {
background: linear-gradient(90deg, #95dfff, #d8f4ff);
}
.canvas-frame {
background: linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, rgba(255, 255, 255, 0.02) 100%);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 12px;
padding: 0.6rem;
.canvas-shell {
display: flex;
justify-content: center;
align-items: center;
min-height: 520px;
overflow: auto;
background: var(--panel-2);
border: 3px solid var(--border);
padding: 12px;
}
#canvas {
display: block;
width: 100%;
max-width: 100%;
margin: 0 auto;
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.18);
max-width: 100%;
height: auto;
background: #000;
outline: none;
image-rendering: pixelated;
}
.controls {
.canvas-options {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.8rem;
gap: 14px;
margin-top: 15px;
font-size: 0.95rem;
color: var(--muted);
font-size: 0.9rem;
}
.controls label {
.canvas-options label {
display: inline-flex;
align-items: center;
gap: 0.35rem;
user-select: none;
cursor: pointer;
gap: 8px;
}
.controls input[type="checkbox"] {
accent-color: #8ad6ff;
cursor: pointer;
.canvas-options input {
accent-color: var(--accent-strong);
}
.btn {
border: 1px solid rgba(167, 232, 255, 0.6);
color: var(--snow);
background: linear-gradient(180deg, rgba(146, 217, 255, 0.35), rgba(88, 173, 222, 0.3));
border-radius: 8px;
padding: 0.42rem 0.7rem;
font-weight: 600;
cursor: pointer;
.status {
margin-top: 15px;
min-height: 24px;
color: var(--accent-strong);
font-weight: 700;
}
.btn:hover {
filter: brightness(1.08);
progress {
width: 100%;
height: 18px;
margin-top: 10px;
border: 3px solid var(--border);
}
.sidebar {
padding: 1rem;
display: grid;
gap: 0.8rem;
align-content: start;
}
.sidebar h2 {
margin: 0;
font-size: 1.05rem;
}
.sidebar p,
.sidebar li {
margin: 0;
color: var(--muted);
font-size: 0.92rem;
line-height: 1.45;
}
.sidebar ul {
margin: 0;
padding-left: 1.1rem;
display: grid;
gap: 0.45rem;
}
.hint {
border-left: 3px solid var(--accent);
padding: 0.5rem 0.65rem;
background: rgba(127, 216, 255, 0.1);
border-radius: 6px;
color: #d5f2ff;
}
#output {
progress[hidden] {
display: none;
}
details {
margin-top: 15px;
}
summary {
cursor: pointer;
}
.feature-list {
padding-left: 24px;
}
.feature-list li {
margin-bottom: 10px;
}
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
textarea {
width: 100%;
min-height: 120px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 8px;
color: #fff;
background: #0a0f19;
font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
font-size: 0.8rem;
padding: 0.5rem;
margin-top: 10px;
padding: 10px;
border: 3px solid var(--border);
font-family: "Courier New", monospace;
font-size: 0.9rem;
resize: vertical;
background: white;
color: var(--text);
}
@keyframes spin {
to {
transform: rotate(360deg);
}
footer {
text-align: center;
margin-top: 40px;
padding-top: 20px;
border-top: 3px solid var(--border);
font-size: 0.9rem;
color: var(--muted);
}
@media (max-width: 920px) {
.layout {
grid-template-columns: 1fr;
@media (max-width: 768px) {
body {
padding: 16px;
font-size: 16px;
}
h1 {
font-size: 2.2rem;
}
.canvas-container {
padding: 15px;
}
.canvas-shell {
min-height: 360px;
}
}

View File

@@ -8,54 +8,63 @@
<link rel="stylesheet" href="style.css" />
</head>
<body>
<main class="page">
<section class="hero">
<div class="title-group">
<h1>Thin Ice</h1>
<div class="container">
<a href="/#projects" class="back-button">← Back</a>
<header>
<h1>Thin Ice</h1>
<p class="subtitle">Inspired by Club Penguin's Thin Ice mini-game.</p>
</header>
<section>
<p>
You start on safe ice, breaking ice where you walk, trying to reach the finish tile before trapping yourself.
</p>
<div class="info-box">
<p>
A game inspired by the Club Penguin mini-game of the same name.
See if you can get a gold medal on all 6 levels by breaking every single tile of ice!
</p>
</div>
</section>
<section class="layout">
<article class="panel game-shell" aria-label="Thin Ice game canvas">
<div class="status-row">
<div class="loading">
<div class="spinner" id="spinner" aria-hidden="true"></div>
<div id="status" role="status" aria-live="polite">Downloading...</div>
</div>
<progress id="progress" max="100" value="0" hidden></progress>
</div>
<div class="canvas-container">
<div class="canvas-toolbar">
<p>Game</p>
<button id="fullscreenButton" class="action-button" type="button">Fullscreen</button>
</div>
<div class="canvas-frame">
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex="-1"></canvas>
</div>
<div class="canvas-shell">
<canvas id="canvas" class="emscripten" aria-label="Thin Ice game canvas" oncontextmenu="event.preventDefault()" tabindex="-1"></canvas>
</div>
<div class="controls" id="controls">
<label><input type="checkbox" id="resize" /> Resize canvas</label>
<label><input type="checkbox" id="pointerLock" checked /> Lock/hide mouse pointer</label>
<button
class="btn"
type="button"
onclick='Module.requestFullscreen(document.getElementById("pointerLock").checked,document.getElementById("resize").checked)'>
Fullscreen
</button>
</div>
<div class="canvas-options">
<label><input type="checkbox" id="resize" /> Resize canvas in fullscreen</label>
<label><input type="checkbox" id="pointerLock" checked /> Lock pointer in fullscreen</label>
</div>
<textarea id="output" rows="8" aria-label="Runtime output"></textarea>
</article>
<div id="status" class="status">Downloading...</div>
<progress id="progress" value="0" max="100" hidden></progress>
<aside class="panel sidebar" aria-label="How to play">
<h2>How to Play</h2>
<ul>
<li>Start on the first tile and plan your route before moving.</li>
<li>Reach the end tile while avoiding water and broken ice.</li>
<li>If you slip up, reset and try a smarter path.</li>
</ul>
</aside>
<details>
<summary>Show console output</summary>
<label class="visually-hidden" for="output">Console output</label>
<textarea id="output" rows="8" readonly></textarea>
</details>
</div>
<section>
<h2>How to Play</h2>
<ul class="feature-list">
<li>Use WASM keys to move across the ice.</li>
<li>Plan ahead so you do not strand yourself on broken tiles.</li>
<li>Reach the end tile without falling into the water.</li>
</ul>
</section>
</main>
<footer>
<p>Built with C++ & Raylib, compiled to WASM with emscripten.</p>
</footer>
</div>
<script src="script.js"></script>
<script async src="thin_ice.js"></script>