diff --git a/README.md b/README.md
index e40d729..5ee5d37 100644
--- a/README.md
+++ b/README.md
@@ -137,6 +137,20 @@
- ๐๏ธ **Several worlds:** each child can have their own worlds (name, seed, creative or survival), with export and import as a file for backups or sharing with a friend.
- ๐พ **Auto-save:** each world's buildings, inventory, animals, pets, robot program and stars are kept in the browser.
+## ๐ Course Maker: build your own games
+
+Not just a world to build in: build **games** in it.
+
+- Place a **๐ Course Start** pad, a **๐ฉ Checkpoint** or two and a **๐ Course Finish** pad, then step on Start: a timer begins.
+- Scatter **๐ช coins** along the way and see who can collect them all.
+- Fall off and you land back at your last checkpoint (or press **R** / tap **โบ**).
+- Finishing celebrates with confetti and remembers your **best time** for each course.
+- Combine with trampolines, speed strips, ice, fan vents, portals and Spark pistons for wild obstacle courses, then challenge your family (or race friends in Play Together).
+
+## ๐ท Photo Mode
+
+Press **P** (or tap **๐ท**) to snap a picture of your world. Add a **frame** (Polaroid with a caption, rainbow, starry), a **filter** (sunny, frosty, black & white, retro) and **stickers**, then save it or share it. Photos stay on your device; nothing is uploaded.
+
## ๐ซ Play Together (online edition)
Build with family and friends, **up to 4 players** in the host's world. Play Together is part of our hosted online edition (it needs our server), so it doesn't appear in the free GitHub Pages copy. Everyone in a game needs an account (see below).
diff --git a/index.html b/index.html
index 761829e..74555dc 100644
--- a/index.html
+++ b/index.html
@@ -37,6 +37,8 @@
+
+
@@ -44,6 +46,7 @@
+
โฑ 0.00 sR: back to checkpoint
@@ -146,6 +149,8 @@
MiniCrafter
Z / Y
Undo / redo (creative)
F3
Debug info
T then 1โ8
Send an emoji (Play Together)
+
P
๐ท Photo Mode
+
R
Back to the last checkpoint (Course Maker)
L / N
Let a friend in / not now (host)
Esc
Pause
@@ -233,6 +238,26 @@
๐ค Your account
+
+
+
๐ท Photo Mode
+
+
+
Frame
+
Filter
+
Stickers: pick one, then tap the photo
+
+
+
+
+
+
+
+
Photos are saved on your device. Nothing is uploaded.
+
+
+
+
Blocks
diff --git a/src/blocks.js b/src/blocks.js
index 9aeb8f0..75c33a4 100644
--- a/src/blocks.js
+++ b/src/blocks.js
@@ -21,6 +21,8 @@ export const B = {
BATTERY: 75, INVERTER: 76, INVERTER_ON: 80, DELAY: 84, DELAY_ON: 88,
SPARK_LAMP: 92, SPARK_LAMP_ON: 93, SPARK_DOOR: 94, SPARK_DOOR_OPEN: 95,
PISTON: 96, PISTON_OUT: 101, PISTON_HEAD: 106,
+ // Course Maker: build your own obstacle courses and races.
+ COURSE_START: 107, COURSE_CHECK: 108, COURSE_FINISH: 109, COIN: 110, COIN_TAKEN: 111,
};
export const BLOCKS = [];
@@ -144,6 +146,15 @@ for (let d = 0; d < 5; d++) {
def(B.PISTON_OUT + d, 'Spark Piston (pushed out)', { top: TILE.PISTON_INNER, bottom: TILE.PISTON_BACK, side: TILE.PISTON_SIDE }, { spark: 'piston', dir: d, on: true, faces: faces(TILE.PISTON_INNER), base: B.PISTON, placeable: false });
}
def(B.PISTON_HEAD, 'Piston Pusher', TILE.PISTON_FRONT, { spark: 'head', placeable: false });
+
+// ---- Course Maker ----
+// Step on Start to begin a timed run, Checkpoints save your spot, Finish ends the run.
+// Coins are collected during a run and come back when it ends.
+def(B.COURSE_START, 'Course Start', { top: TILE.COURSE_START, bottom: TILE.PAD_SIDE, side: TILE.PAD_SIDE }, { course: 'start' });
+def(B.COURSE_CHECK, 'Checkpoint', { top: TILE.COURSE_CHECK, bottom: TILE.PAD_SIDE, side: TILE.PAD_SIDE }, { course: 'check' });
+def(B.COURSE_FINISH, 'Course Finish', { top: TILE.COURSE_FINISH, bottom: TILE.PAD_SIDE, side: TILE.PAD_SIDE }, { course: 'finish' });
+def(B.COIN, 'Coin', TILE.COIN, { solid: false, transparent: true, shape: 'plant', emissive: true, course: 'coin' });
+def(B.COIN_TAKEN, 'Coin (collected)', TILE.COIN_TAKEN, { solid: false, transparent: true, shape: 'plant', course: 'taken', placeable: false });
/** Facing-aware block: turns a placed directional item into the variant facing `dir`. */
export function sparkFacing(id, dir) {
const b = BLOCKS[id];
diff --git a/src/course.js b/src/course.js
new file mode 100644
index 0000000..16a0f5a
--- /dev/null
+++ b/src/course.js
@@ -0,0 +1,139 @@
+// Course Maker: players build their own obstacle courses and races.
+// Course Start step on it to start the clock (step on it again to restart)
+// Checkpoint saves your spot; fall off (or press R) to go back to it
+// Course Finish stops the clock, celebrates, and remembers your best time
+// Coin collect them during a run; they come back when the run ends
+// Best times are saved with the world, one per Start pad.
+import { B, BLOCKS } from './blocks.js';
+import { CS } from './world.js';
+
+const COURSE_RANGE = 128; // coins counted around the Start pad
+const MAX_RUN = 30 * 60; // a run gives up after 30 minutes
+const FALL_LIMIT = 24; // falling this far below the checkpoint sends you back
+
+export const fmtTime = (s) => (s < 60 ? `${s.toFixed(2)} s` : `${Math.floor(s / 60)}:${(s % 60).toFixed(2).padStart(5, '0')}`);
+
+export class Course {
+ /**
+ * @param {object} h { getWorld(), getPlayer(), now(), onStart(run), onCheckpoint(), onCoin(run), onFinish(result), onRespawn(), onCancel(reason) }
+ */
+ constructor(h) {
+ Object.assign(this, h);
+ this.run = null;
+ this.best = new Map(); // "x,y,z" of a Start pad -> best seconds
+ this.internal = false; // true while coins change (not an undo step, not shared, not a real edit)
+ this.taken = []; // coins collected this run
+ }
+
+ /** New world: any coins left "collected" by a closed tab come back. */
+ reset(world, saved) {
+ this.run = null; this.taken = [];
+ this.best = new Map(Array.isArray(saved) ? saved.filter((e) => Array.isArray(e) && typeof e[0] === 'string' && Number.isFinite(e[1])).slice(0, 200) : []);
+ for (const [x, y, z] of this.find(world, (id) => id === B.COIN_TAKEN)) this.set(world, x, y, z, B.COIN);
+ }
+
+ toJSON() { return [...this.best].map(([k, t]) => [k, Math.round(t * 1000) / 1000]); }
+
+ /** Placed blocks matching test (course blocks only come from player edits). */
+ find(world, test, near = null) {
+ const out = [];
+ for (const [ck, m] of world.edits) {
+ const [cx, cz] = ck.split(',').map(Number);
+ if (near && (Math.abs(cx * CS - near[0]) > COURSE_RANGE + CS || Math.abs(cz * CS - near[2]) > COURSE_RANGE + CS)) continue;
+ for (const [i, id] of m) {
+ if (!test(id)) continue;
+ const x = cx * CS + (i % CS), z = cz * CS + (Math.floor(i / CS) % CS), y = Math.floor(i / (CS * CS));
+ if (world.getBlock(x, y, z) !== id) continue;
+ if (near && (Math.abs(x - near[0]) > COURSE_RANGE || Math.abs(z - near[2]) > COURSE_RANGE)) continue;
+ out.push([x, y, z]);
+ }
+ }
+ return out;
+ }
+
+ set(world, x, y, z, id) {
+ this.internal = true;
+ try { world.setBlock(x, y, z, id); } finally { this.internal = false; }
+ }
+
+ restoreCoins() {
+ const W = this.getWorld();
+ for (const [x, y, z] of this.taken) if (W.getBlock(x, y, z) === B.COIN_TAKEN) this.set(W, x, y, z, B.COIN);
+ this.taken = [];
+ W.flushDirty();
+ }
+
+ start(x, y, z) {
+ const W = this.getWorld();
+ this.restoreCoins();
+ const key = `${x},${y},${z}`;
+ const total = this.find(W, (id) => id === B.COIN || id === B.COIN_TAKEN, [x, y, z]).length;
+ this.run = { key, t0: this.now(), coins: 0, total, check: [x + 0.5, y + 1, z + 0.5], checkKey: key, finished: false };
+ this.onStart?.(this.run);
+ }
+
+ finish() {
+ const r = this.run;
+ const time = this.now() - r.t0;
+ const before = this.best.get(r.key);
+ const newBest = before == null || time < before;
+ if (newBest) this.best.set(r.key, time);
+ this.run = null;
+ const result = { time, coins: r.coins, total: r.total, best: newBest ? time : before, newBest, beatOld: newBest && before != null };
+ setTimeout(() => this.restoreCoins(), 1500);
+ this.onFinish?.(result);
+ }
+
+ cancel(reason) {
+ if (!this.run) return;
+ this.run = null;
+ this.restoreCoins();
+ this.onCancel?.(reason);
+ }
+
+ /** Back to the last checkpoint (R key, the โบ button, or after a big fall). */
+ respawn() {
+ const r = this.run;
+ if (!r) return;
+ const P = this.getPlayer();
+ P.pos.set(r.check[0], r.check[1], r.check[2]);
+ P.vel.set(0, 0, 0);
+ this.onRespawn?.();
+ }
+
+ /** Called every frame while playing. */
+ update() {
+ const W = this.getWorld(), P = this.getPlayer();
+ const x = Math.floor(P.pos.x), z = Math.floor(P.pos.z);
+ // Coins: touch them with your body.
+ if (this.run) {
+ for (const dy of [0.2, 1.1]) {
+ const y = Math.floor(P.pos.y + dy);
+ if (W.getBlock(x, y, z) === B.COIN) {
+ this.set(W, x, y, z, B.COIN_TAKEN);
+ W.flushDirty();
+ this.taken.push([x, y, z]);
+ this.run.coins++;
+ this.onCoin?.(this.run, [x, y, z]);
+ }
+ }
+ if (P.flying) return this.cancel('flying');
+ if (this.now() - this.run.t0 > MAX_RUN) return this.cancel('time');
+ if (P.pos.y < this.run.check[1] - FALL_LIMIT) this.respawn();
+ }
+ // Pads: step on them.
+ if (!P.onGround) { this.lastPad = ''; return; }
+ const y = Math.floor(P.pos.y - 0.05);
+ const id = W.getBlock(x, y, z);
+ const kind = BLOCKS[id]?.course;
+ const key = `${x},${y},${z}`;
+ if (!kind || kind === 'coin' || kind === 'taken') { this.lastPad = ''; return; }
+ if (key === this.lastPad) return;
+ this.lastPad = key;
+ if (kind === 'start') this.start(x, y, z);
+ else if (kind === 'check' && this.run && this.run.checkKey !== key) {
+ this.run.check = [x + 0.5, y + 1, z + 0.5]; this.run.checkKey = key;
+ this.onCheckpoint?.(this.run);
+ } else if (kind === 'finish' && this.run) this.finish();
+ }
+}
diff --git a/src/items.js b/src/items.js
index 16044dc..bed6fe9 100644
--- a/src/items.js
+++ b/src/items.js
@@ -124,6 +124,7 @@ mine([B.LANTERN], 0.3);
mine([B.PORTAL_BLUE, B.PORTAL_ORANGE, B.PORTAL_GREEN, B.PORTAL_PURPLE], 0.4);
mine([B.CACTUS], 0.4);
mine(BLOCKS.filter((b) => b?.spark).map((b) => b.id), 0.3);
+mine(BLOCKS.filter((b) => b?.course).map((b) => b.id), 0.3);
mine([B.WOOL_WHITE, B.WOOL_RED, B.WOOL_BLUE, B.WOOL_YELLOW, B.WOOL_GREEN, B.WOOL_BLACK], 0.8);
const DROPS = {
@@ -157,6 +158,7 @@ export function dropFor(blockId, rand = Math.random()) {
if (blockId === B.FARMLAND) return B.DIRT;
if (blockId === B.WATER || blockId === B.BEDROCK || blockId === B.AIR) return null;
if (BLOCKS[blockId]?.spark) return BLOCKS[blockId].base ?? null; // on/off and facing variants give the plain item back
+ if (blockId === B.COIN_TAKEN) return B.COIN;
return DROPS[blockId] ?? (ITEMS.has(blockId) ? blockId : null);
}
@@ -192,6 +194,11 @@ recipe(I.WATERING_CAN, 1, [[I.IRON_INGOT, 1], [B.PLANKS, 2]], 'table');
recipe(B.TORCH, 4, [[I.STICK, 1], [I.COAL, 1]]);
// Spark circuits
recipe(B.WIRE, 8, [[I.GOLD_INGOT, 1], [I.COAL, 1]], 'table');
+// Course Maker
+recipe(B.COURSE_START, 1, [[B.PLANKS, 2], [B.WOOL_GREEN, 1]]);
+recipe(B.COURSE_CHECK, 1, [[B.PLANKS, 2], [B.WOOL_BLUE, 1]]);
+recipe(B.COURSE_FINISH, 1, [[B.PLANKS, 2], [B.WOOL_WHITE, 1], [B.WOOL_BLACK, 1]]);
+recipe(B.COIN, 8, [[I.GOLD_INGOT, 1]]);
recipe(B.LEVER, 1, [[I.STICK, 1], [B.COBBLE, 1], [B.WIRE, 1]]);
recipe(B.BUTTON, 1, [[B.STONE, 1], [B.WIRE, 1]]);
recipe(B.PLATE, 1, [[B.PLANKS, 2], [B.WIRE, 1]]);
diff --git a/src/main.js b/src/main.js
index 9df1871..b865288 100644
--- a/src/main.js
+++ b/src/main.js
@@ -25,6 +25,8 @@ import { Spark } from './spark.js';
import { makeShareLink, readSharedFromHash, validateShared } from './share.js';
import { Together, COLORS, ANIMALS, EMOJI, profileName, saveProfile, loadSiteConfig, SITE } from './together.js';
import { Account, accountMessage } from './account.js';
+import { Course, fmtTime } from './course.js';
+import { PhotoMode, FRAMES, FILTERS, STICKERS } from './photo.js';
const account = new Account();
import { IDEAS, ideaOfTheDay } from './ideas.js';
@@ -81,6 +83,112 @@ const spark = new Spark({
onChange: () => { dirtySave = true; },
onEvent: (kind) => quests.emit('spark', { kind }),
});
+// ---------- Course Maker ----------
+const course = new Course({
+ getWorld: () => world,
+ getPlayer: () => player,
+ now: () => simTime,
+ onStart(run) {
+ sfx.tone(520, 0.12, 'square', 0.12); setTimeout(() => sfx.tone(780, 0.18, 'square', 0.14), 150);
+ toast(run.total ? `๐ Go! Collect ${run.total} coin${run.total === 1 ? '' : 's'} and reach the Finish!` : '๐ Go! Reach the Finish pad!');
+ renderCourseHud();
+ quests.emit('course', { kind: 'start' });
+ },
+ onCheckpoint() { sfx.tone(880, 0.15, 'triangle', 0.14, 300); toast('๐ฉ Checkpoint! Fall off and you come back here.'); },
+ onCoin(run, [x, y, z]) {
+ sfx.tone(1200 + run.coins * 40, 0.08, 'square', 0.1, 600);
+ particles.burst(x, y, z, TILE.COIN);
+ renderCourseHud();
+ },
+ onRespawn() { sfx.whoosh?.(); },
+ onFinish(r) {
+ const p = player.pos;
+ for (const tile of [TILE.WOOL_RED, TILE.WOOL_BLUE, TILE.WOOL_YELLOW, TILE.WOOL_GREEN, TILE.COIN]) particles.burst(Math.floor(p.x), Math.floor(p.y) + 1, Math.floor(p.z), tile);
+ sfx.fanfare?.(); sfx.yay?.();
+ const coins = r.total ? ` ยท ๐ช ${r.coins}/${r.total}` : '';
+ hint(`๐ Finished in ${fmtTime(r.time)}${coins}${r.newBest ? (r.beatOld ? ' ยท ๐ New best time!' : '') : ` ยท Best ${fmtTime(r.best)}`}`, 4500);
+ renderCourseHud();
+ quests.emit('course', { kind: 'finish', time: r.time, coins: r.coins, total: r.total, beatOld: r.beatOld });
+ dirtySave = true;
+ },
+ onCancel(reason) {
+ toast(reason === 'flying' ? 'Course run stopped: no flying during a run! Step on Start to try again.' : 'Course run stopped.');
+ renderCourseHud();
+ },
+});
+function renderCourseHud() {
+ const run = course.run;
+ $('course-hud').classList.toggle('hidden', !run);
+ document.getElementById('t-respawn')?.classList.toggle('hidden', !run);
+ if (run) $('course-coins').textContent = run.total ? `๐ช ${run.coins}/${run.total}` : '';
+}
+
+// ---------- Photo Mode ----------
+const photo = new PhotoMode();
+async function openPhoto() {
+ if (state !== 'playing') return;
+ renderer.render(scene, camera); // capture a clean frame (the HUD is not part of the 3D view)
+ await photo.capture(canvas);
+ state = 'photo';
+ clearInput();
+ touch?.setEnabled(false);
+ if (document.pointerLockElement) document.exitPointerLock();
+ sfx.tone(1400, 0.05, 'square', 0.12); setTimeout(() => sfx.tone(900, 0.08, 'square', 0.1), 60); // click!
+ $('photo').classList.remove('hidden');
+ renderPhoto();
+}
+function closePhoto() {
+ $('photo').classList.add('hidden');
+ state = 'menu';
+ enterPlay();
+}
+function renderPhoto() {
+ const chips = (box, items, current, pick) => {
+ box.innerHTML = '';
+ for (const [key, label] of items) {
+ const b = document.createElement('button');
+ b.type = 'button'; b.className = 'chip' + (key === current ? ' on' : ''); b.textContent = label;
+ b.addEventListener('click', () => { pick(key); renderPhoto(); });
+ box.appendChild(b);
+ }
+ };
+ chips($('ph-frames'), FRAMES, photo.frame, (k) => { photo.frame = k; });
+ chips($('ph-filters'), FILTERS, photo.filter, (k) => { photo.filter = k; });
+ chips($('ph-stickers'), STICKERS.map((e) => [e, e]), photo.sticker, (k) => { photo.sticker = k; });
+ $('ph-caption-row').classList.toggle('hidden', photo.frame !== 'polaroid');
+ const c = photo.draw();
+ const box = $('ph-canvas');
+ if (c.parentNode !== box) { box.innerHTML = ''; box.appendChild(c); }
+}
+$('ph-canvas').addEventListener('click', (e) => {
+ const pt = photo.photoPoint(e, photo.canvas);
+ if (!pt) return;
+ photo.addSticker(pt);
+ sfx.pop();
+ renderPhoto();
+});
+$('ph-undo').addEventListener('click', () => { photo.stickers.pop(); renderPhoto(); });
+$('ph-caption').addEventListener('input', (e) => { photo.caption = e.target.value; renderPhoto(); });
+$('ph-caption').addEventListener('keydown', (e) => e.stopPropagation());
+$('ph-close').addEventListener('click', closePhoto);
+$('ph-save').addEventListener('click', async () => {
+ const blob = await photo.blob();
+ const a = document.createElement('a');
+ a.href = URL.createObjectURL(blob);
+ a.download = `minicrafter-${new Date().toISOString().slice(0, 19).replace(/[T:]/g, '-')}.png`;
+ document.body.appendChild(a); a.click(); a.remove();
+ setTimeout(() => URL.revokeObjectURL(a.href), 4000);
+ toast('๐ท Photo saved!');
+ quests.emit('photo', {});
+});
+$('ph-share').addEventListener('click', async () => {
+ const blob = await photo.blob();
+ const file = new File([blob], 'minicrafter.png', { type: 'image/png' });
+ if (navigator.canShare?.({ files: [file] })) {
+ try { await navigator.share({ files: [file], title: 'My MiniCrafter build' }); quests.emit('photo', {}); } catch { /* cancelled */ }
+ } else $('ph-save').click();
+});
+
// ---------- Play Together ----------
let guestReturnId = null; // the world to go back to after visiting a friend's game
const together = new Together({
@@ -248,6 +356,7 @@ function startWorld(seedStr, saved, newMode) {
player.onLand = (dist) => { if (isSurvival()) survival.landed(dist); };
world.onChange = (x, y, z, from, to) => {
spark.track(x, y, z, from, to);
+ if (course.internal) return; // collected coins are only part of this player's run
together.queueEdit(x, y, z, to); // Play Together: share every change (unless it came from the network)
if (!spark.internal && !together.applying) history.record(x, y, z, from, to); // circuits switching and friends' edits aren't undo steps
};
@@ -298,6 +407,8 @@ function startWorld(seedStr, saved, newMode) {
spawn();
}
spark.reset(world);
+ course.reset(world, saved?.courses);
+ renderCourseHud();
if (!spawnPoint) spawnPoint = findSpawnColumn();
const meta = worlds.get(currentWorldId);
adv.hardcore = !!meta?.hardcore;
@@ -338,6 +449,7 @@ function save() {
mode, inv: inv.toJSON(), health: survival.health, spawn: spawnPoint, tips: [...shownTips], mobs: mobs.serialize(), quests: quests.toJSON(), robot: robot.toJSON(), robotCode: robotUI.getState(),
crops: [...crops].map(([k, t]) => [...k.split(',').map(Number), Math.round(t)]),
xp: adv.xp, level: adv.level, hunger: survival.hunger, over: adv.over, graves: [...adv.graves], armor: adv.armor,
+ courses: course.toJSON(),
}, { mode, stars: quests.stars });
if (ok) dirtySave = false;
}
@@ -538,6 +650,7 @@ function pickerTab(id) {
const def = ITEMS.get(id), blk = id < 256 ? BLOCKS[id] : null;
if (blk) {
if (blk.spark) return 'spark';
+ if (blk.course) return 'fun';
if (blk.plant || NATURE.has(id)) return 'nature';
if (blk.bounce || blk.speed || blk.slippery || blk.fan || blk.note !== undefined || blk.confetti || blk.portal || blk.star || blk.emissive) return 'fun';
return 'build';
@@ -1088,7 +1201,7 @@ $('acc-delete').addEventListener('click', async () => {
// Every pop-up panel gets a โ that is always on screen, and tapping the dimmed area
// outside a panel closes it too. (Phones have no Escape key, and on a small screen the
// Done button can be scrolled out of sight under a long list.)
-for (const [overlay, done] of [['inventory', 'inv-done'], ['craft', 'craft-done'], ['worlds', 'w-done'], ['trade', 'tr-done'], ['questbook', 'qb-done'], ['together', 'tg-close'], ['account', 'acc-done'], ['gate', 'gate-cancel']]) {
+for (const [overlay, done] of [['inventory', 'inv-done'], ['craft', 'craft-done'], ['worlds', 'w-done'], ['trade', 'tr-done'], ['questbook', 'qb-done'], ['together', 'tg-close'], ['account', 'acc-done'], ['gate', 'gate-cancel'], ['photo', 'ph-close']]) {
const ov = $(overlay);
const x = document.createElement('button');
x.type = 'button'; x.className = 'x-close'; x.textContent = 'โ'; x.setAttribute('aria-label', 'Close');
@@ -1407,6 +1520,10 @@ document.addEventListener('keydown', (e) => {
if (e.code === 'KeyQ' || e.code === 'Escape') closeOverlay(e.code === 'KeyQ');
return;
}
+ if (state === 'photo') {
+ if (e.code === 'Escape' || e.code === 'KeyP') closePhoto();
+ return;
+ }
if (state === 'robot' || state === 'trade') {
if (e.code === 'Escape') closeOverlay(false);
return;
@@ -1432,6 +1549,8 @@ document.addEventListener('keydown', (e) => {
if (e.code === 'KeyZ') undoRedo(false);
if (e.code === 'KeyY') undoRedo(true);
if (e.code === 'KeyT' && together.active) toggleEmojiBar();
+ if (e.code === 'KeyR' && course.run) course.respawn();
+ if (e.code === 'KeyP') openPhoto();
if (e.code === 'KeyL' && knockId != null) answerKnock(true);
if (e.code === 'KeyN' && knockId != null) answerKnock(false);
});
@@ -1504,6 +1623,8 @@ const touch = touchMode ? new TouchControls({
else if (name === 'pause' && state === 'playing') showMenu();
else if (name === 'undo' && state === 'playing') undoRedo(false);
else if (name === 'emoji' && state === 'playing') toggleEmojiBar();
+ else if (name === 'respawn' && state === 'playing') course.respawn();
+ else if (name === 'photo' && state === 'playing') openPhoto();
},
}) : null;
@@ -2188,7 +2309,8 @@ function frame(now, manual = false) {
mobs.maxHostile = settings.monsters === 'easy' ? 4 : 8;
player.blocking = state === 'playing' && isAdventure() && mouse.right && !!ITEMS.get(heldItem())?.shield;
spark.passive = together.isGuest; // the host runs the circuits; guests see the results
- if (state === 'playing') { updateBow(simTime); projectiles.update(dt); if (!together.isGuest) spark.update(dt); }
+ if (state === 'playing') { updateBow(simTime); projectiles.update(dt); if (!together.isGuest) spark.update(dt); course.update(); }
+ if (course.run) $('course-time').textContent = fmtTime(simTime - course.run.t0);
together.update(dt);
mobs.update(dt, player, light, state === 'playing' || (state === 'menu' && !hasPlayed));
critters.update(dt, player, light, timeOfDay > 0.55 && timeOfDay < 0.95, state === 'playing' || (state === 'menu' && !hasPlayed));
@@ -2296,7 +2418,7 @@ $('btn-install').addEventListener('click', () => {
// Expose for debugging in the console.
window.minicrafter = {
get world() { return world; }, get player() { return player; }, get target() { return target; },
- get inv() { return inv; }, adv, projectiles, spark, together, account, placeFacing, lightLevel, hurtPlayer, bow, gainXp, isAdventure, createWorld, history, tool, undoRedo, crops, waterAt, critters, findPortals, get fireflyTarget() { return fireflyTarget; }, worlds, get currentWorldId() { return currentWorldId; }, openWorld, get mobTarget() { return mobTarget; }, get robotTarget() { return robotTarget; }, survival, mobs, quests, robot, robotUI, keys, mouse, save, setMode,
+ get inv() { return inv; }, adv, projectiles, spark, together, account, course, photo, openPhoto, closePhoto, get state() { return state; }, placeFacing, lightLevel, hurtPlayer, bow, gainXp, isAdventure, createWorld, history, tool, undoRedo, crops, waterAt, critters, findPortals, get fireflyTarget() { return fireflyTarget; }, worlds, get currentWorldId() { return currentWorldId; }, openWorld, get mobTarget() { return mobTarget; }, get robotTarget() { return robotTarget; }, survival, mobs, quests, robot, robotUI, keys, mouse, save, setMode,
select: (i) => select(i),
openOverlay: () => openOverlay(),
/** Dev/test helper: enter play mode without pointer lock (for automated testing). */
diff --git a/src/photo.js b/src/photo.js
new file mode 100644
index 0000000..ce481d4
--- /dev/null
+++ b/src/photo.js
@@ -0,0 +1,109 @@
+// Photo Mode: take a picture of your world, add a frame, a filter, stickers and a caption,
+// then save it to your device (or share it). Nothing is uploaded anywhere.
+export const FRAMES = [['none', 'None'], ['polaroid', 'Polaroid'], ['rainbow', 'Rainbow'], ['stars', 'Starry']];
+export const FILTERS = [['normal', 'Normal'], ['warm', 'Sunny'], ['cool', 'Frosty'], ['bw', 'Black & white'], ['retro', 'Retro']];
+export const STICKERS = ['โญ', 'โค๏ธ', '๐', '๐', '๐ฐ', '๐ถ', '๐ฑ', '๐ท', '๐ฆ', '๐ธ', '๐', '๐', '๐ฅ', '๐', '๐ค', '๐'];
+
+const OUT_W = 1280; // saved photo width (the height follows the screen shape)
+
+export class PhotoMode {
+ constructor() {
+ this.src = null; // the captured scene (an Image)
+ this.frame = 'polaroid';
+ this.filter = 'normal';
+ this.stickers = []; // { e, x, y, s } in 0..1 photo coordinates
+ this.sticker = STICKERS[0];
+ this.caption = '';
+ this.canvas = document.createElement('canvas');
+ }
+
+ /** Grabs the current 3D view (call right after rendering). */
+ capture(glCanvas) {
+ const url = glCanvas.toDataURL('image/png');
+ this.stickers = [];
+ return new Promise((res) => {
+ const img = new Image();
+ img.onload = () => { this.src = img; res(); };
+ img.src = url;
+ });
+ }
+
+ /** Draws the finished postcard onto this.canvas. */
+ draw() {
+ const img = this.src;
+ if (!img) return this.canvas;
+ const ph = Math.round(OUT_W * img.height / img.width); // photo area
+ const pad = this.frame === 'none' ? 0 : Math.round(OUT_W * 0.035);
+ const bottom = this.frame === 'polaroid' ? Math.round(OUT_W * 0.13) : pad;
+ const c = this.canvas;
+ c.width = OUT_W + pad * 2; c.height = ph + pad + bottom;
+ const ctx = c.getContext('2d');
+ // Frame background
+ if (this.frame === 'polaroid') { ctx.fillStyle = '#fbfaf5'; ctx.fillRect(0, 0, c.width, c.height); }
+ else if (this.frame === 'rainbow') {
+ const g = ctx.createLinearGradient(0, 0, c.width, c.height);
+ ['#e5484d', '#f2862e', '#f5c518', '#4caf50', '#3b82f6', '#9b5de5'].forEach((col, i, a) => g.addColorStop(i / (a.length - 1), col));
+ ctx.fillStyle = g; ctx.fillRect(0, 0, c.width, c.height);
+ } else if (this.frame === 'stars') {
+ ctx.fillStyle = '#0b1026'; ctx.fillRect(0, 0, c.width, c.height);
+ ctx.fillStyle = '#ffe27a';
+ for (let i = 0; i < 90; i++) { const x = (i * 97) % c.width, y = (i * 53 + (i % 7) * 31) % c.height; if (x > pad && x < c.width - pad && y > pad && y < c.height - bottom) continue; ctx.font = `${10 + (i % 4) * 5}px system-ui`; ctx.fillText('โฆ', x, y); }
+ }
+ // Photo with filter
+ ctx.drawImage(img, pad, pad, OUT_W, ph);
+ if (this.filter !== 'normal') this.applyFilter(ctx, pad, pad, OUT_W, ph);
+ // Stickers
+ for (const s of this.stickers) {
+ ctx.font = `${Math.round(OUT_W * 0.07 * s.s)}px system-ui, "Apple Color Emoji", "Segoe UI Emoji", sans-serif`;
+ ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
+ ctx.fillText(s.e, pad + s.x * OUT_W, pad + s.y * ph);
+ }
+ // Caption on the Polaroid strip
+ if (this.frame === 'polaroid' && this.caption) {
+ ctx.fillStyle = '#2b2f3a'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
+ ctx.font = `600 ${Math.round(OUT_W * 0.04)}px "Comic Sans MS", "Chalkboard SE", system-ui, sans-serif`;
+ ctx.fillText(this.caption.slice(0, 40), c.width / 2, ph + pad + bottom / 2, c.width - pad * 2);
+ }
+ // A tiny watermark
+ ctx.font = `${Math.round(OUT_W * 0.016)}px system-ui, sans-serif`; ctx.textAlign = 'right'; ctx.textBaseline = 'bottom';
+ ctx.fillStyle = this.frame === 'polaroid' ? 'rgba(40,40,50,.45)' : 'rgba(255,255,255,.7)';
+ ctx.fillText('MiniCrafter', c.width - Math.max(pad, 10), c.height - Math.max(4, (bottom - OUT_W * 0.02) / 4));
+ return c;
+ }
+
+ applyFilter(ctx, x, y, w, h) {
+ const d = ctx.getImageData(x, y, w, h);
+ const p = d.data;
+ for (let i = 0; i < p.length; i += 4) {
+ let r = p[i], g = p[i + 1], b = p[i + 2];
+ if (this.filter === 'bw') { const v = 0.3 * r + 0.59 * g + 0.11 * b; r = g = b = v; }
+ else if (this.filter === 'warm') { r = r * 1.1 + 12; g = g * 1.03 + 4; b = b * 0.88; }
+ else if (this.filter === 'cool') { r = r * 0.9; g = g * 1.0 + 4; b = b * 1.12 + 14; }
+ else if (this.filter === 'retro') { const v = 0.3 * r + 0.59 * g + 0.11 * b; r = v * 0.6 + r * 0.4 + 30; g = v * 0.6 + g * 0.4 + 14; b = v * 0.6 + b * 0.4 - 10; }
+ p[i] = r < 0 ? 0 : r > 255 ? 255 : r; p[i + 1] = g < 0 ? 0 : g > 255 ? 255 : g; p[i + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
+ }
+ if (this.filter === 'retro') { // soft vignette
+ ctx.putImageData(d, x, y);
+ const v = ctx.createRadialGradient(x + w / 2, y + h / 2, Math.min(w, h) * 0.35, x + w / 2, y + h / 2, Math.max(w, h) * 0.7);
+ v.addColorStop(0, 'rgba(0,0,0,0)'); v.addColorStop(1, 'rgba(40,20,0,0.45)');
+ ctx.fillStyle = v; ctx.fillRect(x, y, w, h);
+ return;
+ }
+ ctx.putImageData(d, x, y);
+ }
+
+ /** Where on the photo (0..1) a click on the displayed canvas landed, or null if it was on the frame. */
+ photoPoint(evt, el) {
+ const r = el.getBoundingClientRect();
+ const c = this.canvas;
+ const pad = this.frame === 'none' ? 0 : Math.round(OUT_W * 0.035);
+ const ph = c.height - pad - (this.frame === 'polaroid' ? Math.round(OUT_W * 0.13) : pad);
+ const cx = (evt.clientX - r.left) / r.width * c.width, cy = (evt.clientY - r.top) / r.height * c.height;
+ const x = (cx - pad) / OUT_W, y = (cy - pad) / ph;
+ return x >= 0 && x <= 1 && y >= 0 && y <= 1 ? { x, y } : null;
+ }
+
+ addSticker(pt) { if (this.stickers.length < 30) this.stickers.push({ e: this.sticker, x: pt.x, y: pt.y, s: 0.8 + Math.random() * 0.5 }); }
+
+ blob() { return new Promise((res) => this.draw().toBlob(res, 'image/png')); }
+}
diff --git a/src/quests.js b/src/quests.js
index 66ab7cc..baeb5dd 100644
--- a/src/quests.js
+++ b/src/quests.js
@@ -49,6 +49,10 @@ export const QUESTS = [
{ id: 'climb', track: 'all', icon: 'โฐ๏ธ', title: 'Mountain Top', text: 'Climb up high until you reach height 60. Press F3 to see your height.', event: 'height', value: (d) => Math.floor(d), count: 60, stars: 2 },
{ id: 'night', track: 'all', icon: 'โญ', title: 'Star Gazer', text: 'Stay up until night and look at the stars.', event: 'night', count: 1, stars: 1 },
{ id: 'trade3', track: 'survival', icon: '๐ค', title: 'Fair Trader', text: 'Make 3 trades with villagers. Count what you give and what you get!', event: 'trade', count: 3, stars: 2 },
+ { id: 'course1', track: 'all', icon: '๐', title: 'Ready, Set, Go!', text: 'Build a course: a Course Start pad, some jumps, and a Course Finish pad. Step on Start and race to the Finish!', event: 'course', test: (d) => d.kind === 'finish', count: 1, stars: 2 },
+ { id: 'coins', track: 'all', icon: '๐ช', title: 'Coin Collector', text: 'Put at least 5 coins along a course, then collect every one of them in a single run.', event: 'course', test: (d) => d.kind === 'finish' && d.total >= 5 && d.coins === d.total, count: 1, stars: 2 },
+ { id: 'pb', track: 'all', icon: '๐', title: 'Personal Best', text: 'Beat your best time on a course. Can you find a faster way?', event: 'course', test: (d) => d.kind === 'finish' && d.beatOld, count: 1, stars: 2 },
+ { id: 'photo', track: 'all', icon: '๐ท', title: 'Say Cheese!', text: 'Press P (or tap ๐ท) to take a photo of your build. Add a frame and a sticker, then save it.', event: 'photo', count: 1, stars: 1 },
{ id: 'lamp', track: 'all', icon: '๐ก', title: 'Light It Up', text: 'Put Spark Wire from a Spark Lever to a Spark Lamp, then right-click the lever to switch it on.', event: 'spark', test: (d) => d.kind === 'lamp', count: 1, stars: 2 },
{ id: 'sparkdoor', track: 'all', icon: '๐ช', title: 'Secret Door', text: 'Wire a Pressure Plate or Button to a Spark Door so it opens all by itself.', event: 'spark', test: (d) => d.kind === 'door', count: 1, stars: 2 },
{ id: 'piston', track: 'all', icon: '๐ฆ', title: 'Push It!', text: 'Power a Spark Piston so it pushes a block. Pistons can even lift you up!', event: 'spark', test: (d) => d.kind === 'piston', count: 1, stars: 2 },
diff --git a/src/textures.js b/src/textures.js
index 5482a58..acc5eab 100644
--- a/src/textures.js
+++ b/src/textures.js
@@ -4,7 +4,7 @@ import { mulberry32 } from './noise.js';
export const T = 16; // tile size in px
export const COLS = 8;
-export const ROWS = 13;
+export const ROWS = 14;
export const ATLAS_W = COLS * T;
export const ATLAS_H = ROWS * T;
@@ -26,6 +26,7 @@ export const TILE = {
BATTERY: 83, GATE_SIDE: 84, INVERTER: 85, INVERTER_ON: 86, DELAY: 87, DELAY_ON: 88,
SPARK_LAMP: 89, SPARK_LAMP_ON: 90, SPARK_DOOR: 91, SPARK_DOOR_OPEN: 92,
PISTON_FRONT: 93, PISTON_SIDE: 94, PISTON_BACK: 95, PISTON_INNER: 96,
+ COURSE_START: 97, COURSE_CHECK: 98, COURSE_FINISH: 99, COIN: 100, COIN_TAKEN: 101, PAD_SIDE: 102,
};
/** Rainbow colours for the 8 musical step-stones (do re mi fa sol la ti do). */
@@ -371,6 +372,29 @@ export function createAtlas() {
return vary([110, 112, 120], 0.12);
});
paint(TILE.PISTON_BACK, (x, y) => (edge(x, y) ? [50, 52, 60] : Math.hypot(x - 7.5, y - 7.5) < 3 ? [70, 72, 82] : vary([110, 112, 120], 0.12)));
+ // ---- Course Maker pads and coins ----
+ const padEdge = (x, y) => x === 0 || y === 0 || x === T - 1 || y === T - 1;
+ const flag = (tile, base, cloth) => paint(tile, (x, y) => {
+ if (padEdge(x, y)) return [235, 235, 240];
+ if (x === 5 && y >= 3 && y <= 12) return [80, 60, 40]; // pole
+ if (x >= 6 && x <= 11 && y >= 3 && y <= 7 && (x - 6) <= 6 - Math.abs(y - 5) * 0.6) return cloth;
+ return vary(base, 0.06);
+ });
+ flag(TILE.COURSE_START, [70, 170, 80], [255, 255, 255]);
+ flag(TILE.COURSE_CHECK, [60, 120, 210], [255, 215, 60]);
+ paint(TILE.COURSE_FINISH, (x, y) => (padEdge(x, y) ? [235, 235, 240] : ((x >> 2) + (y >> 2)) % 2 ? [30, 30, 36] : [245, 245, 250]));
+ paint(TILE.PAD_SIDE, (x, y) => (y < 3 ? [235, 235, 240] : y === 3 ? [180, 180, 190] : vary([120, 125, 135], 0.08)));
+ const coin = (tile, alpha, c) => paint(tile, (x, y) => {
+ const dx = x - 7.5, dy = y - 7.5, r = Math.hypot(dx * 1.25, dy);
+ if (r > 6.2) return [0, 0, 0, 0];
+ if (r > 5.2) return [c[0] * 0.75, c[1] * 0.75, c[2] * 0.6, alpha];
+ if ((x === 7 || x === 8) && y >= 4 && y <= 11) return [c[0] * 0.8, c[1] * 0.78, c[2] * 0.5, alpha]; // a star line on the face
+ if (dx < -1 && dy < -1 && r < 3.6) return [255, 255, 235, alpha]; // shine
+ return [c[0], c[1], c[2], alpha];
+ });
+ coin(TILE.COIN, 255, [255, 205, 50]);
+ coin(TILE.COIN_TAKEN, 255, [120, 120, 130]);
+
paint(TILE.PISTON_INNER, (x, y) => (edge(x, y) ? [50, 52, 60] : x >= 6 && x <= 9 && y >= 6 && y <= 9 ? [140, 140, 150] : vary([60, 62, 70], 0.1)));
// Ores: stone + clusters of mineral pixels.
diff --git a/style.css b/style.css
index f9fc014..16ea852 100644
--- a/style.css
+++ b/style.css
@@ -455,3 +455,29 @@ label.check input { width: 22px; height: 22px; flex: none; margin: 0; accent-col
a.online-link { display: block; text-align: center; text-decoration: none; color: #fff; padding: 8px 14px; border-radius: 6px; border: 2px solid #3b82f6; background: #24324f; font-weight: 600; margin-top: 8px; }
a.online-link:hover { background: #2c3d60; }
a.online-link small { display: block; font-weight: 400; color: #9cc3ff; }
+
+/* ---------- Course Maker ---------- */
+#course-hud { position: absolute; top: 44px; left: 50%; transform: translateX(-50%); display: flex; gap: 14px; align-items: center; padding: 6px 14px; border-radius: 999px; background: rgba(20, 40, 20, .78); border: 2px solid #66b043; font-size: 1.05rem; white-space: nowrap; }
+#course-hud b { font-variant-numeric: tabular-nums; color: #ffe27a; }
+#course-hud .course-key { font-size: .75rem; color: #cfd6e4; }
+body.touch #course-hud .course-key { display: none; }
+#t-photo { top: 14px; right: max(14px, env(safe-area-inset-right)); left: auto; width: 52px; height: 52px; font-size: 22px; }
+#t-respawn { left: max(24px, env(safe-area-inset-left)); bottom: 200px; }
+body.touch #quest-tracker { right: calc(max(10px, env(safe-area-inset-right)) + 60px); }
+@media (max-height: 520px) {
+ #course-hud { top: 34px; font-size: .9rem; padding: 4px 10px; }
+ #t-photo { top: 8px; width: 44px; height: 44px; font-size: 18px; }
+ #t-respawn { bottom: 134px; left: max(14px, env(safe-area-inset-left)); }
+}
+
+/* ---------- Photo Mode ---------- */
+.photo-panel { width: min(900px, 100%); }
+.ph-canvas { margin-top: 8px; border-radius: 8px; overflow: hidden; background: #000; cursor: crosshair; }
+.ph-canvas { display: flex; justify-content: center; }
+.ph-canvas canvas { display: block; width: auto; height: auto; max-width: 100%; max-height: 52vh; }
+.ph-controls { display: grid; gap: 8px; margin-top: 10px; }
+.ph-label { font-size: .8rem; color: #9aa3b5; }
+.ph-controls .chips { margin-top: 4px; }
+.ph-stickers .chip { font-size: 1.2rem; padding: 2px 8px; }
+#ph-caption-row { display: grid; gap: 4px; }
+#ph-caption { font: inherit; padding: 8px 10px; border-radius: 6px; border: 2px solid #4b556b; background: #121622; color: #fff; user-select: text; -webkit-user-select: text; }
diff --git a/sw.js b/sw.js
index 62e8a4a..8a04702 100644
--- a/sw.js
+++ b/sw.js
@@ -1,6 +1,6 @@
// Service worker: caches the whole game so it works offline once loaded.
// Bump VERSION whenever files change so players get the update.
-const VERSION = 'minicrafter-v25';
+const VERSION = 'minicrafter-v26';
const CORE = [
'./', './index.html', './style.css', './privacy.html', './terms.html', './legal.css', './manifest.webmanifest', './site-config.json',
'./icons/icon-192.png', './icons/icon-512.png', './icons/icon-maskable-512.png', './icons/apple-touch-icon.png', './icons/favicon-32.png',
@@ -12,6 +12,8 @@ const CORE = [
'./src/spark.js',
'./src/together.js',
'./src/account.js',
+ './src/course.js',
+ './src/photo.js',
'./src/craftui.js',
'./src/critters.js',
'./src/ideas.js',
diff --git a/tests/smoke.mjs b/tests/smoke.mjs
index e7f0eaa..29bafbf 100644
--- a/tests/smoke.mjs
+++ b/tests/smoke.mjs
@@ -217,6 +217,19 @@ try {
out.a3 = lit && inverted && pushed;
}
+ // Course Maker: start pad starts a timed run, coins are collected, finish records a best time.
+ {
+ const C = m.course, cx = Math.floor(p.pos.x), cz = Math.floor(p.pos.z), cy = Math.min(88, Math.floor(p.pos.y) + 10);
+ for (let i = -1; i <= 6; i++) { W.setBlock(cx + i, cy, cz, B.STONE); for (let h = 1; h < 4; h++) W.setBlock(cx + i, cy + h, cz, 0); }
+ W.setBlock(cx, cy, cz, B.COURSE_START); W.setBlock(cx + 5, cy, cz, B.COURSE_FINISH); W.setBlock(cx + 2, cy + 1, cz, B.COIN);
+ W.flushDirty();
+ const stand = (i) => { p.flying = false; p.pos.set(cx + i + 0.5, cy + 1, cz + 0.5); p.vel.set(0, 0, 0); m.step(3, 16.7); };
+ stand(0); const started = !!C.run && C.run.total === 1;
+ stand(1); stand(2); const gotCoin = C.run?.coins === 1 && W.getBlock(cx + 2, cy + 1, cz) === B.COIN_TAKEN;
+ stand(5); const finished = !C.run && C.best.size === 1;
+ out.course = started && gotCoin && finished;
+ }
+
// Worlds: create a second world, switch back, save round trip.
const first = m.currentWorldId;
const w = m.worlds.add({ name: 'CI World', seed: 'ci', mode: 'survival' });
@@ -243,6 +256,7 @@ try {
ok(features.adventure, 'adventure: XP levels, hunger, tougher falls (gentle modes unchanged)');
ok(features.a2, 'adventure A2: no monsters in gentle modes; arrows and swords defeat them');
ok(features.a3, 'adventure A3: spark wire, inverter and piston work');
+ ok(features.course, 'course maker: start, coin, finish and best time');
ok(features.switched && features.back && features.saved, 'worlds: create, switch and save');
ok(errors.length === 0, 'no console errors (desktop)', errors.slice(0, 3).join(' | '));
if (failures) await page.screenshot({ path: 'smoke-desktop.png' });