/*

Raycasting: walk a first-person maze drawn one screen column at a time, with a CRT finish.
@description A Wolfenstein-style raycaster: walk a maze in first person, drawn one vertical line per column.

Part of the BLIT386 demo series.

Prerequisites:
  - Basics: https://demos.blit386.dev/basics
  - Primitives: https://demos.blit386.dev/primitives
  - PipBoy CRT: https://demos.blit386.dev/crt-pipboy

Live version: https://demos.blit386.dev/raycasting

Guides:
  - Input: https://blit386.dev/docs/guides/input#keyboard
  - Post-Process Effects: https://blit386.dev/docs/guides/post-process-effects#display-tier-effects

---

WHAT YOU WILL SEE
-----------------

A first-person view of a small maze, in the style of early 1990s shooters. The top half of
the screen is a slate ceiling, the bottom half a brown floor, and the walls in between come
in three colors: gray stone, red brick, and blue tile. Walls grow dimmer the farther away
they are, and walls facing north or south are a little darker than walls facing east
or west, which is what makes the corners readable.

A minimap in the top-left corner shows the whole maze from above, with you as a yellow dot
and the exit as a green cell. Walk into the exit and "LEVEL CLEAR" appears; two seconds
later you are back at the start.

When WebGPU is active, the finished frame goes through a gentle CRT chain: barrel
curvature, chromatic aberration, a bright band rolling slowly down the screen, scanlines,
an RGB mask, grain, vignette, and bloom.

WHAT YOU WILL LEARN
-------------------

- Raycasting: for each of the 320 screen columns, send one ray from the player into a grid
  map, find the first wall it hits, and draw a vertical line whose height shrinks with the
  distance. 320 lines make the whole 3D-looking picture.
- The DDA grid walk (Digital Differential Analyzer), which steps a ray from one grid line to
  the next, so it never skips a wall and never tests the same cell twice.
- Why the distance has to be "perpendicular" (measured straight out from the camera) rather
  than the true ray length, to avoid a curved fisheye look.
- Distance shading done entirely with palette slots: each wall color is stored eight times,
  from bright to dark, and the renderer just picks a slot.
- BT.getAxis() with AXIS_LEFT_X / AXIS_RIGHT_X to turn and AXIS_LEFT_Y / AXIS_RIGHT_Y to
  walk, so both gamepad sticks steer the same way, mixed with the all-or-nothing keys and
  D-pads and clamped back to full speed.
- Axis-separated collision, which lets the player slide along a wall instead of sticking.
- configure() flags: keyboardLayout 'single' so WASD and the arrows both drive player 0, and
  a drawingBufferSize four times the display size so display-tier effects have room.
- BT.effectClear() to start init() from an empty chain, so a hot reload never stacks a
  second CRT chain on the first.
- BT.effectAdd() / BT.effectRemove() to switch the CRT chain on and off at runtime, and
  onReducedMotionChange() to drop the moving grain and rolling band when the player asks
  for less motion.

HOW DOES THE RAYCASTER WORK?
----------------------------

Picture standing in the maze holding a flashlight that only shines in a thin vertical
slice. Sweep it from the left edge of your view to the right edge, 320 slices in all. Each
slice tells you how far away the wall in that direction is. A close wall fills most of the
screen height; a far one is a short sliver near the horizon. Drawing those slices side by
side gives the illusion of depth, even though the maze itself is just a flat grid of
letters.

TRY THIS
--------

- Walk with W / S or the up and down arrows; turn with A / D or the left and right arrows.
- On a gamepad, use the D-pad or either stick: left and right turns, up and down walks.
  Push a stick a little to go slowly, all the way for full speed.
- On a phone or tablet, hold the D-pad keys in the bottom-right corner, or swipe left or
  right for a quick quarter turn.
- Press C to switch the CRT effects off and on, and R to go back to the start.
- Find the green exit on the minimap and walk into it.
- Add ?backend=software to the URL to see the maze without the CRT chain.

*/

import {
    class BarrelDistortion
Barrel distortion that warps UVs outward from the screen center. Display-tier: operates on the upscaled output. Applying this in the pixel tier (logical 320x240) discretizes the curve onto the source texel grid, which CSS upscale then magnifies into visible step artifacts. At output resolution the curve has enough resolution to express smoothly. The math comes from Timothy Lottes's public-domain `crt-lottes.glsl`: `warp(uv) = uv + delta * d2 * curvature` where `delta = uv - 0.5` and `d2 = dot(delta, delta)`.
@since1.0.3
BarrelDistortion
,
class Bloom
Single-pass box-blur bloom. Samples a 5x5 neighborhood (25 taps) around each fragment, averages, then mixes with the original color by {@link glow } . {@link spread } scales the texel offset so the bloom radius can be tuned independently of the source resolution. Display-tier: bloom mixes neighboring pixels into intermediate hues that are not in the active palette. Running it in pixel space would violate the palette-pixel aesthetic; running it on the upscaled output reads as the warm phosphor glow of an old monitor instead. The implementation matches the original PipBoy bloom shader. A future optimization would be a two-pass separable Gaussian (5 + 5 = 10 taps); add it once a GPU perf test demands it.
@since1.0.3
Bloom
,
function bootstrap(DemoClass: DemoConstructor, options?: BootstrapOptions): Promise<boolean>
One-liner bootstrap function for BLIT386 demos. Handles canvas retrieval and engine initialization. Backend selection (WebGPU or software fallback) is managed internally by BTAPI. This function provides a streamlined way to start a demo with sensible defaults while allowing customization through options.
@since0.2.0@changed1.4.0 Calling `bootstrap()` again while already initialized now routes to a hot swap (via {@link registerHotReload}) when a Vite HMR context is registered, or logs a double-bootstrap guard and returns `false` otherwise - previously it silently started a second, unstoppable `GameLoop`.@changed1.7.0 Exposes `BT` on `window.BT` after bootstrap finishes, gated by {@link BootstrapOptions#exposeGlobal } (default: {@link BT.isDevMode}). It is exposed on every path, a failed boot included, so the console can still inspect the engine; a harness that waits for a running game should poll `window.BT?.isReady`, not the presence of `window.BT`.@changed1.9.0 An `onSuccess` callback that throws is logged and no longer replaces the running game with an error panel, fires `onError`, or makes `bootstrap()` resolve `false`.@paramDemoClass - Demo class constructor implementing `IBTDemo` (optional `configure()` for hardware settings).@paramoptions - Optional configuration for IDs and callbacks.@returns`true` when the demo boots successfully; otherwise `false`.@example// Simplest usage - uses default IDs. bootstrap(MyDemo);@example// With custom options. bootstrap(MyDemo, { canvasID: 'custom-canvas', containerID: 'custom-container', onSuccess: () => console.log('Demo started!'), onError: (err) => analytics.trackError(err), });@example// Await the result. const success = await bootstrap(MyDemo); if (success) { console.log('Demo is running'); }
bootstrap
,
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
,
class ChromaticAberration
RGB channel offset that simulates lens chromatic aberration: red samples left of the fragment, blue samples right, green stays centered. Display-tier: spreads color along the lens axis. At logical resolution the single-pixel offset is too coarse and reads as a glitch instead of a soft fringe.
@since1.0.3
ChromaticAberration
,
class Color32
Mutable 32-bit RGBA color value with 8-bit channels.
@since0.1.0@changed1.9.0 `toUint32()` returns an unsigned value; colors with alpha 128 or more used to come back negative.
Color32
,
class Noise
Additive per-pixel pseudo-random noise. Reseeds each frame from {@link time } so the noise pattern animates. Display-tier.
@since1.0.3
Noise
,
class Rect2i
Integer rectangle for pixel-perfect bounds and regions. Used throughout the engine for sprite regions, display-space bounds, and zero-allocation geometry helpers. Both convenience getters and allocation-free `*To()` helpers are provided so callers can choose between readability and hot-path efficiency.
@since0.1.0
Rect2i
,
class RGBMask
CRT shadow mask: per-pixel R/G/B vertical-stripe pattern with darkened cell borders, simulating the phosphor grille of an aperture-grille CRT. Display-tier: at output resolution there are enough output pixels per mask cell to read as colored stripes. The cell pitch (in output pixels) is the {@link size } parameter. Math is a direct WGSL port of the libretro `crt-lottes.glsl` mask code.
@since1.0.3
RGBMask
,
class RollLine
Slowly scrolling vertical interference band that brightens a horizontal stripe of the image. Combination of three cosines + smoothstep gives the stripe a soft top/bottom edge. Display-tier. Demo drives {@link time } (typically `BT.ticks / BT.targetFPS`).
@since1.0.3
RollLine
,
class Scanlines
CRT scanlines: alternating bright/dark horizontal bands aligned to the source vertical resolution. Display-tier: at output resolution there is enough vertical pixels for scanlines to read as alternating bright/dark bands. At logical 320x240 the Gaussian weight quantizes to one of two values per source row and you lose the smooth fade.
@since1.0.3
Scanlines
,
class Vector2i
Integer 2D vector for pixel-perfect positioning. Used for points, sizes, directions, and camera offsets throughout the engine. The API includes both allocation-free `*To()` / `*InPlace()` variants and convenience methods that return new vectors.
@since0.1.0@changed1.9.0 `normalized()` of a zero vector returns a new mutable vector instead of the frozen `Vector2i.zero()`.
Vector2i
,
class Vignette
Edge-darkening vignette: smooth radial fade from full brightness at the center to black at the corners. Display-tier: applies to the whole simulated screen, not the underlying pixel art.
@since1.0.3
Vignette
,
} from 'blit386'; import { import isAvailableisAvailable } from './shared/post-process-backend.js'; import { import applyThemeapplyTheme, import uiui, import UI_DIRECTIONSUI_DIRECTIONS } from './shared/ui.js'; /** @typedef {import('blit386').Palette} Palette */ /** @typedef {import('blit386').Effect} Effect */ // The game draws into a 320x240 picture. const const SCREEN_W: 320SCREEN_W = 320; const const SCREEN_H: 240SCREEN_H = 240; // Palette slots for the scene. Slot 0 is reserved as transparent, so colors start at 1. const const COLOR_CEILING: 1COLOR_CEILING = 1; const const COLOR_FLOOR: 2COLOR_FLOOR = 2; const const COLOR_MAP_WALL: 3COLOR_MAP_WALL = 3; const const COLOR_MAP_FLOOR: 4COLOR_MAP_FLOOR = 4; const const COLOR_MAP_PLAYER: 5COLOR_MAP_PLAYER = 5; const const COLOR_MAP_EXIT: 6COLOR_MAP_EXIT = 6; // The walls use a block of 3 kinds x 2 sides x 8 distance shades = 48 slots, starting // here. const const WALL_BASE: 16WALL_BASE = 16; const const SHADES: 8SHADES = 8; // The map letters that mean a wall, in the same order as WALL_COLORS below. Any other // wall letter (such as '#') falls back to the first color. const const WALL_KINDS: "#AB"WALL_KINDS = '#AB'; const const WALL_COLORS: {}WALL_COLORS = [new new Color32(r?: number, g?: number, b?: number, a?: number): Color32
Creates a clamped 8-bit RGBA color.
@paramr - Red channel (0-255, defaults to 255).@paramg - Green channel (0-255, defaults to 255).@paramb - Blue channel (0-255, defaults to 255).@parama - Alpha channel (0-255, defaults to 255 = opaque).
Color32
(215, 215, 225), new new Color32(r?: number, g?: number, b?: number, a?: number): Color32
Creates a clamped 8-bit RGBA color.
@paramr - Red channel (0-255, defaults to 255).@paramg - Green channel (0-255, defaults to 255).@paramb - Blue channel (0-255, defaults to 255).@parama - Alpha channel (0-255, defaults to 255 = opaque).
Color32
(235, 100, 80), new new Color32(r?: number, g?: number, b?: number, a?: number): Color32
Creates a clamped 8-bit RGBA color.
@paramr - Red channel (0-255, defaults to 255).@paramg - Green channel (0-255, defaults to 255).@paramb - Blue channel (0-255, defaults to 255).@parama - Alpha channel (0-255, defaults to 255 = opaque).
Color32
(90, 135, 245)];
// How much of a wall's brightness the far distance bands lose: 0 would be no fading at // all, 1 would fade all the way to black. const const WALL_FADE: 0.65WALL_FADE = 0.65; // The maze, drawn as text: one string per row, one letter per cell. '#', 'A', and 'B' are // walls of different colors, '.' is floor, 'P' is where the player starts, and 'X' is the // exit. The outer ring is all wall, so a ray can never leave the map. const const MAP: {}MAP = [ '################', '#P.....#.......#', '#.###..#.A..B..#', '#.#A#..#.A..B..#', '#.#.#..#.......#', '#.#.......BBB..#', '#.#.####.......#', '#......#.AAAA..#', '#.####.#.......#', '#.#....#.###...#', '#.#.##.#...#.B.#', '#.#..#.######..#', '#.#..#......#..#', '#.##.####.#.#..#', '#....A....#...X#', '################', ]; // The letters a player can stand on. Everything else in MAP is solid. const const FLOOR_CELLS: ".XP"FLOOR_CELLS = '.XP'; const const CELL_EXIT: "X"CELL_EXIT = 'X'; const const CELL_SPAWN: "P"CELL_SPAWN = 'P'; // Minimap size and position: each map cell becomes a 3x3 pixel square. const const MAP_CELL: 3MAP_CELL = 3; const const MAP_ORIGIN: Vector2iMAP_ORIGIN = new new Vector2i(x?: number, y?: number): Vector2i
Creates an integer 2D vector, truncating inputs toward zero.
@paramx - Horizontal component (defaults to 0).@paramy - Vertical component (defaults to 0).
Vector2i
(4, 4);
// How fast the player moves, in map cells per tick (60 ticks make one second), and how // fast they turn, in radians per tick (a full circle is about 6.28 radians). const const MOVE_SPEED: 0.05MOVE_SPEED = 0.05; const const TURN_SPEED: 0.04TURN_SPEED = 0.04; // A quick quarter turn for a swipe: a quarter of a full circle. const const QUARTER_TURN: numberQUARTER_TURN = Math.PI / 2; // How close the player may get to a wall, in cells, so the camera never pokes through it. const const PLAYER_RADIUS: 0.2PLAYER_RADIUS = 0.2; // Half the width of the camera "window" in front of the player. 0.66 gives about 66 // degrees of view, the classic value. const const FOV_PLANE: 0.66FOV_PLANE = 0.66; // How long "LEVEL CLEAR" stays on screen before the player goes back to the start. const const CLEAR_TICKS: 120CLEAR_TICKS = 120; // The rolling band's brightness (0 is invisible) and how fast it scrolls down the screen. const const ROLL_AMOUNT: 0.26ROLL_AMOUNT = 0.26; const const ROLL_SPEED: 0.92ROLL_SPEED = 0.92; // Is the map cell under the point (x, y) solid? Positions are in cells and can have // fractions: (2.5, 3.7) is inside the cell at column 2, row 3. Math.floor() cuts off the // fraction to find that cell. A point outside the map counts as wall, which is what stops // a runaway ray. function function isWall(x: any, y: any): booleanisWall(x: anyx, y: anyy) { const const row: anyrow = const MAP: {}MAP[Math.floor(y: anyy)]; const const cell: anycell = const row: anyrow?.[Math.floor(x: anyx)]; return const cell: anycell === var undefinedundefined || !const FLOOR_CELLS: ".XP"FLOOR_CELLS.includes(const cell: anycell); } // Casts one ray from the player at (px, py) in the direction (dx, dy) and writes what it // hit into `hit`: the distance to the wall, which side of the cell it struck (0 for an // east or west face, 1 for a north or south face), and the wall's map letter. Reusing the // same `hit` box for all 320 rays means no new objects are made every frame. function function castRay(px: any, py: any, dx: any, dy: any, hit: any): voidcastRay(px: anypx, py: anypy, dx: anydx, dy: anydy, hit: anyhit) { // The cell the ray starts in. let let mapX: anymapX = Math.floor(px: anypx); let let mapY: anymapY = Math.floor(py: anypy); // How far the ray has to travel to cross one whole cell sideways (deltaX) or one // whole cell up or down (deltaY). A ray going nearly straight up crosses vertical // grid lines very rarely, so its deltaX is huge. Math.abs() makes a number positive. // A direction of exactly 0 never crosses those lines at all, so it gets Infinity. const const deltaX: anydeltaX = dx: anydx === 0 ? Infinity : Math.abs(1 / dx: anydx); const const deltaY: anydeltaY = dy: anydy === 0 ? Infinity : Math.abs(1 / dy: anydy); // Which way to step through the grid: -1 for left or up, +1 for right or down. const const stepX: 1 | -1stepX = dx: anydx < 0 ? -1 : 1; const const stepY: 1 | -1stepY = dy: anydy < 0 ? -1 : 1; // How far the ray travels before it reaches the first vertical grid line (sideX) and // the first horizontal one (sideY). The player usually stands somewhere inside a // cell, so this first stretch is shorter than a full delta. let let sideX: numbersideX = dx: anydx < 0 ? (px: anypx - let mapX: anymapX) * const deltaX: anydeltaX : (let mapX: anymapX + 1 - px: anypx) * const deltaX: anydeltaX; let let sideY: numbersideY = dy: anydy < 0 ? (py: anypy - let mapY: anymapY) * const deltaY: anydeltaY : (let mapY: anymapY + 1 - py: anypy) * const deltaY: anydeltaY; let let side: numberside = 0; // The DDA walk: always step across whichever grid line is closer, one cell at a time, // until the cell we land in is a wall. Like walking a checkerboard and always taking // the nearer edge, so no square is ever skipped. The solid outer ring of MAP (and // isWall() treating "outside" as wall) guarantees this loop ends. while (!function isWall(x: any, y: any): booleanisWall(let mapX: anymapX, let mapY: anymapY)) { if (let sideX: numbersideX < let sideY: numbersideY) { let sideX: numbersideX += const deltaX: anydeltaX; let mapX: anymapX += const stepX: 1 | -1stepX; let side: numberside = 0; } else { let sideY: numbersideY += const deltaY: anydeltaY; let mapY: anymapY += const stepY: 1 | -1stepY; let side: numberside = 1; } } // We went one delta past the wall face, so step back one to get the distance to the // face itself. Because the ray direction includes the camera plane, this is already // the perpendicular distance: measured straight out from the camera, not along the // slanted ray. The slanted length would make flat walls bulge like a fisheye lens. hit: anyhit.dist = let side: numberside === 0 ? let sideX: numbersideX - const deltaX: anydeltaX : let sideY: numbersideY - const deltaY: anydeltaY; hit: anyhit.side = let side: numberside; hit: anyhit.cell = const MAP: {}MAP[let mapY: anymapY]?.[let mapX: anymapX] ?? '#'; } // Finds the 'P' cell and returns its center. indexOf() returns the position of a letter // in a string, or -1 if it is not there. Adding 0.5 puts the player in the middle of the // cell rather than on its corner. function
function findSpawn(): {
    x: any;
    y: number;
}
findSpawn
() {
for (let let y: numbery = 0; let y: numbery < const MAP: {}MAP.length; let y: numbery++) { const const x: anyx = const MAP: {}MAP[let y: numbery].indexOf(const CELL_SPAWN: "P"CELL_SPAWN); if (const x: anyx >= 0) { return { x: anyx: const x: anyx + 0.5, y: numbery: let y: numbery + 0.5 }; } } throw new Error('MAP has no P spawn cell'); } // Builds a gentler CRT chain than the PipBoy CRT demo uses: its interference tears thin // wall columns apart. Order matters: curvature goes first so everything else bends with // it, and bloom goes last so its glow spreads over the RGB mask. function function buildCrt(): {}buildCrt() { const const curve: BarrelDistortioncurve = new new BarrelDistortion(): BarrelDistortion
Barrel distortion that warps UVs outward from the screen center. Display-tier: operates on the upscaled output. Applying this in the pixel tier (logical 320x240) discretizes the curve onto the source texel grid, which CSS upscale then magnifies into visible step artifacts. At output resolution the curve has enough resolution to express smoothly. The math comes from Timothy Lottes's public-domain `crt-lottes.glsl`: `warp(uv) = uv + delta * d2 * curvature` where `delta = uv - 0.5` and `d2 = dot(delta, delta)`.
@since1.0.3
BarrelDistortion
();
const curve: BarrelDistortioncurve.BarrelDistortion.curvature: number
Curvature strength. Typical values: - `0.02` - subtle, like a flat-screen monitor. - `0.05` - moderate desktop CRT. - `0.10` - heavy small CRT or pocket TV.
curvature
= 0.04;
const const fringe: ChromaticAberrationfringe = new new ChromaticAberration(): ChromaticAberration
RGB channel offset that simulates lens chromatic aberration: red samples left of the fragment, blue samples right, green stays centered. Display-tier: spreads color along the lens axis. At logical resolution the single-pixel offset is too coarse and reads as a glitch instead of a soft fringe.
@since1.0.3
ChromaticAberration
();
const fringe: ChromaticAberrationfringe.ChromaticAberration.aberration: number
Channel offset in display-chain (output) pixels. Reasonable values are `0.5` to `3.0`. Set to `0` to disable.
aberration
= 0.6;
// A soft bright band that slowly scrolls from top to bottom, like an old TV whose // picture is not quite in sync. Same settings as the Sprite Effects demo. const const roll: RollLineroll = new new RollLine(): RollLine
Slowly scrolling vertical interference band that brightens a horizontal stripe of the image. Combination of three cosines + smoothstep gives the stripe a soft top/bottom edge. Display-tier. Demo drives {@link time } (typically `BT.ticks / BT.targetFPS`).
@since1.0.3
RollLine
();
const roll: RollLineroll.RollLine.amount: number
Roll line amplitude (mix factor onto a brightness boost).
amount
= const ROLL_AMOUNT: 0.26ROLL_AMOUNT;
const roll: RollLineroll.RollLine.speed: number
Scroll speed multiplier; final scroll velocity = `time * speed`.
speed
= const ROLL_SPEED: 0.92ROLL_SPEED;
const const lines: Scanlineslines = new new Scanlines(): Scanlines
CRT scanlines: alternating bright/dark horizontal bands aligned to the source vertical resolution. Display-tier: at output resolution there is enough vertical pixels for scanlines to read as alternating bright/dark bands. At logical 320x240 the Gaussian weight quantizes to one of two values per source row and you lose the smooth fade.
@since1.0.3
Scanlines
();
const lines: Scanlineslines.Scanlines.amount: number
Scanline mix amount in `[0, 1]`. 0 disables.
amount
= 0.3;
const lines: Scanlineslines.Scanlines.strength: number
Negative gaussian falloff parameter for scanline brightness. More negative values produce sharper dark bands. PipBoy reference: `-8.0`.
strength
= -7;
const const mask: RGBMaskmask = new new RGBMask(): RGBMask
CRT shadow mask: per-pixel R/G/B vertical-stripe pattern with darkened cell borders, simulating the phosphor grille of an aperture-grille CRT. Display-tier: at output resolution there are enough output pixels per mask cell to read as colored stripes. The cell pitch (in output pixels) is the {@link size } parameter. Math is a direct WGSL port of the libretro `crt-lottes.glsl` mask code.
@since1.0.3
RGBMask
();
const mask: RGBMaskmask.RGBMask.intensity: number
Mask brightness mix amount in `[0, 1]`. 0 hides the mask.
intensity
= 0.12;
const mask: RGBMaskmask.RGBMask.size: number
Mask cell pitch in output (display-chain) pixels. Smaller = denser mask.
size
= 6;
const mask: RGBMaskmask.RGBMask.border: number
Border darkening within each mask cell. 0 disables, 1 strong.
border
= 0.4;
const const grain: Noisegrain = new new Noise(): Noise
Additive per-pixel pseudo-random noise. Reseeds each frame from {@link time } so the noise pattern animates. Display-tier.
@since1.0.3
Noise
();
const grain: Noisegrain.Noise.amount: number
Noise amplitude as a `[-amount, +amount]` additive perturbation on each channel. Reasonable values are `0.005` to `0.05`. Set to `0` to disable.
amount
= 0.015;
const const edges: Vignetteedges = new new Vignette(): Vignette
Edge-darkening vignette: smooth radial fade from full brightness at the center to black at the corners. Display-tier: applies to the whole simulated screen, not the underlying pixel art.
@since1.0.3
Vignette
();
const edges: Vignetteedges.Vignette.amount: number
Vignette darkening exponent. Higher values produce a stronger vignette with a sharper falloff. PipBoy reference: `0.2`. Set to `0` to disable.
amount
= 0.15;
const const glow: Bloomglow = new new Bloom(): Bloom
Single-pass box-blur bloom. Samples a 5x5 neighborhood (25 taps) around each fragment, averages, then mixes with the original color by {@link glow } . {@link spread } scales the texel offset so the bloom radius can be tuned independently of the source resolution. Display-tier: bloom mixes neighboring pixels into intermediate hues that are not in the active palette. Running it in pixel space would violate the palette-pixel aesthetic; running it on the upscaled output reads as the warm phosphor glow of an old monitor instead. The implementation matches the original PipBoy bloom shader. A future optimization would be a two-pass separable Gaussian (5 + 5 = 10 taps); add it once a GPU perf test demands it.
@since1.0.3
Bloom
();
const glow: Bloomglow.Bloom.spread: number
Texel offset multiplier for the box-blur kernel.
spread
= 2.5;
const glow: Bloomglow.Bloom.glow: number
Mix factor between the original sample and the blurred neighborhood.
glow
= 0.15;
return [const curve: BarrelDistortioncurve, const fringe: ChromaticAberrationfringe, const roll: RollLineroll, const lines: Scanlineslines, const mask: RGBMaskmask, const grain: Noisegrain, const edges: Vignetteedges, const glow: Bloomglow]; } // Which palette slot holds a wall color: `kind` picks the color (0-2), `side` the // brightness of the face (0 or 1), and `shade` how far away it is (0 bright to 7 dark). // The slots sit in one tidy block, like rows and columns in a table. function function wallSlot(kind: any, side: any, shade: any): anywallSlot(kind: anykind, side: anyside, shade: anyshade) { return const WALL_BASE: 16WALL_BASE + kind: anykind * const SHADES: 8SHADES * 2 + side: anyside * const SHADES: 8SHADES + shade: anyshade; } // A first-person maze. update() reads the controls and moves the player through the grid; // render() casts one ray per screen column and draws the minimap. class class DemoDemo { /** @type {Palette | null} */ Demo.palette: Palette | null
@type{Palette | null}
palette
= null;
// The player's position in map cells, and the direction they face in radians. Angle 0 // looks right along the map; the angle grows clockwise on screen. Demo.x: numberx = 0; Demo.y: numbery = 0; Demo.angle: numberangle = 0; // True while "LEVEL CLEAR" is showing, and how many ticks are left before the // respawn. Demo.levelClear: booleanlevelClear = false; Demo.clearTimer: numberclearTimer = 0; // True when WebGPU is running, so the CRT chain can be used at all. Demo.effectsAvailable: booleaneffectsAvailable = false; // Whether the player wants the CRT chain on. The C key flips it. Demo.crtOn: booleancrtOn = true; // The CRT effects, built once in init() when WebGPU is available. /** @type {Effect[]} */ Demo.crt: {}
@type{Effect[]}
crt
= [];
// Scratch objects reused every frame so render() makes no new objects (no "litter" // for the browser to clean up later).
Demo.hit: {
    dist: number;
    side: number;
    cell: string;
}
hit
= { dist: numberdist: 0, side: numberside: 0, cell: stringcell: '#' };
Demo.lineTop: Vector2ilineTop = new new Vector2i(x?: number, y?: number): Vector2i
Creates an integer 2D vector, truncating inputs toward zero.
@paramx - Horizontal component (defaults to 0).@paramy - Vertical component (defaults to 0).
Vector2i
(0, 0);
Demo.lineBottom: Vector2ilineBottom = new new Vector2i(x?: number, y?: number): Vector2i
Creates an integer 2D vector, truncating inputs toward zero.
@paramx - Horizontal component (defaults to 0).@paramy - Vertical component (defaults to 0).
Vector2i
(0, 0);
Demo.rect: Rect2irect = new new Rect2i(x?: number, y?: number, width?: number, height?: number): Rect2i
Creates an integer rectangle, truncating all inputs toward zero.
@paramx - Left-edge X coordinate (defaults to 0).@paramy - Top-edge Y coordinate (defaults to 0).@paramwidth - Width in pixels (defaults to 0).@paramheight - Height in pixels (defaults to 0).
Rect2i
(0, 0, 0, 0);
// Engine settings, read once before init(): the small screen, the bigger drawing // buffer the CRT effects need, and the one-player keyboard layout.
Demo.configure(): {
    displaySize: Vector2i;
    drawingBufferSize: Vector2i;
    keyboardLayout: string;
}
configure
() {
return { displaySize: Vector2idisplaySize: new new Vector2i(x?: number, y?: number): Vector2i
Creates an integer 2D vector, truncating inputs toward zero.
@paramx - Horizontal component (defaults to 0).@paramy - Vertical component (defaults to 0).
Vector2i
(const SCREEN_W: 320SCREEN_W, const SCREEN_H: 240SCREEN_H),
// The CRT effects run on the final, upscaled picture. Giving them four times // as many pixels lets scanlines and the RGB mask look smooth instead of // blocky. drawingBufferSize: Vector2idrawingBufferSize: new new Vector2i(x?: number, y?: number): Vector2i
Creates an integer 2D vector, truncating inputs toward zero.
@paramx - Horizontal component (defaults to 0).@paramy - Vertical component (defaults to 0).
Vector2i
(const SCREEN_W: 320SCREEN_W * 4, const SCREEN_H: 240SCREEN_H * 4),
// 'single' maps both WASD and the arrow keys to player 0, so either hand // works. It also stops the arrow keys from scrolling the page while you // walk. keyboardLayout: stringkeyboardLayout: 'single', }; } // Runs once at start: builds the palette (scene colors, the shaded wall ramps, the // kit theme), sets up the CRT chain when WebGPU is active, and places the player. async Demo.init(): unknowninit() { this.Demo.palette: Palette | null
@type{Palette | null}
palette
=
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.paletteCreate: (size?: number) => Palette
Creates a standalone palette instance.
@since1.0.3@paramsize - Palette size. Defaults to 256 colors.@returnsNew mutable palette.
paletteCreate
(256);
// Scene colors: ceiling, floor, and the four minimap colors. this.Demo.palette: Palette
@type{Palette | null}
palette
.Palette.set(index: number, color: Color32): void
Writes a color into a palette slot. The values are copied into the slot's existing color, so a reference from {@link getRef } stays valid.
@changed1.9.0 Copies into the slot's existing color instead of replacing it, so references from `getRef` stay linked to the palette.@paramindex - Palette index to overwrite.@paramcolor - Color to store.@throwsError if the index is invalid or if index `0` is set opaque.
set
(const COLOR_CEILING: 1COLOR_CEILING, new new Color32(r?: number, g?: number, b?: number, a?: number): Color32
Creates a clamped 8-bit RGBA color.
@paramr - Red channel (0-255, defaults to 255).@paramg - Green channel (0-255, defaults to 255).@paramb - Blue channel (0-255, defaults to 255).@parama - Alpha channel (0-255, defaults to 255 = opaque).
Color32
(75, 80, 100));
this.Demo.palette: Palette
@type{Palette | null}
palette
.Palette.set(index: number, color: Color32): void
Writes a color into a palette slot. The values are copied into the slot's existing color, so a reference from {@link getRef } stays valid.
@changed1.9.0 Copies into the slot's existing color instead of replacing it, so references from `getRef` stay linked to the palette.@paramindex - Palette index to overwrite.@paramcolor - Color to store.@throwsError if the index is invalid or if index `0` is set opaque.
set
(const COLOR_FLOOR: 2COLOR_FLOOR, new new Color32(r?: number, g?: number, b?: number, a?: number): Color32
Creates a clamped 8-bit RGBA color.
@paramr - Red channel (0-255, defaults to 255).@paramg - Green channel (0-255, defaults to 255).@paramb - Blue channel (0-255, defaults to 255).@parama - Alpha channel (0-255, defaults to 255 = opaque).
Color32
(125, 110, 92));
this.Demo.palette: Palette
@type{Palette | null}
palette
.Palette.set(index: number, color: Color32): void
Writes a color into a palette slot. The values are copied into the slot's existing color, so a reference from {@link getRef } stays valid.
@changed1.9.0 Copies into the slot's existing color instead of replacing it, so references from `getRef` stay linked to the palette.@paramindex - Palette index to overwrite.@paramcolor - Color to store.@throwsError if the index is invalid or if index `0` is set opaque.
set
(const COLOR_MAP_WALL: 3COLOR_MAP_WALL, new new Color32(r?: number, g?: number, b?: number, a?: number): Color32
Creates a clamped 8-bit RGBA color.
@paramr - Red channel (0-255, defaults to 255).@paramg - Green channel (0-255, defaults to 255).@paramb - Blue channel (0-255, defaults to 255).@parama - Alpha channel (0-255, defaults to 255 = opaque).
Color32
(220, 220, 230));
this.Demo.palette: Palette
@type{Palette | null}
palette
.Palette.set(index: number, color: Color32): void
Writes a color into a palette slot. The values are copied into the slot's existing color, so a reference from {@link getRef } stays valid.
@changed1.9.0 Copies into the slot's existing color instead of replacing it, so references from `getRef` stay linked to the palette.@paramindex - Palette index to overwrite.@paramcolor - Color to store.@throwsError if the index is invalid or if index `0` is set opaque.
set
(const COLOR_MAP_FLOOR: 4COLOR_MAP_FLOOR, new new Color32(r?: number, g?: number, b?: number, a?: number): Color32
Creates a clamped 8-bit RGBA color.
@paramr - Red channel (0-255, defaults to 255).@paramg - Green channel (0-255, defaults to 255).@paramb - Blue channel (0-255, defaults to 255).@parama - Alpha channel (0-255, defaults to 255 = opaque).
Color32
(45, 45, 55));
this.Demo.palette: Palette
@type{Palette | null}
palette
.Palette.set(index: number, color: Color32): void
Writes a color into a palette slot. The values are copied into the slot's existing color, so a reference from {@link getRef } stays valid.
@changed1.9.0 Copies into the slot's existing color instead of replacing it, so references from `getRef` stay linked to the palette.@paramindex - Palette index to overwrite.@paramcolor - Color to store.@throwsError if the index is invalid or if index `0` is set opaque.
set
(const COLOR_MAP_PLAYER: 5COLOR_MAP_PLAYER, new new Color32(r?: number, g?: number, b?: number, a?: number): Color32
Creates a clamped 8-bit RGBA color.
@paramr - Red channel (0-255, defaults to 255).@paramg - Green channel (0-255, defaults to 255).@paramb - Blue channel (0-255, defaults to 255).@parama - Alpha channel (0-255, defaults to 255 = opaque).
Color32
(255, 220, 60));
this.Demo.palette: Palette
@type{Palette | null}
palette
.Palette.set(index: number, color: Color32): void
Writes a color into a palette slot. The values are copied into the slot's existing color, so a reference from {@link getRef } stays valid.
@changed1.9.0 Copies into the slot's existing color instead of replacing it, so references from `getRef` stay linked to the palette.@paramindex - Palette index to overwrite.@paramcolor - Color to store.@throwsError if the index is invalid or if index `0` is set opaque.
set
(const COLOR_MAP_EXIT: 6COLOR_MAP_EXIT, new new Color32(r?: number, g?: number, b?: number, a?: number): Color32
Creates a clamped 8-bit RGBA color.
@paramr - Red channel (0-255, defaults to 255).@paramg - Green channel (0-255, defaults to 255).@paramb - Blue channel (0-255, defaults to 255).@parama - Alpha channel (0-255, defaults to 255 = opaque).
Color32
(60, 220, 90));
// Each wall color is stored 16 times: two faces (the north and south faces at 80 // percent brightness) times eight distance bands that fade toward a dim version // of the color. `k` is the brightness multiplier, from 1 for a close, bright face // down to about 0.43 for the farthest band, so distant walls stay readable. // forEach() runs the code once for each color in the list, with its position. const WALL_COLORS: {}WALL_COLORS.forEach((base: anybase, kind: anykind) => { for (let let side: numberside = 0; let side: numberside < 2; let side: numberside++) { for (let let shade: numbershade = 0; let shade: numbershade < const SHADES: 8SHADES; let shade: numbershade++) { const const k: numberk = (let side: numberside === 0 ? 1 : 0.8) * (1 - (let shade: numbershade / const SHADES: 8SHADES) * const WALL_FADE: 0.65WALL_FADE); this.Demo.palette: Palette | null
@type{Palette | null}
palette
.Palette.set(index: number, color: Color32): void
Writes a color into a palette slot. The values are copied into the slot's existing color, so a reference from {@link getRef } stays valid.
@changed1.9.0 Copies into the slot's existing color instead of replacing it, so references from `getRef` stay linked to the palette.@paramindex - Palette index to overwrite.@paramcolor - Color to store.@throwsError if the index is invalid or if index `0` is set opaque.
set
(
function wallSlot(kind: any, side: any, shade: any): anywallSlot(kind: anykind, let side: numberside, let shade: numbershade), new new Color32(r?: number, g?: number, b?: number, a?: number): Color32
Creates a clamped 8-bit RGBA color.
@paramr - Red channel (0-255, defaults to 255).@paramg - Green channel (0-255, defaults to 255).@paramb - Blue channel (0-255, defaults to 255).@parama - Alpha channel (0-255, defaults to 255 = opaque).
Color32
(Math.floor(base: anybase.r * const k: numberk), Math.floor(base: anybase.g * const k: numberk), Math.floor(base: anybase.b * const k: numberk)),
); } } }); // The shared UI kit draws the touch D-pad and the "LEVEL CLEAR" caption, and // needs its colors in the palette. They go into slots 240 and up, far from the // scene. import applyThemeapplyTheme(this.Demo.palette: Palette
@type{Palette | null}
palette
);
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.paletteSet: (palette: Palette) => void
Stores the active engine palette. Use this to swap the **entire palette** (e.g. switch between a day and night theme). After this call the renderer uploads the new palette uniform on the next frame. **Palette-value swap (change what a slot looks like):** mutate the live {@link BT.palette } in place with `palette.set(slot, newColor)`. The renderer uploads dirty slots on the next frame; no `paletteSet()` or {@link BT.spritesRefresh } needed. **Palette-layout swap (same colors, different slot positions):** build a new palette with the same colors at new indices, call `paletteSet()`, then call {@link BT.spritesRefresh } so every sprite sheet re-maps its original RGBA pixels against the new slot layout.
@since1.0.3@parampalette - Palette to make active.
paletteSet
(this.Demo.palette: Palette
@type{Palette | null}
palette
);
// Post-process effects only exist on WebGPU. In the Canvas 2D fallback the maze // still works; it just has no CRT look. this.Demo.effectsAvailable: booleaneffectsAvailable = import isAvailableisAvailable(); if (this.Demo.effectsAvailable: booleaneffectsAvailable) { // Start from an empty chain. During development the engine re-runs init() // when this file is edited, and without this the new CRT chain would be // stacked on top of the old one, which the C toggle would then never remove.
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.effectClear: () => void
Removes every registered post-processing effect across both tiers. When the engine is not ready, or the effect call fails, reports the error once (a panel in dev builds, the console in release) instead of throwing; the game keeps running.
@since1.0.3
effectClear
();
this.Demo.crt: {}
@type{Effect[]}
crt
= function buildCrt(): {}buildCrt();
this.Demo.applyEffects(): voidapplyEffects(); } this.Demo.respawn(): voidrespawn(); return true; } // Runs every tick: handles the C and R shortcuts, reads the keys, sticks, D-pad and // swipes, turns and moves the player through the maze, and checks for the exit. Demo.update(): voidupdate() { // First line: lets the kit latch key presses, touches, swipes, and the D-pad. import uiui.tick(); this.Demo.handleShortcuts(): voidhandleShortcuts(); // While "LEVEL CLEAR" is showing, the player cannot move. Count down, then // restart. if (this.Demo.levelClear: booleanlevelClear) { this.Demo.clearTimer: numberclearTimer -= 1; if (this.Demo.clearTimer: numberclearTimer <= 0) { this.Demo.respawn(): voidrespawn(); } return; } // How hard the player wants to turn and walk, each from -1 to +1. On a gamepad // both sticks work the same way: left and right turns, up and down walks. // BT.getAxis() returns 0 when a stick rests in the middle and up to 1 when it is // pushed all the way, with in-between values for a gentle push. The two sticks // are added together. Stick Y is negative when pushed up, so we flip it to make // "up" mean forward. let let turn: numberturn =
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.getAxis: (axis: number, player?: number) => number
Reads a gamepad axis value for a player. Stick axes return values in `[-1.0, 1.0]` with dead-zone filtering. Trigger axes return values in `[0.0, 1.0]`.
@since1.0.3@paramaxis - Axis constant (`AXIS_LEFT_X` .. `AXIS_TRIGGER_R`).@paramplayer - Zero-based player index (`0`..`3`).@returnsAxis value, or `0` when unavailable.
getAxis
(
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.type AXIS_LEFT_X: number
Left stick horizontal axis index.
@since1.0.3
AXIS_LEFT_X
, 0) +
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.getAxis: (axis: number, player?: number) => number
Reads a gamepad axis value for a player. Stick axes return values in `[-1.0, 1.0]` with dead-zone filtering. Trigger axes return values in `[0.0, 1.0]`.
@since1.0.3@paramaxis - Axis constant (`AXIS_LEFT_X` .. `AXIS_TRIGGER_R`).@paramplayer - Zero-based player index (`0`..`3`).@returnsAxis value, or `0` when unavailable.
getAxis
(
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.type AXIS_RIGHT_X: number
Right stick horizontal axis index.
@since1.0.3
AXIS_RIGHT_X
, 0);
let let walk: numberwalk = -(
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.getAxis: (axis: number, player?: number) => number
Reads a gamepad axis value for a player. Stick axes return values in `[-1.0, 1.0]` with dead-zone filtering. Trigger axes return values in `[0.0, 1.0]`.
@since1.0.3@paramaxis - Axis constant (`AXIS_LEFT_X` .. `AXIS_TRIGGER_R`).@paramplayer - Zero-based player index (`0`..`3`).@returnsAxis value, or `0` when unavailable.
getAxis
(
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.type AXIS_LEFT_Y: number
Left stick vertical axis index.
@since1.0.3
AXIS_LEFT_Y
, 0) +
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.getAxis: (axis: number, player?: number) => number
Reads a gamepad axis value for a player. Stick axes return values in `[-1.0, 1.0]` with dead-zone filtering. Trigger axes return values in `[0.0, 1.0]`.
@since1.0.3@paramaxis - Axis constant (`AXIS_LEFT_X` .. `AXIS_TRIGGER_R`).@paramplayer - Zero-based player index (`0`..`3`).@returnsAxis value, or `0` when unavailable.
getAxis
(
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.type AXIS_RIGHT_Y: number
Right stick vertical axis index.
@since1.0.3
AXIS_RIGHT_Y
, 0));
// Keys, the gamepad D-pad, and the on-screen touch D-pad are all-or-nothing: held // means full speed. BT.isDown() is true every tick a key or gamepad button is // held (it reads both at once), and ui.dpad.isDown() does the same for the touch // D-pad. if (
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.isDown: (button: number, player?: number) => boolean
Checks whether a button is currently held. For pointer buttons (`BTN_POINTER_A..D`), the second parameter is the pointer slot index (0 = mouse, 1-3 = touch / pen). For mouse slot 0: `A` is left, `B` is right, `C` is middle, `D` is back / forward (matches RetroBlit canonical, not DOM `PointerEvent.button` index). Touch / pen slots only support `A`; B/C/D return `false`. `button` accepts one or more bit flags from the `BTN_*` set (for example `BT.BTN_A | BT.BTN_B`). Matching uses ANY semantics: returns `true` when any selected button is held. For face buttons (`BTN_UP`…`BTN_SELECT`), players `0` and `1` merge keyboard and gamepad input (logical OR). Players `2` and `3` use gamepad only. Pointer flags (`BTN_POINTER_*`) use the `player` argument as pointer slot. `BTN_L2`, `BTN_R2` and `BTN_TRIGGER` are gamepad only (no keyboard mapping).
@since1.1.1@changed1.8.0 Also accepts BTN_L2 / BTN_R2 / BTN_TRIGGER (gamepad only).@parambutton - Button constant from the `BTN_*` set.@paramplayer - Zero-based player index for gamepads / keyboard, or pointer slot (0-3) for `BTN_POINTER_*`.@returns`true` while the button remains pressed.
isDown
(
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.type BTN_LEFT: number
Left button bit flag.
@since0.1.0
BTN_LEFT
, 0) || import uiui.dpad.isDown(import UI_DIRECTIONSUI_DIRECTIONS.LEFT)) {
let turn: numberturn -= 1; } if (
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.isDown: (button: number, player?: number) => boolean
Checks whether a button is currently held. For pointer buttons (`BTN_POINTER_A..D`), the second parameter is the pointer slot index (0 = mouse, 1-3 = touch / pen). For mouse slot 0: `A` is left, `B` is right, `C` is middle, `D` is back / forward (matches RetroBlit canonical, not DOM `PointerEvent.button` index). Touch / pen slots only support `A`; B/C/D return `false`. `button` accepts one or more bit flags from the `BTN_*` set (for example `BT.BTN_A | BT.BTN_B`). Matching uses ANY semantics: returns `true` when any selected button is held. For face buttons (`BTN_UP`…`BTN_SELECT`), players `0` and `1` merge keyboard and gamepad input (logical OR). Players `2` and `3` use gamepad only. Pointer flags (`BTN_POINTER_*`) use the `player` argument as pointer slot. `BTN_L2`, `BTN_R2` and `BTN_TRIGGER` are gamepad only (no keyboard mapping).
@since1.1.1@changed1.8.0 Also accepts BTN_L2 / BTN_R2 / BTN_TRIGGER (gamepad only).@parambutton - Button constant from the `BTN_*` set.@paramplayer - Zero-based player index for gamepads / keyboard, or pointer slot (0-3) for `BTN_POINTER_*`.@returns`true` while the button remains pressed.
isDown
(
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.type BTN_RIGHT: number
Right button bit flag.
@since0.1.0
BTN_RIGHT
, 0) || import uiui.dpad.isDown(import UI_DIRECTIONSUI_DIRECTIONS.RIGHT)) {
let turn: numberturn += 1; } if (
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.isDown: (button: number, player?: number) => boolean
Checks whether a button is currently held. For pointer buttons (`BTN_POINTER_A..D`), the second parameter is the pointer slot index (0 = mouse, 1-3 = touch / pen). For mouse slot 0: `A` is left, `B` is right, `C` is middle, `D` is back / forward (matches RetroBlit canonical, not DOM `PointerEvent.button` index). Touch / pen slots only support `A`; B/C/D return `false`. `button` accepts one or more bit flags from the `BTN_*` set (for example `BT.BTN_A | BT.BTN_B`). Matching uses ANY semantics: returns `true` when any selected button is held. For face buttons (`BTN_UP`…`BTN_SELECT`), players `0` and `1` merge keyboard and gamepad input (logical OR). Players `2` and `3` use gamepad only. Pointer flags (`BTN_POINTER_*`) use the `player` argument as pointer slot. `BTN_L2`, `BTN_R2` and `BTN_TRIGGER` are gamepad only (no keyboard mapping).
@since1.1.1@changed1.8.0 Also accepts BTN_L2 / BTN_R2 / BTN_TRIGGER (gamepad only).@parambutton - Button constant from the `BTN_*` set.@paramplayer - Zero-based player index for gamepads / keyboard, or pointer slot (0-3) for `BTN_POINTER_*`.@returns`true` while the button remains pressed.
isDown
(
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.type BTN_UP: number
Up button bit flag.
@since0.1.0
BTN_UP
, 0) || import uiui.dpad.isDown(import UI_DIRECTIONSUI_DIRECTIONS.UP)) {
let walk: numberwalk += 1; } if (
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.isDown: (button: number, player?: number) => boolean
Checks whether a button is currently held. For pointer buttons (`BTN_POINTER_A..D`), the second parameter is the pointer slot index (0 = mouse, 1-3 = touch / pen). For mouse slot 0: `A` is left, `B` is right, `C` is middle, `D` is back / forward (matches RetroBlit canonical, not DOM `PointerEvent.button` index). Touch / pen slots only support `A`; B/C/D return `false`. `button` accepts one or more bit flags from the `BTN_*` set (for example `BT.BTN_A | BT.BTN_B`). Matching uses ANY semantics: returns `true` when any selected button is held. For face buttons (`BTN_UP`…`BTN_SELECT`), players `0` and `1` merge keyboard and gamepad input (logical OR). Players `2` and `3` use gamepad only. Pointer flags (`BTN_POINTER_*`) use the `player` argument as pointer slot. `BTN_L2`, `BTN_R2` and `BTN_TRIGGER` are gamepad only (no keyboard mapping).
@since1.1.1@changed1.8.0 Also accepts BTN_L2 / BTN_R2 / BTN_TRIGGER (gamepad only).@parambutton - Button constant from the `BTN_*` set.@paramplayer - Zero-based player index for gamepads / keyboard, or pointer slot (0-3) for `BTN_POINTER_*`.@returns`true` while the button remains pressed.
isDown
(
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.type BTN_DOWN: number
Down button bit flag.
@since0.1.0
BTN_DOWN
, 0) || import uiui.dpad.isDown(import UI_DIRECTIONSUI_DIRECTIONS.DOWN)) {
let walk: numberwalk -= 1; } // Holding a key while also pushing a stick (or both sticks at once) must not go // faster than full speed. Math.min() and Math.max() clamp each value back into // the -1 to +1 range. let turn: numberturn = Math.max(-1, Math.min(1, let turn: numberturn)); let walk: numberwalk = Math.max(-1, Math.min(1, let walk: numberwalk)); this.Demo.angle: numberangle += let turn: numberturn * const TURN_SPEED: 0.04TURN_SPEED; // A swipe left or right snaps a quarter turn, handy for touch players at corners. // ui.swipe() answers with one of the UI_DIRECTIONS names, or null for no swipe. const const swipe: anyswipe = import uiui.swipe(); if (const swipe: anyswipe === import UI_DIRECTIONSUI_DIRECTIONS.LEFT) { this.Demo.angle: numberangle -= const QUARTER_TURN: numberQUARTER_TURN; } else if (const swipe: anyswipe === import UI_DIRECTIONSUI_DIRECTIONS.RIGHT) { this.Demo.angle: numberangle += const QUARTER_TURN: numberQUARTER_TURN; } // Walking: the step is positive forward, negative backward, and zero standing // still. const const step: numberstep = let walk: numberwalk * const MOVE_SPEED: 0.05MOVE_SPEED; // Math.cos() and Math.sin() turn the facing angle into how much of the step goes // right (x) and how much goes down (y), like splitting a diagonal walk into its // across and down parts. if (const step: numberstep !== 0) { this.Demo.moveBy(dx: any, dy: any): voidmoveBy(Math.cos(this.Demo.angle: numberangle) * const step: numberstep, Math.sin(this.Demo.angle: numberangle) * const step: numberstep); } // Standing on the exit cell wins the level. if (const MAP: {}MAP[Math.floor(this.Demo.y: numbery)][Math.floor(this.Demo.x: numberx)] === const CELL_EXIT: "X"CELL_EXIT) { this.Demo.levelClear: booleanlevelClear = true; this.Demo.clearTimer: numberclearTimer = const CLEAR_TICKS: 120CLEAR_TICKS; } } // Draws one frame: ceiling and floor, then one ray per screen column for the walls, // then the minimap and the kit's controls on top. Demo.render(): voidrender() { // Top half ceiling, bottom half floor. The walls are drawn on top of both. this.Demo.rect: Rect2irect.Rect2i.set(x: number, y: number, width: number, height: number): Rect2i
Sets all components of this rectangle. Modifies this rectangle directly for maximum performance. WARNING: Mutates this rectangle. Don't use on frozen/cached singletons.
@paramx - New x position.@paramy - New y position.@paramwidth - New width.@paramheight - New height.@returnsThis rectangle for chaining.
set
(0, 0, const SCREEN_W: 320SCREEN_W, const SCREEN_H: 240SCREEN_H / 2);
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.drawRectFill: (rect: Rect2i, paletteIndex: number) => void
Draws a filled rectangle.
@since0.1.0@paramrect - Rectangle bounds in display coordinates.@parampaletteIndex - Palette color index.
drawRectFill
(this.Demo.rect: Rect2irect, const COLOR_CEILING: 1COLOR_CEILING);
this.Demo.rect: Rect2irect.Rect2i.set(x: number, y: number, width: number, height: number): Rect2i
Sets all components of this rectangle. Modifies this rectangle directly for maximum performance. WARNING: Mutates this rectangle. Don't use on frozen/cached singletons.
@paramx - New x position.@paramy - New y position.@paramwidth - New width.@paramheight - New height.@returnsThis rectangle for chaining.
set
(0, const SCREEN_H: 240SCREEN_H / 2, const SCREEN_W: 320SCREEN_W, const SCREEN_H: 240SCREEN_H / 2);
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.drawRectFill: (rect: Rect2i, paletteIndex: number) => void
Draws a filled rectangle.
@since0.1.0@paramrect - Rectangle bounds in display coordinates.@parampaletteIndex - Palette color index.
drawRectFill
(this.Demo.rect: Rect2irect, const COLOR_FLOOR: 2COLOR_FLOOR);
// The direction the player faces, as an arrow one cell long (dirX, dirY), and the // camera plane: a short line at right angles to it (planeX, planeY). Think of the // plane as a window held in front of your face; every ray passes through one // point of that window. const const dirX: anydirX = Math.cos(this.Demo.angle: numberangle); const const dirY: anydirY = Math.sin(this.Demo.angle: numberangle); const const planeX: numberplaneX = -const dirY: anydirY * const FOV_PLANE: 0.66FOV_PLANE; const const planeY: numberplaneY = const dirX: anydirX * const FOV_PLANE: 0.66FOV_PLANE; for (let let col: numbercol = 0; let col: numbercol < const SCREEN_W: 320SCREEN_W; let col: numbercol++) { // Where this column sits on the window: -1 at the left edge, 0 in the middle, // +1 at the right edge. The ray goes forward plus that much of the plane. const const cameraX: numbercameraX = (2 * let col: numbercol) / const SCREEN_W: 320SCREEN_W - 1; function castRay(px: any, py: any, dx: any, dy: any, hit: any): voidcastRay(this.Demo.x: numberx, this.Demo.y: numbery, const dirX: anydirX + const planeX: numberplaneX * const cameraX: numbercameraX, const dirY: anydirY + const planeY: numberplaneY * const cameraX: numbercameraX, this.
Demo.hit: {
    dist: number;
    side: number;
    cell: string;
}
hit
);
// A wall one cell away fills the whole screen height; twice as far, half as // tall. Math.max() keeps the distance from reaching zero, which would divide // by zero. const const height: anyheight = Math.floor(const SCREEN_H: 240SCREEN_H / Math.max(this.
Demo.hit: {
    dist: number;
    side: number;
    cell: string;
}
hit
.dist: numberdist, 0.01));
// Center the line on the horizon and clip it to the screen. const const top: anytop = Math.max(0, Math.floor((const SCREEN_H: 240SCREEN_H - const height: anyheight) / 2)); const const bottom: anybottom = Math.min(const SCREEN_H: 240SCREEN_H - 1, const top: anytop + const height: anyheight); // Pick the palette slot: which wall color, which face, and how far away. Each // whole cell of distance is one shade darker, up to the darkest shade. const const kind: anykind = Math.max(0, const WALL_KINDS: "#AB"WALL_KINDS.indexOf(this.
Demo.hit: {
    dist: number;
    side: number;
    cell: string;
}
hit
.cell: stringcell));
const const shade: anyshade = Math.min(const SHADES: 8SHADES - 1, Math.floor(this.
Demo.hit: {
    dist: number;
    side: number;
    cell: string;
}
hit
.dist: numberdist));
this.Demo.lineTop: Vector2ilineTop.Vector2iOps.set(x: number, y: number): Vector2i
Sets both components of this vector. Modifies this vector directly for maximum performance. WARNING: Mutates this vector. Don't use on frozen/cached singletons.
@paramx - New x component.@paramy - New y component.@returnsThis vector for chaining.
set
(let col: numbercol, const top: anytop);
this.Demo.lineBottom: Vector2ilineBottom.Vector2iOps.set(x: number, y: number): Vector2i
Sets both components of this vector. Modifies this vector directly for maximum performance. WARNING: Mutates this vector. Don't use on frozen/cached singletons.
@paramx - New x component.@paramy - New y component.@returnsThis vector for chaining.
set
(let col: numbercol, const bottom: anybottom);
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.drawLine: (p0: Vector2i, p1: Vector2i, paletteIndex: number) => void
Draws a pixel-perfect line between two points. Uses rasterized line drawing without antialiasing.
@since0.1.0@paramp0 - Start position in display coordinates.@paramp1 - End position in display coordinates.@parampaletteIndex - Palette color index.
drawLine
(this.Demo.lineTop: Vector2ilineTop, this.Demo.lineBottom: Vector2ilineBottom, function wallSlot(kind: any, side: any, shade: any): anywallSlot(const kind: anykind, this.
Demo.hit: {
    dist: number;
    side: number;
    cell: string;
}
hit
.side: numberside, const shade: anyshade));
} this.Demo.renderMinimap(): voidrenderMinimap(); // Some effects (the grain and the rolling band) animate, so they need the current // time each frame. `'time' in fx` asks whether this effect has a time setting at // all. for (const const fx: anyfx of this.Demo.crt: {}
@type{Effect[]}
crt
) {
if ('time' in const fx: anyfx) { const fx: anyfx.time =
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.timeSeconds: number
Fixed-step elapsed time in seconds (`BT.ticks * BT.deltaSeconds`).
@since1.0.4@returnsElapsed fixed-step time in seconds since initialization.
timeSeconds
;
} } // The win message, centered over the view with the shared caption style. if (this.Demo.levelClear: booleanlevelClear) { import uiui.caption(const SCREEN_W: 320SCREEN_W / 2 - 33, const SCREEN_H: 240SCREEN_H / 2 - 7, 'LEVEL CLEAR', { color: stringcolor: 'accent' }); } // Without WebGPU there is no CRT chain, so say why the C key does nothing. The // shared note is too wide for this 320-pixel screen, so this is a short version, // placed just above the engine's small overlay hint in the bottom-left corner. if (!this.Demo.effectsAvailable: booleaneffectsAvailable) { import uiui.caption(4, const SCREEN_H: 240SCREEN_H - 24, 'CRT needs WebGPU', { color: stringcolor: 'warm' }); } // The touch D-pad for walking and turning. It appears after the first touch. import uiui.dpadWidget(); } // Draws the maze from above in the top-left corner, then the player as a 2x2 dot. Demo.renderMinimap(): voidrenderMinimap() { for (let let y: numbery = 0; let y: numbery < const MAP: {}MAP.length; let y: numbery++) { for (let let x: numberx = 0; let x: numberx < const MAP: {}MAP[let y: numbery].length; let x: numberx++) { let let color: numbercolor = const COLOR_MAP_FLOOR: 4COLOR_MAP_FLOOR; if (const MAP: {}MAP[let y: numbery][let x: numberx] === const CELL_EXIT: "X"CELL_EXIT) { let color: numbercolor = const COLOR_MAP_EXIT: 6COLOR_MAP_EXIT; } else if (function isWall(x: any, y: any): booleanisWall(let x: numberx, let y: numbery)) { let color: numbercolor = const COLOR_MAP_WALL: 3COLOR_MAP_WALL; } this.Demo.rect: Rect2irect.Rect2i.set(x: number, y: number, width: number, height: number): Rect2i
Sets all components of this rectangle. Modifies this rectangle directly for maximum performance. WARNING: Mutates this rectangle. Don't use on frozen/cached singletons.
@paramx - New x position.@paramy - New y position.@paramwidth - New width.@paramheight - New height.@returnsThis rectangle for chaining.
set
(const MAP_ORIGIN: Vector2iMAP_ORIGIN.Vector2i.x: number
Horizontal component (defaults to 0).
x
+ let x: numberx * const MAP_CELL: 3MAP_CELL, const MAP_ORIGIN: Vector2iMAP_ORIGIN.Vector2i.y: number
Vertical component (defaults to 0).
y
+ let y: numbery * const MAP_CELL: 3MAP_CELL, const MAP_CELL: 3MAP_CELL, const MAP_CELL: 3MAP_CELL);
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.drawRectFill: (rect: Rect2i, paletteIndex: number) => void
Draws a filled rectangle.
@since0.1.0@paramrect - Rectangle bounds in display coordinates.@parampaletteIndex - Palette color index.
drawRectFill
(this.Demo.rect: Rect2irect, let color: numbercolor);
} } // The player's position in cells times the cell size gives minimap pixels. The -1 // centers the 2x2 dot on that spot. this.Demo.rect: Rect2irect.Rect2i.set(x: number, y: number, width: number, height: number): Rect2i
Sets all components of this rectangle. Modifies this rectangle directly for maximum performance. WARNING: Mutates this rectangle. Don't use on frozen/cached singletons.
@paramx - New x position.@paramy - New y position.@paramwidth - New width.@paramheight - New height.@returnsThis rectangle for chaining.
set
(
const MAP_ORIGIN: Vector2iMAP_ORIGIN.Vector2i.x: number
Horizontal component (defaults to 0).
x
+ Math.floor(this.Demo.x: numberx * const MAP_CELL: 3MAP_CELL) - 1,
const MAP_ORIGIN: Vector2iMAP_ORIGIN.Vector2i.y: number
Vertical component (defaults to 0).
y
+ Math.floor(this.Demo.y: numbery * const MAP_CELL: 3MAP_CELL) - 1,
2, 2, );
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.drawRectFill: (rect: Rect2i, paletteIndex: number) => void
Draws a filled rectangle.
@since0.1.0@paramrect - Rectangle bounds in display coordinates.@parampaletteIndex - Palette color index.
drawRectFill
(this.Demo.rect: Rect2irect, const COLOR_MAP_PLAYER: 5COLOR_MAP_PLAYER);
} // Moves the player by (dx, dy) without walking into walls. The trick is to try the // two directions one at a time: if the sideways part is blocked but the forward part // is not, the player still slides along the wall instead of stopping dead. // Math.sign() is -1, 0, or +1, so the radius is added on the side we are moving // toward. Demo.moveBy(dx: any, dy: any): voidmoveBy(dx: anydx, dy: anydy) { const const nx: anynx = this.Demo.x: numberx + dx: anydx; if (!function isWall(x: any, y: any): booleanisWall(const nx: anynx + Math.sign(dx: anydx) * const PLAYER_RADIUS: 0.2PLAYER_RADIUS, this.Demo.y: numbery)) { this.Demo.x: numberx = const nx: anynx; } const const ny: anyny = this.Demo.y: numbery + dy: anydy; if (!function isWall(x: any, y: any): booleanisWall(this.Demo.x: numberx, const ny: anyny + Math.sign(dy: anydy) * const PLAYER_RADIUS: 0.2PLAYER_RADIUS)) { this.Demo.y: numbery = const ny: anyny; } } // Keyboard shortcuts: C switches the CRT look, R goes back to the start. // BT.isKeyPressed() is true only on the tick a key goes down, so holding C does not // flicker the CRT on and off. C only matters on WebGPU, where the CRT chain exists. Demo.handleShortcuts(): voidhandleShortcuts() { if (
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.isKeyPressed: (key: string, repeatRate?: number) => boolean
Checks whether a keyboard key was pressed on the current fixed-update tick. Optional `repeatRate` is in fixed ticks between repeats (`0` or omitted = edge only). When `repeatRate > 0`, repeats fire while held per `(ticks - firstPressTick) > 0 && (ticks - firstPressTick) % repeatRate === 0`. Call from `update()`, not `render()`: the press edge clears once per fixed-update tick, which always runs before that frame's `render()`, so a press read from `render()` can be intermittently missed under rapid input.
@since1.1.1@paramkey - DOM keyboard code string.@paramrepeatRate - Ticks between repeat triggers; omit or `0` for no repeat.@returns`true` on the press edge (and on repeat ticks when configured).
isKeyPressed
('KeyC') && this.Demo.effectsAvailable: booleaneffectsAvailable) {
this.Demo.crtOn: booleancrtOn = !this.Demo.crtOn: booleancrtOn; this.Demo.applyEffects(): voidapplyEffects(); } if (
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.isKeyPressed: (key: string, repeatRate?: number) => boolean
Checks whether a keyboard key was pressed on the current fixed-update tick. Optional `repeatRate` is in fixed ticks between repeats (`0` or omitted = edge only). When `repeatRate > 0`, repeats fire while held per `(ticks - firstPressTick) > 0 && (ticks - firstPressTick) % repeatRate === 0`. Call from `update()`, not `render()`: the press edge clears once per fixed-update tick, which always runs before that frame's `render()`, so a press read from `render()` can be intermittently missed under rapid input.
@since1.1.1@paramkey - DOM keyboard code string.@paramrepeatRate - Ticks between repeat triggers; omit or `0` for no repeat.@returns`true` on the press edge (and on repeat ticks when configured).
isKeyPressed
('KeyR')) {
this.Demo.respawn(): voidrespawn(); } } // Puts the player back on the start cell, facing right. Demo.respawn(): voidrespawn() { const
const spawn: {
    x: any;
    y: number;
}
spawn
=
function findSpawn(): {
    x: any;
    y: number;
}
findSpawn
();
this.Demo.x: numberx =
const spawn: {
    x: any;
    y: number;
}
spawn
.x: anyx;
this.Demo.y: numbery =
const spawn: {
    x: any;
    y: number;
}
spawn
.y: numbery;
this.Demo.angle: numberangle = 0; this.Demo.levelClear: booleanlevelClear = false; this.Demo.clearTimer: numberclearTimer = 0; } // Takes every CRT effect off, then puts back the ones that should run: none when the // CRT is switched off, and all but the moving grain and rolling band when the player // prefers reduced motion. Removing first keeps the chain in its original order. Demo.applyEffects(): voidapplyEffects() { for (const const fx: anyfx of this.Demo.crt: {}
@type{Effect[]}
crt
) {
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.effectRemove: (effect: Effect) => void
Removes a previously registered post-processing effect. Searches both tiers and disposes the effect from whichever chain holds it. Removing an effect that was never added is a no-op. When the engine is not ready, or the effect call fails, reports the error once (a panel in dev builds, the console in release) instead of throwing; the game keeps running.
@since1.0.3@parameffect - Effect instance to remove.
effectRemove
(const fx: anyfx);
} if (!this.Demo.crtOn: booleancrtOn) { return; } for (const const fx: anyfx of this.Demo.crt: {}
@type{Effect[]}
crt
) {
if (
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.isReducedMotionPreferred: boolean
Whether reduced motion is currently preferred. Resolves `window.matchMedia('(prefers-reduced-motion: reduce)')`, or the `?reducedmotion` / `?noreducedmotion` URL flags when either is present. Pair with {@link IBTDemo#onReducedMotionChange } to react when the preference changes at runtime - it is not fixed for the session, the same way {@link BT.screenOrientation } is not.
@since1.7.0@returns`true` when reduced motion should be preferred.
isReducedMotionPreferred
&& (const fx: anyfx instanceof class Noise
Additive per-pixel pseudo-random noise. Reseeds each frame from {@link time } so the noise pattern animates. Display-tier.
@since1.0.3
Noise
|| const fx: anyfx instanceof class RollLine
Slowly scrolling vertical interference band that brightens a horizontal stripe of the image. Combination of three cosines + smoothstep gives the stripe a soft top/bottom edge. Display-tier. Demo drives {@link time } (typically `BT.ticks / BT.targetFPS`).
@since1.0.3
RollLine
)) {
continue; }
const BT: {
    FLIP_H: number;
    FLIP_V: number;
    ROT_90_CW: number;
    ROT_180_CW: number;
    ROT_270_CW: number;
    BTN_UP: number;
    BTN_DOWN: number;
    BTN_LEFT: number;
    BTN_RIGHT: number;
    BTN_A: number;
    BTN_B: number;
    BTN_X: number;
    BTN_Y: number;
    BTN_L: number;
    BTN_R: number;
    BTN_START: number;
    BTN_SELECT: number;
    BTN_POINTER_A: number;
    BTN_POINTER_B: number;
    BTN_POINTER_C: number;
    BTN_POINTER_D: number;
    PLAYER_ONE: number;
    PLAYER_TWO: number;
    PLAYER_THREE: number;
    PLAYER_FOUR: number;
    AXIS_LEFT_X: number;
    AXIS_LEFT_Y: number;
    AXIS_RIGHT_X: number;
    AXIS_RIGHT_Y: number;
    AXIS_TRIGGER_L: number;
    ... 10 more ...;
    DEFAULT_KEYBOARD_SINGLE_PLAYER2: Readonly<Record<number, readonly string[]>>;
} & ... 7 more ... & {
    ...;
}
Main BLIT386 API namespace used by runtime demos. Assembled from the parts in `src/bt/` with property descriptors, so getters stay getters.
BT
.effectAdd: (effect: Effect) => void
Appends a fullscreen post-processing effect to whichever chain matches its declared {@link Effect#tier } . - `tier='pixel'` -> pixel chain (logical resolution). - `tier='display'` -> display chain (output resolution); requires `drawingBufferSize` in effective hardware settings (`configure()` or `defaultConfig()`). Effects run in registration order within each tier. The pixel chain runs first, followed by the upscale pass, followed by the display chain. Each {@link Effect } instance owns its own GPU resources and may be mutated each frame from demo code. When the engine is not ready, or the effect call fails, reports the error once (a panel in dev builds, the console in release) instead of throwing; the game keeps running.
@since1.0.3@parameffect - Effect instance to append.
effectAdd
(const fx: anyfx);
} } // The engine calls this when the reduced-motion preference changes while the demo // runs. Demo.onReducedMotionChange(): voidonReducedMotionChange() { this.Demo.applyEffects(): voidapplyEffects(); } } function bootstrap(DemoClass: DemoConstructor, options?: BootstrapOptions): Promise<boolean>
One-liner bootstrap function for BLIT386 demos. Handles canvas retrieval and engine initialization. Backend selection (WebGPU or software fallback) is managed internally by BTAPI. This function provides a streamlined way to start a demo with sensible defaults while allowing customization through options.
@since0.2.0@changed1.4.0 Calling `bootstrap()` again while already initialized now routes to a hot swap (via {@link registerHotReload}) when a Vite HMR context is registered, or logs a double-bootstrap guard and returns `false` otherwise - previously it silently started a second, unstoppable `GameLoop`.@changed1.7.0 Exposes `BT` on `window.BT` after bootstrap finishes, gated by {@link BootstrapOptions#exposeGlobal } (default: {@link BT.isDevMode}). It is exposed on every path, a failed boot included, so the console can still inspect the engine; a harness that waits for a running game should poll `window.BT?.isReady`, not the presence of `window.BT`.@changed1.9.0 An `onSuccess` callback that throws is logged and no longer replaces the running game with an error panel, fires `onError`, or makes `bootstrap()` resolve `false`.@paramDemoClass - Demo class constructor implementing `IBTDemo` (optional `configure()` for hardware settings).@paramoptions - Optional configuration for IDs and callbacks.@returns`true` when the demo boots successfully; otherwise `false`.@example// Simplest usage - uses default IDs. bootstrap(MyDemo);@example// With custom options. bootstrap(MyDemo, { canvasID: 'custom-canvas', containerID: 'custom-container', onSuccess: () => console.log('Demo started!'), onError: (err) => analytics.trackError(err), });@example// Await the result. const success = await bootstrap(MyDemo); if (success) { console.log('Demo is running'); }
bootstrap
(class DemoDemo);