This project uses a Modular state-driven architecture with a clear separation between logic, rendering, and input. The goal of this structure is to make features easy to add without breaking existing systems.
By separating update and draw phases, the code remains predictable, frame-rate independent, and easier to debug.
IMPORTANT NOTE:
The p5.js Web Editor does not support ES module imports β switch to local development!
The most up to date non-modular version of this project that will run on the web editor is v2.3 (SINGLE FILE): https://github.com/UoB-COMSM0166/2026-group-1/blob/496a6811c6db81a47fa46beab3b390756c9f7b2c/docs/georgia/platformer_dev_2.3/SINGLE FILE VERSION/sketch.js
InputSystem β intent
PlayerSystem β apply intent
PhysicsSystem β resolve motion
TorchSystem β resource +timing
RenderSystem β draw state
Engine β orchestrates
/project-root
β
ββ index.html # HTML file that loads p5.js and sketch.js
ββ config.js # Config file, for constants: gravity, jump power,
| canvas size
ββ sketch.js # Main file: p5.js canvas, engine wiring,
| darknessLayer, input bridge
ββ /gameEngine
β ββ engine.js # Engine class, runs update loop, registers systems
ββ /systems # Modular game systems
β ββ inputSystem.js # Handles input, sets player.intent
β ββ playerSystem.js # Applies intent to player (movement/jump)
β ββ physicsSystem.js # Gravity, collisions, landing checks
β ββ torchSystem.js # Torch behaviour, flicker, power drain
β ββ renderSystem.js # Draws everything: background, platforms, player,
| torch, UI
ββ /entities # Optional: reusable classes
β ββ player.js # Player class / data structure
β ββ torch.js # Torch class
|
ββ /assets # Images, sprites, sounds
β ββ/images
| | ββforrest.png
| ββ/sprites
| ββ/sounds
|
ββ /utils # Optional: helper functions (e.g., constrain, lerp)
Config answers βwhat should exist?β
Instances ( eg. const torch = new Torch() )answer βwhat exists right now?β
Systems answer βwhat happens each frame?β
| File | Responsibility |
|---|---|
| sketch.js | Main p5.js canvas; creates darknessLayer; initializes entities & systems; registers systems with Engine; forwards p5 input events. |
| gameEngine/engine.js | Engine class orchestrates game loop: calculates deltaTime, updates all systems, and calls draw phases. |
| systems/inputSystem.js | Sets player intent flags for movement/jump/torch; no direct side-effects on other systems. |
| systems/playerSystem.js | Applies movement and jump logic based on intent; updates player state. |
| systems/physicsSystem.js | Handles gravity and collision detection with ground and platforms; updates player.onGround. |
| systems/torchSystem.js | Manages torch on/off state, flicker timing, and drains player power. |
| systems/renderSystem.js | Draws background, platforms, player, torch light (via darknessLayer), and UI elements. |
| entities/player.js | Player class definition with default stats and resources. |
| entities/torch.js | Torch class definition with radius, flicker timer, and visibility logic. |