Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Add a vehicle controller and chase camera to set-game, with a driving smoke (part of #777)

Nguyen Xuan Anadd18424f06b
diff --git a/changes/777-vehicle-game.md b/changes/777-vehicle-game.md
new file mode 100644
index 00000000..d599dd94
--- /dev/null
+++ b/changes/777-vehicle-game.md
@@ -0,0 +1 @@
+- `set-game` can drive the player as an arcade car (`controller: "vehicle"`, `maximumSpeed`) with a `chase` camera, and the web smoke plays a driving course next to the creature run (#777)
diff --git a/docs/game.md b/docs/game.md
index 585d11f6..0ee88b2a 100644
--- a/docs/game.md
+++ b/docs/game.md
@@ -37,10 +37,11 @@ A scene recipe can carry a `game` section. It names the node the player controls
| Field | Default | Meaning |
| --- | --- | --- |
| `player.node` | required | A node of the scene. The rules part with the same id follows the player |
-| `player.controller` | `character` | The [character controller](player.md) |
+| `player.controller` | `character` | `character` ([character controller](player.md)) or `vehicle` ([arcade car](player.md#vehicle-and-flight-controllers): W throttle, S reverse, A/D steer, Space brakes; `walkSpeed`, `runSpeed` and `jumpSpeed` are ignored) |
| `player.walkSpeed`, `runSpeed`, `jumpSpeed` | 3, 6, 7 | Metres per second, 0 to 100 |
+| `player.maximumSpeed` | 20 | Top speed of a `vehicle`, metres per second, 0 to 100 |
| `player.footOffset` | 0 | Metres from the node origin down to the feet. Zone checks use the feet |
-| `camera` | `follow` | `follow`, `first-person` or `top-down`, the [camera rigs](player.md#camera-rigs) |
+| `camera` | `follow` | `follow`, `first-person`, `top-down` or `chase` (behind the player, swinging round to its heading: use it with a `vehicle`), the [camera rigs](player.md#camera-rigs) |
| `input` | `keyboard` | `keyboard` (WASD move, arrows look, Space jump, Shift run), `gamepad` (adds the first pad) or `touch` (adds a left-half stick and tap to jump) |
| `physics` | `false` | Accepted. The web export refuses `true` until the physics engine can be bundled |
| `ground` | 0 | Height of the walkable ground in metres |
@@ -52,7 +53,7 @@ A rules part named like a scene node is hidden and shown with it, which is how a
`scene_export_web` writes one folder: `index.html`, `game.json` (the recipe) and `engine/` (the built 67js modules, found by following the imports from `build/game.js`). It runs from any static host with no server code, and the folder is bounded: the engine stays under 12 MiB, the recipe under 1 MiB, and the newest four builds are kept. Procedural scenes only; placed catalog assets and vegetation are refused with the fix. The page shows the variables and the verdict in a corner label and exposes the running game as `window.__game` (`rules.state`, `controller.state`, `scene`, `runtime`).
-`index.html?replay=name.json` plays a recording (`recordInput`, see [input](input.md#custom-and-scripted-input)) from the same folder instead of the keyboard. `scripts/smoke-game-web.mjs` builds a creature that collects 3 coins and reaches a goal through the MCP tools, exports it, and wins it from a replay in headless Chrome.
+`index.html?replay=name.json` plays a recording (`recordInput`, see [input](input.md#custom-and-scripted-input)) from the same folder instead of the keyboard. `scripts/smoke-game-web.mjs` builds a creature that collects 3 coins and reaches a goal through the MCP tools, exports it, and wins it from a replay in headless Chrome. `node scripts/smoke-game-web.mjs bin/67js-mcp.mjs drive` does the same for a car that passes 3 gates and reaches a finish line under a `chase` camera.
## From code
diff --git a/scripts/smoke-game-web.mjs b/scripts/smoke-game-web.mjs
index b7acd60e..ade53abe 100644
--- a/scripts/smoke-game-web.mjs
+++ b/scripts/smoke-game-web.mjs
@@ -9,7 +9,8 @@ import { chromium } from 'playwright-core';
// Proves the game path end to end: an agent builds a creature that runs and jumps to collect 3 coins and reach a goal using
// only MCP tools, exports it as a static web build, and a recorded input replay wins the game in headless Chrome on the GPU.
-// Run it through your GPU lock if the machine is shared: node scripts/smoke-game-web.mjs
+// A second sample drives a car through 3 gates to a finish line. Run it through your GPU lock if the machine is shared:
+// node scripts/smoke-game-web.mjs [path to 67js-mcp.mjs] [creature|drive]
setPriority(0, constants.priority.PRIORITY_BELOW_NORMAL);
const CHROME_PATH = process.env.CHROME_PATH ?? 'C:/Program Files/Google/Chrome/Application/chrome.exe';
@@ -34,45 +35,87 @@ async function callExpectingError(name, argumentsValue) {
return result.content.find(item => item.type === 'text').text;
}
-const COINS = [[0, 0.5, -3], [0, 0.5, -6], [0, 0.5, -9]];
-const GOAL = [0, 1, -12];
-const recipe = {
- format: '67js.scene', schemaVersion: 1,
- geometries: [{ id: 'block', type: 'box', bevel: 0 }, { id: 'ball', type: 'sphere' }],
- materials: [
- { id: 'grass', color: [0.2, 0.45, 0.2] }, { id: 'fur', color: [0.85, 0.45, 0.2] },
- { id: 'gold', color: [0.95, 0.75, 0.1], metallic: 0.8, roughness: 0.3 }, { id: 'flag', color: [0.2, 0.4, 0.9] },
- ],
- nodes: [
- { id: 'floor', geometry: 'block', material: 'grass', translation: [0, -0.1, -6], scale: [12, 0.2, 24] },
- { id: 'creature', translation: [0, 0.5, 0] },
- { id: 'body', parent: 'creature', geometry: 'block', material: 'fur', scale: [0.8, 0.8, 1.2] },
- { id: 'head', parent: 'creature', geometry: 'ball', material: 'fur', translation: [0, 0.35, -0.6], scale: [0.5, 0.5, 0.5] },
- ...COINS.map((translation, index) => ({ id: `coin-${index + 1}`, geometry: 'ball', material: 'gold', translation, scale: [0.4, 0.4, 0.4] })),
- { id: 'goal', geometry: 'block', material: 'flag', translation: GOAL, scale: [1.5, 2, 0.2] },
- ],
- camera: { eye: [4, 4, 6], target: [0, 0.5, -3], fov: 50 },
-};
-const coinRules = COINS.map((center, index) => ({
- id: `collect-${index + 1}`, once: true,
- when: { type: 'enter', zone: `coin-zone-${index + 1}`, tag: 'player' },
- do: [{ type: 'add', variable: 'score', value: 1 }, { type: 'hide', part: `coin-${index + 1}` }],
-}));
-const game = {
- player: { node: 'creature', footOffset: 0.5 },
- camera: 'follow',
- input: 'keyboard',
- rules: {
- version: 1,
- variables: { score: 0 },
- zones: [...COINS.map((center, index) => ({ id: `coin-zone-${index + 1}`, shape: 'sphere', center: [center[0], 0.5, center[2]], radius: 1.2 })),
- { id: 'goal-zone', shape: 'box', center: [0, 1, GOAL[2]], size: [3, 4, 2] }],
- parts: [{ id: 'creature', tags: ['player'] }, ...COINS.map((center, index) => ({ id: `coin-${index + 1}`, tags: ['coin'] }))],
- rules: [...coinRules, { id: 'reach-goal', when: { type: 'enter', zone: 'goal-zone', tag: 'player' }, if: ['>=', 'score', 3], do: [{ type: 'win' }] }],
- },
-};
-// Hold forward and run from sample 1, press jump at sample 40, and let go at sample 240.
-const replay = { version: 1, samples: 260, truncated: false, events: [[1, 'keyboard/KeyW', 1], [1, 'keyboard/ShiftLeft', 1], [40, 'keyboard/Space', 1], [42, 'keyboard/Space', 0], [240, 'keyboard/KeyW', 0], [240, 'keyboard/ShiftLeft', 0]] };
+function creatureSample() {
+ const COINS = [[0, 0.5, -3], [0, 0.5, -6], [0, 0.5, -9]];
+ const GOAL = [0, 1, -12];
+ const recipe = {
+ format: '67js.scene', schemaVersion: 1,
+ geometries: [{ id: 'block', type: 'box', bevel: 0 }, { id: 'ball', type: 'sphere' }],
+ materials: [
+ { id: 'grass', color: [0.2, 0.45, 0.2] }, { id: 'fur', color: [0.85, 0.45, 0.2] },
+ { id: 'gold', color: [0.95, 0.75, 0.1], metallic: 0.8, roughness: 0.3 }, { id: 'flag', color: [0.2, 0.4, 0.9] },
+ ],
+ nodes: [
+ { id: 'floor', geometry: 'block', material: 'grass', translation: [0, -0.1, -6], scale: [12, 0.2, 24] },
+ { id: 'creature', translation: [0, 0.5, 0] },
+ { id: 'body', parent: 'creature', geometry: 'block', material: 'fur', scale: [0.8, 0.8, 1.2] },
+ { id: 'head', parent: 'creature', geometry: 'ball', material: 'fur', translation: [0, 0.35, -0.6], scale: [0.5, 0.5, 0.5] },
+ ...COINS.map((translation, index) => ({ id: `coin-${index + 1}`, geometry: 'ball', material: 'gold', translation, scale: [0.4, 0.4, 0.4] })),
+ { id: 'goal', geometry: 'block', material: 'flag', translation: GOAL, scale: [1.5, 2, 0.2] },
+ ],
+ camera: { eye: [4, 4, 6], target: [0, 0.5, -3], fov: 50 },
+ };
+ const coinRules = COINS.map((center, index) => ({
+ id: `collect-${index + 1}`, once: true,
+ when: { type: 'enter', zone: `coin-zone-${index + 1}`, tag: 'player' },
+ do: [{ type: 'add', variable: 'score', value: 1 }, { type: 'hide', part: `coin-${index + 1}` }],
+ }));
+ const game = {
+ player: { node: 'creature', footOffset: 0.5 },
+ camera: 'follow',
+ input: 'keyboard',
+ rules: {
+ version: 1,
+ variables: { score: 0 },
+ zones: [...COINS.map((center, index) => ({ id: `coin-zone-${index + 1}`, shape: 'sphere', center: [center[0], 0.5, center[2]], radius: 1.2 })),
+ { id: 'goal-zone', shape: 'box', center: [0, 1, GOAL[2]], size: [3, 4, 2] }],
+ parts: [{ id: 'creature', tags: ['player'] }, ...COINS.map((center, index) => ({ id: `coin-${index + 1}`, tags: ['coin'] }))],
+ rules: [...coinRules, { id: 'reach-goal', when: { type: 'enter', zone: 'goal-zone', tag: 'player' }, if: ['>=', 'score', 3], do: [{ type: 'win' }] }],
+ },
+ };
+ // Hold forward and run from sample 1, press jump at sample 40, and let go at sample 240.
+ const replay = { version: 1, samples: 260, truncated: false, events: [[1, 'keyboard/KeyW', 1], [1, 'keyboard/ShiftLeft', 1], [40, 'keyboard/Space', 1], [42, 'keyboard/Space', 0], [240, 'keyboard/KeyW', 0], [240, 'keyboard/ShiftLeft', 0]] };
+ return { recipe, game, replay, title: 'Creature run', expectedScore: 3 };
+}
+
+function driveSample() {
+ const checkpointZs = [-10, -20, -30];
+ const finishZ = -40;
+ const recipe = {
+ format: '67js.scene', schemaVersion: 1,
+ geometries: [{ id: 'block', type: 'box', bevel: 0 }],
+ materials: [{ id: 'asphalt', color: [0.2, 0.2, 0.22] }, { id: 'paint', color: [0.8, 0.15, 0.1] }, { id: 'gate', color: [0.95, 0.75, 0.1] }],
+ nodes: [
+ { id: 'road', geometry: 'block', material: 'asphalt', translation: [0, -0.1, -22], scale: [8, 0.2, 52] },
+ { id: 'car', translation: [0, 0.4, 0] },
+ { id: 'car-body', parent: 'car', geometry: 'block', material: 'paint', scale: [1.2, 0.5, 2.4] },
+ ...checkpointZs.map((z, index) => ({ id: `gate-${index + 1}`, geometry: 'block', material: 'gate', translation: [0, 0.6, z], scale: [5, 1.2, 0.2] })),
+ ],
+ camera: { eye: [5, 5, 8], target: [0, 0.5, -6], fov: 50 },
+ };
+ const game = {
+ player: { node: 'car', controller: 'vehicle', maximumSpeed: 20, footOffset: 0.4 },
+ camera: 'chase',
+ input: 'keyboard',
+ rules: {
+ version: 1,
+ variables: { score: 0 },
+ zones: [...checkpointZs.map((z, index) => ({ id: `gate-zone-${index + 1}`, shape: 'box', center: [0, 1, z], size: [6, 3, 3] })),
+ { id: 'finish-zone', shape: 'box', center: [0, 1, finishZ], size: [8, 3, 3] }],
+ parts: [{ id: 'car', tags: ['player'] }, ...checkpointZs.map((z, index) => ({ id: `gate-${index + 1}`, tags: ['gate'] }))],
+ rules: [...checkpointZs.map((z, index) => ({ id: `pass-${index + 1}`, once: true, when: { type: 'enter', zone: `gate-zone-${index + 1}`, tag: 'player' }, do: [{ type: 'add', variable: 'score', value: 1 }, { type: 'hide', part: `gate-${index + 1}` }] })),
+ { id: 'finish', when: { type: 'enter', zone: 'finish-zone', tag: 'player' }, if: ['>=', 'score', 3], do: [{ type: 'win' }] }],
+ },
+ };
+ // Hold the throttle for the whole run; the car takes about 3 s to cover 40 m.
+ const replay = { version: 1, samples: 400, truncated: false, events: [[1, 'keyboard/KeyW', 1], [380, 'keyboard/KeyW', 0]] };
+ return { recipe, game, replay, title: 'Drive', expectedScore: 3 };
+}
+
+const SAMPLES = { creature: creatureSample, drive: driveSample };
+const sampleName = process.argv[3] ?? 'creature';
+assert.ok(SAMPLES[sampleName], `Unknown sample "${sampleName}". Use one of: ${Object.keys(SAMPLES).join(', ')}.`);
+const { recipe, game, replay, title, expectedScore } = SAMPLES[sampleName]();
function serveFolder(folder) {
const server = createServer(async (request, response) => {
@@ -98,14 +141,14 @@ try {
const badNode = await callExpectingError('scene_apply', { expectedRevision: 0, operations: [{ type: 'set-game', game: { ...game, player: { node: 'creatur' } } }] });
assert.match(badNode, /player\.node.*creatur.*Use one of/s);
const badRules = await callExpectingError('scene_apply', { expectedRevision: 0, operations: [{ type: 'set-game', game: { ...game, rules: { version: 1, parts: [{ id: 'coin-1', tags: ['coin'] }] } } }] });
- assert.match(badRules, /rules\.parts has no part "creature"/);
+ assert.match(badRules, new RegExp(`rules\\.parts has no part "${game.player.node}"`));
const noGame = await callExpectingError('scene_export_web', {});
assert.match(noGame, /no game/);
await call('scene_apply', { expectedRevision: 0, operations: [{ type: 'set-game', game }] });
const capabilities = await call('scene_capabilities', { topic: 'game' });
assert.ok(capabilities.value?.fields ?? capabilities.fields, 'scene_capabilities topic game answers');
- const exported = await call('scene_export_web', { title: 'Creature run' });
+ const exported = await call('scene_export_web', { title });
assert.ok(exported.bytes < 12 * 1024 * 1024, `bytes ${exported.bytes}`);
const folder = dirname(exported.entry);
await writeFile(join(folder, 'replay.json'), JSON.stringify(replay));
@@ -123,7 +166,7 @@ try {
});
const state = await page.evaluate(() => ({ ...window.__game.rules.state, y: window.__game.controller.state.position[1] }));
assert.equal(state.status, 'won');
- assert.equal(state.variables.score, 3);
+ assert.equal(state.variables.score, expectedScore);
assert.deepEqual(problems, []);
await page.screenshot({ path: join(directory, 'won.png') });
console.log(JSON.stringify({ ok: true, bytes: exported.bytes, files: exported.files, step: state.step, screenshot: join(directory, 'won.png') }));
diff --git a/src/game-setup-notes.js b/src/game-setup-notes.js
index 40e17bbb..0402d0e4 100644
--- a/src/game-setup-notes.js
+++ b/src/game-setup-notes.js
@@ -1,11 +1,11 @@
// What scene_capabilities topic game says. It sits beside game-setup.js, not in the agent scene capabilities, so the core agent-scene bundle does not carry it; the MCP runtime adds it to the scene capabilities. A test keeps the names in step with game-setup.js.
export const GAME_CAPABILITIES = Object.freeze({
field: 'recipe.game, set with set-game (null clears). Plain data, never code.',
- fields: 'player {node (a node id; its children move with it), controller character, walkSpeed 3, runSpeed 6, jumpSpeed 7 (0-100 m/s), footOffset 0 (m from the node origin down to the feet)}, camera, input, physics (bool, false), ground (height in m, 0), rules (game rules document).',
- cameras: Object.freeze(['follow', 'first-person', 'top-down']),
+ fields: 'player {node (a node id; its children move with it), controller character|vehicle (an arcade car: W throttle, S reverse, A/D steer, Space brakes), walkSpeed 3, runSpeed 6, jumpSpeed 7 (0-100 m/s), maximumSpeed 20 (vehicle top speed, 0-100 m/s), footOffset 0 (m from the node origin down to the feet)}, camera, input, physics (bool, false), ground (height in m, 0), rules (game rules document).',
+ cameras: Object.freeze(['follow', 'first-person', 'top-down', 'chase']),
inputPresets: Object.freeze({ keyboard: 'WASD and arrows move and look, Space jumps, Shift runs', gamepad: 'keyboard plus the first gamepad (stick 0, jump on button 0)', touch: 'keyboard plus a left-half virtual stick and tap to jump' }),
rules: 'version 1, variables, zones {id, shape sphere|box, center, radius|size}, parts {id, tags, position}, prefabs, rules [{id, once, when, if, do}]. The rules part named like the player node follows the player; a part named like a node is hidden or shown with it. Triggers enter|exit|contact|input|timer|variable (input actions: jump, run); actions set|add|show|hide|spawn|animation|sound|win|lose|restart. Full list: docs/game-rules.md.',
- notes: 'Yaw 0 faces -Z; W moves forward. Zone checks use the feet position. physics true is accepted but the web export refuses it for now. scene_export_web writes the playable folder.',
+ notes: 'Use camera chase with a vehicle. Yaw 0 faces -Z; W moves forward. Zone checks use the feet position. physics true is accepted but the web export refuses it for now. scene_export_web writes the playable folder.',
example: Object.freeze({
type: 'set-game',
game: Object.freeze({
diff --git a/src/game-setup.js b/src/game-setup.js
index cc226840..a89413e7 100644
--- a/src/game-setup.js
+++ b/src/game-setup.js
@@ -3,19 +3,20 @@ import { validateGameRules } from './game-rules.js';
// The `game` section of a scene recipe: which node the player controls, how, with what camera and input, and the rules
// that decide when the game is won. It is plain data. The runtime in src/game.js reads it; nothing in it is code.
-export const GAME_CAMERAS = Object.freeze(['follow', 'first-person', 'top-down']);
+export const GAME_CAMERAS = Object.freeze(['follow', 'first-person', 'top-down', 'chase']);
export const GAME_INPUT_PRESETS = Object.freeze(['keyboard', 'gamepad', 'touch']);
-export const GAME_CONTROLLERS = Object.freeze(['character']);
+export const GAME_CONTROLLERS = Object.freeze(['character', 'vehicle']);
export const GAME_SETUP_LIMITS = Object.freeze({
maxSpeed: 100,
maxJumpSpeed: 100,
+ maxVehicleSpeed: 100,
maxFootOffset: 100,
maxGround: 10000,
});
const SETUP_FIELDS = ['player', 'camera', 'input', 'physics', 'ground', 'rules'];
-const PLAYER_FIELDS = ['node', 'controller', 'walkSpeed', 'runSpeed', 'jumpSpeed', 'footOffset'];
+const PLAYER_FIELDS = ['node', 'controller', 'walkSpeed', 'runSpeed', 'jumpSpeed', 'maximumSpeed', 'footOffset'];
function fail(path, problem) {
throw new RangeError(`Game setup ${path} ${problem}`);
@@ -58,6 +59,7 @@ function normalizePlayer(player, nodeIds) {
walkSpeed: boundedNumber(player.walkSpeed, 3, 0, GAME_SETUP_LIMITS.maxSpeed, 'player.walkSpeed'),
runSpeed: boundedNumber(player.runSpeed, 6, 0, GAME_SETUP_LIMITS.maxSpeed, 'player.runSpeed'),
jumpSpeed: boundedNumber(player.jumpSpeed, 7, 0, GAME_SETUP_LIMITS.maxJumpSpeed, 'player.jumpSpeed'),
+ maximumSpeed: boundedNumber(player.maximumSpeed, 20, 0, GAME_SETUP_LIMITS.maxVehicleSpeed, 'player.maximumSpeed'),
footOffset: boundedNumber(player.footOffset, 0, -GAME_SETUP_LIMITS.maxFootOffset, GAME_SETUP_LIMITS.maxFootOffset, 'player.footOffset'),
};
return normalized;
diff --git a/src/game.js b/src/game.js
index 7598bf4d..d870480d 100644
--- a/src/game.js
+++ b/src/game.js
@@ -6,7 +6,7 @@ import { groundBounceEnvironment } from './ground-bounce.js';
import { createRuntime } from './runtime.js';
import { createInput, gamepadSource, keyboardSource } from './input.js';
import { replaySource, touchSource } from './input-sources.js';
-import { createCharacterController, createFirstPersonCamera, createFollowCamera, createTopDownCamera } from './player.js';
+import { createCharacterController, createChaseCamera, createFirstPersonCamera, createFollowCamera, createTopDownCamera, createVehicleController } from './player.js';
import { createGameRules } from './game-rules.js';
// Plays the `game` section of a scene recipe in a page: the scene, the input preset, the character controller, the camera rig
@@ -50,6 +50,7 @@ function cameraRigFor(kind, controller, input) {
const rigOptions = { subject: controller.state, input };
if (kind === 'first-person') return createFirstPersonCamera(rigOptions);
if (kind === 'top-down') return createTopDownCamera(rigOptions);
+ if (kind === 'chase') return createChaseCamera(rigOptions);
return createFollowCamera(rigOptions);
}
@@ -133,17 +134,20 @@ async function buildGame(canvas, recipe, { replay, showStatus = true, createRend
const start = nodeTranslation(recipe.nodes, game.player.node);
const body = { position: [0, 0, 0], rotationY: 0 };
let rig = null;
- const controller = createCharacterController({
- input,
- position: [start[0], start[1] - footOffset, start[2]],
- ground: game.ground,
- walkSpeed: game.player.walkSpeed,
- runSpeed: game.player.runSpeed,
- jumpSpeed: game.player.jumpSpeed,
- faceCamera: game.camera === 'first-person',
- cameraYaw: () => rig?.yaw ?? 0,
- node: body,
- });
+ const startPosition = [start[0], start[1] - footOffset, start[2]];
+ const controller = game.player.controller === 'vehicle'
+ ? createVehicleController({ input, position: startPosition, ground: game.ground, maximumSpeed: game.player.maximumSpeed, node: body })
+ : createCharacterController({
+ input,
+ position: startPosition,
+ ground: game.ground,
+ walkSpeed: game.player.walkSpeed,
+ runSpeed: game.player.runSpeed,
+ jumpSpeed: game.player.jumpSpeed,
+ faceCamera: game.camera === 'first-person',
+ cameraYaw: () => rig?.yaw ?? 0,
+ node: body,
+ });
rig = cameraRigFor(game.camera, controller, input);
const nodeIds = new Set(recipe.nodes.map(node => node.id));
diff --git a/tests/game-setup.test.js b/tests/game-setup.test.js
index 972b7fa3..9f613b21 100644
--- a/tests/game-setup.test.js
+++ b/tests/game-setup.test.js
@@ -30,20 +30,28 @@ function recipeWith(game) {
test('a minimal setup gets its defaults', () => {
const setup = normalizeGameSetup({ player: { node: 'creature' } }, NODE_IDS);
assert.deepEqual(setup, {
- player: { node: 'creature', controller: 'character', walkSpeed: 3, runSpeed: 6, jumpSpeed: 7, footOffset: 0 },
+ player: { node: 'creature', controller: 'character', walkSpeed: 3, runSpeed: 6, jumpSpeed: 7, maximumSpeed: 20, footOffset: 0 },
camera: 'follow', input: 'keyboard', physics: false, ground: 0,
});
});
+test('a vehicle with a chase camera keeps its top speed', () => {
+ const setup = normalizeGameSetup({ player: { node: 'creature', controller: 'vehicle', maximumSpeed: 30 }, camera: 'chase' }, NODE_IDS);
+ assert.equal(setup.player.controller, 'vehicle');
+ assert.equal(setup.player.maximumSpeed, 30);
+ assert.equal(setup.camera, 'chase');
+});
+
test('each bad field names itself and says what to pass', () => {
const player = { node: 'creature' };
const unknownZone = { version: 1, rules: [{ when: { type: 'enter', zone: 'nowhere', tag: 'player' }, do: [] }] };
const cases = [
[{}, /player must be an object/],
[{ player: { node: 'creatur' } }, /player\.node names "creatur".*Use one of: creature, coin-1/],
- [{ player, camera: 'orbit' }, /camera is "orbit". Use one of: follow, first-person, top-down/],
+ [{ player, camera: 'orbit' }, /camera is "orbit". Use one of: follow, first-person, top-down, chase/],
[{ player, input: 'mouse' }, /input is "mouse". Use one of: keyboard, gamepad, touch/],
- [{ player: { ...player, controller: 'car' } }, /player\.controller is "car". Use one of: character/],
+ [{ player: { ...player, controller: 'car' } }, /player\.controller is "car". Use one of: character, vehicle/],
+ [{ player: { ...player, maximumSpeed: 101 } }, /player\.maximumSpeed must be a number from 0 to 100/],
[{ player: { ...player, walkSpeed: 101 } }, /player\.walkSpeed must be a number from 0 to 100/],
[{ player: { ...player, jumpSpeed: Infinity } }, /player\.jumpSpeed must be a number/],
[{ player, physics: 'yes' }, /physics must be true or false/],
diff --git a/tests/game-start.test.js b/tests/game-start.test.js
index d3965f35..de6a6154 100644
--- a/tests/game-start.test.js
+++ b/tests/game-start.test.js
@@ -66,3 +66,16 @@ test('a start that fails after the renderer exists disposes the renderer and ret
restore();
}
});
+
+test('a vehicle game starts a vehicle controller with a chase camera', async () => {
+ const restore = withAnimationFrameStubs();
+ try {
+ const recipe = gameRecipe();
+ recipe.game = { ...recipe.game, player: { ...recipe.game.player, controller: 'vehicle', maximumSpeed: 30 }, camera: 'chase' };
+ const game = await startGame({}, recipe, { replay: EMPTY_RECORDING, showStatus: false, createRenderer: () => standInRenderer() });
+ assert.equal(typeof game.controller.state.forwardSpeed, 'number');
+ game.dispose();
+ } finally {
+ restore();
+ }
+});