Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
25 changes: 25 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@
<button class="tbtn" id="t-inv" data-btn="inventory" aria-label="Inventory">🎒</button>
<button class="tbtn" id="t-fly" data-btn="fly" aria-label="Fly">🕊️</button>
<button class="tbtn" id="t-emoji" data-btn="emoji" aria-label="Emoji">😊</button>
<button class="tbtn" id="t-photo" data-btn="photo" aria-label="Take a photo">📷</button>
<button class="tbtn hidden" id="t-respawn" data-btn="respawn" aria-label="Back to checkpoint">↺</button>
<button class="tbtn big" id="t-jump" data-btn="jump" aria-label="Jump / up">⬆</button>
<button class="tbtn" id="t-down" data-btn="down" aria-label="Down">⬇</button>
</div>

<div id="hud" class="hidden">
<div id="crosshair"></div>
<div id="tg-chip" class="hidden"></div>
<div id="course-hud" class="hidden"><span>⏱ <b id="course-time">0.00 s</b></span><span id="course-coins"></span><span class="course-key">R: back to checkpoint</span></div>
<div id="knock" class="hidden"><span id="knock-text"></span><button id="knock-yes" type="button">Let in <kbd>L</kbd></button><button id="knock-no" type="button">Not now <kbd>N</kbd></button></div>
<div id="emoji-bar" class="hidden"></div>
<div id="debug" class="hidden"></div>
Expand Down Expand Up @@ -146,6 +149,8 @@ <h1>MiniCrafter</h1>
<tr><td>Z / Y</td><td>Undo / redo (creative)</td></tr>
<tr><td>F3</td><td>Debug info</td></tr>
<tr><td>T then 1–8</td><td>Send an emoji (Play Together)</td></tr>
<tr><td>P</td><td>📷 Photo Mode</td></tr>
<tr><td>R</td><td>Back to the last checkpoint (Course Maker)</td></tr>
<tr><td>L / N</td><td>Let a friend in / not now (host)</td></tr>
<tr><td>Esc</td><td>Pause</td></tr>
</table>
Expand Down Expand Up @@ -233,6 +238,26 @@ <h2>👤 Your account</h2>
</div>
</div>

<div id="photo" class="overlay hidden">
<div class="panel photo-panel">
<h2>📷 Photo Mode</h2>
<div id="ph-canvas" class="ph-canvas" title="Tap the photo to add a sticker"></div>
<div class="ph-controls">
<div><span class="ph-label">Frame</span><div id="ph-frames" class="chips"></div></div>
<div><span class="ph-label">Filter</span><div id="ph-filters" class="chips"></div></div>
<div><span class="ph-label">Stickers: pick one, then tap the photo</span><div id="ph-stickers" class="chips ph-stickers"></div></div>
<label id="ph-caption-row"><span class="ph-label">Caption</span><input id="ph-caption" type="text" maxlength="40" placeholder="My amazing castle!" autocomplete="off"></label>
</div>
<div class="tg-row">
<button id="ph-undo" type="button">↶ Undo sticker</button>
<button id="ph-share" type="button">📤 Share</button>
<button id="ph-save" class="primary" type="button">💾 Save photo</button>
</div>
<p class="note">Photos are saved on your device. Nothing is uploaded.</p>
<button id="ph-close" class="wide-btn" type="button">Back to the game</button>
</div>
</div>

<div id="inventory" class="overlay hidden">
<div class="panel wide">
<h2>Blocks</h2>
Expand Down
11 changes: 11 additions & 0 deletions src/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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];
Expand Down
139 changes: 139 additions & 0 deletions src/course.js
Original file line number Diff line number Diff line change
@@ -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();
}
}
7 changes: 7 additions & 0 deletions src/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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]]);
Expand Down
Loading
Loading