@magmacrunch/adenosine-rpg
v0.5.0
Published
Lightweight 2D tile-based RPG engine
Readme
@magmacrunch/adenosine-rpg
Lightweight 2D tile-based RPG engine: game loop, movement, camera, collision, dialogue, inventory and entities. No runtime dependencies.
npm install @magmacrunch/adenosine-rpgUse
import {
initCanvas, player, createGameLoop, initInput,
updateCamera, renderWorld, setCurrentMap, setMap,
setGameStarted, handleMovement,
} from '@magmacrunch/adenosine-rpg';
initCanvas(document.getElementById('gameCanvas'));
player.x = 10;
player.y = 10;
const map = [
[2,2,2,2,2],
[2,0,0,0,2],
[2,0,0,0,2],
[2,2,2,2,2],
];
setCurrentMap('level1');
setMap(map);
initInput();
const loop = createGameLoop({
update: (dt) => {
updateCamera({ target: player, tileSize: 16, mapWidth: 5, mapHeight: 4 });
handleMovement(player, { speed: 0.4, dt, collisionOpts: { map, solidTiles: [2] } });
},
render: () => renderWorld({
map, tileSize: 16,
renderTile: (ctx, x, y, id) => {
ctx.fillStyle = { 0: '#7cb342', 2: '#5d4037' }[id] || '#000';
ctx.fillRect(x, y, 16, 16);
},
layers: [{ sortY: player.y, render: (ctx) => { /* draw player */ } }],
}),
fps: 30,
});
setGameStarted(true);
loop.start();API.md documents every export, with parameters and return shapes.
Dialogue in a text file
parseDialogueFile reads a game's conversations from one plain text file that
somebody who does not write code can edit: no quotes, no brackets to balance.
== granny
if granny-helping -> granny-thanks
Granny Granola: Mind the oats, dear.
Would you fetch the cans for me?
> Help her -> granny-thanks [set granny-helping]
> Not now
== granny-thanks
Granny Granola: Bless you, dear.import { parseDialogueFile, startConversation, finishConversation } from '@magmacrunch/adenosine-rpg';
const file = parseDialogueFile(await (await fetch('dialogue.txt')).text());
const flags = new Set(); // or anything with has and add, kept in the save
const c = startConversation(file, 'granny', flags); // follows the if lines
// show c.speaker, c.lines and c.answers; then, with the answer picked (or -1):
const next = finishConversation(c, picked, flags); // a name to start, or nullA mistake throws a DialogueFileError carrying the line number, so an editor
can point at it.
The format is shared with tunacan, the C pixel engine, and tunacan's
source/dialogue.h is the spec: the comment at its top is the full set of
rules. This is a second reader held to that one. It refuses the same mistakes
at the same lines, counts lengths in UTF-8 bytes as the C does, and enforces
the C loader's fixed limits (DIALOGUE_LIMITS), so a file one accepts the
other accepts. dialogue-file.test.ts mirrors tunacan's tests/test_dialogue.c
case for case; a change to the format is a change to both, tests first.
Without a bundler
The engine also runs from a single script tag:
<script src="https://cdn.jsdelivr.net/npm/@magmacrunch/[email protected]/dist/index.global.js"></script>It installs itself as window.AdRPG. Leave the @0.5 pin in place; an
unpinned jsDelivr URL serves whatever latest is, breaking changes included.
Under node_modules the file is dist/index.global.js.
Note
State lives in module-level singletons, so one page runs one RPG. That suits the game it was extracted from; a second concurrent instance would need the state module reworked.
Module format
There is no CommonJS entry point (exports has no require condition), so
import the module or load the IIFE build.
License
PolyForm Noncommercial 1.0.0. Copyright 2026 magmacrunch media.
Any noncommercial purpose is permitted. For a commercial licence, ask.
Part of adenosine, a collection
of lightweight web game engines by magmacrunch media.
Keep the NOTICE file with any copy you distribute.
