This example, using Bun, demonstrates Banjo in under 125 lines of code. All of these files can all be found within the quick-start examples folder of the GitHub repo. You can clone the repo, open a shell in the examples/quick-start folder, then use bun server.ts to run:
Bun is not a requirement to use Banjo. It's just our favorite way to prototype and build
This is a simple template to provide minimal styling and the elements used by the "game".
This contains the actual "game" logic. It updates a <div> with the current estimated engine FPS and TPS, animates a round <div> across the screen in a bouncing ball pattern, and uses a watcher to monitor the engine pause state separately from the engine itself.
This contains a simple Bun server to host the HTML and transpile the "game" logic on the fly.
1 2 3 4 5 6 7 8 9101112131415
constserver=Bun.serve({asyncfetch({url}){constpath=newURL(url).pathname;if(path==='/game.ts'){const[body]=(awaitBun.build({entrypoints:['./game.ts']})).outputs;returnnewResponse(body);}if(path.startsWith('/src:')){returnnewResponse(Bun.file(path.slice(5)));}returnnewResponse(Bun.file('./index.html'));},});console.log(`Now listening on http://${server.hostname}:${server.port}\n${'-'.repeat(25+server.hostname.length+server.port.toString().length)}`);