This project is a small browser game “engine” designed for teaching. Students can build worlds by editing HTML + CSS only.
- Worlds live in
index.html - Styling lives in
style.css - Blocks (configs) live in
blocks.js - Engine runtime lives in
engine.js - World logic + input lives in
main.js
Open index.html in a browser.
Tip: if your browser blocks ES modules when opened as a file, use a simple local server.
In index.html, change the active world here:
<div id="game" data-active-world="world-runner">Options:
world-runnerworld-platformerworld-dodgerworld-shooter
Only the selected world is shown (handled in style.css).
Common:
- Start / Jump:
Space(orArrowUp) - Pause:
PorEsc
Platformer / Dodger / Shooter:
- Move:
ArrowLeft/ArrowRight
Shooter:
- Shoot: hold
X
Each .entity is a div with CSS classes like:
<div class="entity player gravity jump health" data-x="60" data-y="0"></div>- The CSS classes on the entity act like “blocks”.
engine.jsloops over entities every frame.- For each class, the engine runs a behavior with the same name (if it exists).
- Block configuration (numbers/strings) comes from
blocks.jsvia theBLOCKSregistry.
Example:
gravitybehavior reads{ force: 0.4 }spawnRainbehavior reads spawn rate + templateshooterbehavior reads cooldown + bullet template
-
Copy an existing world container in
index.html:- Example: duplicate
<div id="world-dodger" class="game-world"> ... </div>
- Example: duplicate
-
Give it a new id:
- Example:
id="world-mynewworld"
- Example:
-
Add entities using
.entity+ block classes:- Player entity (usually class
player) - Spawner entity (class
spawner+ a spawn block) - Any obstacles / goal objects
- Player entity (usually class
-
Style it in
style.css:- Add rules for
#world-mynewworld, plus.player,.obstacle, etc.
- Add rules for
-
Select it by setting:
data-active-world="world-mynewworld"on#game
If students are ready for a little JavaScript, you can expand the library:
- New block config: add to
blocks.jsdefineBlock("myBlock", { ... })
- New engine behavior:
- Add a built-in behavior in
engine.js(global feature), or - Register a world-specific behavior in
main.jsvia:game.registerBehavior("myBlock", (entity, cfg, game) => { ... })
- Add a built-in behavior in
-
World 1 — Runner (
world-runner)- Jump over obstacles, score increases over time.
-
World 2 — Platformer (
world-platformer)- Move + jump across platforms, touch the goal to win, falling off ends the run.
-
World 3 — Dodger (
world-dodger)- Move left/right and avoid falling objects; survive ~10 seconds to win.
-
World 4 — Shooter (
world-shooter)- Move left/right and shoot enemies; clear all enemies to win.