Epsilon Engine Source code

2D and 2.5D games

Use EpsilonGame as the entry point when a project can contain different game presets. It dispatches the six Arcade preset IDs to EpsilonArcade. Each level is data that can be validated, copied and saved. Each playthrough has its own mutable world.

Levels and simulation#

Call Contract
EpsilonGame.defaults(preset, seed?) Returns an authored starting level. The default seed is 1701.
EpsilonGame.level(raw, preset, seed?) Validates and returns a normalized level. A null or undefined level selects the preset default. Wrong schema, duplicate IDs and invalid spawn/exit counts throw.
EpsilonGame.create(raw, preset, seed?) Returns a fresh world. For scrolling games the player position is world.x and world.y. The pipe world keeps a cursor, board pieces and water paths.
EpsilonGame.advance(world, dt, input = {}) Advances in place, returns an array of event strings such as "collect", "hurt" or "win". Pass nonnegative finite seconds. Each call accumulates up to 0.25 s of elapsed time and preserves the sub-tick remainder.
EpsilonGame.campaign(scenes), next(campaign, won) Build a cursor over playable scene IDs in authored order. A win advances it and returns the next ID. The final win sets complete and returns null.
EpsilonArcade.retryCheckpoint(world) After a defeat with a captured flag, returns a new world restored to the flag. Assign that return value to the active run. Otherwise returns null.

The legacy single-screen level schema is epsilon-prime.level/v1 for zelda, mario and dkc editor presets. The extended platform and puzzle worlds use epsilon-prime.arcade/v1 for hubie, hocus, keen, dkc-scroll and metroid. They require one spawn and one exit, support up to 128 objects, and validate coordinates against the world bounds. empipe uses the grid schema epsilon-prime.pipe/v1. Its board has terminals, optional mandatory pass cells, obstacles and pieces. These preset IDs appear in saved projects.

Supply held booleans on each frame. left and right steer. The scrolling controllers read up to jump, and interpret down, action and fire by preset. Rift Station also accepts slide for its latched touch control. Clear held inputs on blur or touch cancellation. If a level reaches a terminal state, later steps return an empty event list.

Editing and drawing#

EpsilonLevelAuthoring.edit(level, preset, operation) validates a copy and returns the new level. World operations include add, move, resize and remove. A pipe board uses cell or terminal operations. Resizing requires an object with width and height. The editor preserves the required spawn and exit.

This example adds a checkpoint and undoes the edit. The original level remains available for another run.

import './src/arcade-core.js';
import './src/level-authoring.js';

const level = globalThis.EpsilonArcade.defaults('metroid');
const editor = globalThis.EpsilonLevelAuthoring;
const history = editor.history();
history.sync('room', level);

const edited = editor.edit(level, 'metroid', {
  kind: 'add', id: 'west-flag', type: 'checkpoint', x: 180, y: 250
});
history.record(level, edited);
const hasFlag = doc => doc.objects.some(object => object.id === 'west-flag');
console.log(hasFlag(edited), hasFlag(history.undo()), history.canRedo);
true false true
Interface When to use it
history(max = 32) sync(key, level) establishes the active document. record(before, after) adds an edit. undo() and redo() return copies or null.
EpsilonLevelAuthoring.hit(level, x, y) On a world level, picks the last matching object in draw order using pixel coordinates and returns its ID or null. For a pipe board, pass integer grid coordinates directly to a cell or terminal edit.
EpsilonArcade.pipePlace(world, x, y, mask), pipeStart(world) Place a pipe in an editable cell or erase with mask 0. Placement returns a boolean. Starting flow mutates the world and advance moves water through it.
EpsilonArcade.supportsDepth(preset) Checks for a 2.5D edition. metroid, dkc-scroll, hocus and keen accept presentation: "2.5d".
EpsilonArcadeDepth.project(x, y, z), faces(x, y, w, h, depth) Return projected points and front/top/side polygons for drawing. The collision face still uses the authored 2D bounds.
EpsilonArcadeFeedback.create(), receive(feedback, events, world, reduced?), step(feedback, dt) Consume simulation events to update notices and particles and return sound motifs. The presentation loop advances their lifetimes separately.

A flag restores items, keys, abilities and cleared obstacles as they stood when reached. The hosted campaign player separately records completed chapters in browser storage. To add a chapter or investigate where a return visit resumes, see the campaign build path.