A template for creating small and fast browser games.
goodluck is not a typical library. It's not suitable for installing via
npm install. Instead, use it as a template: clone it into a new repo,
remove features you don't need, and hack away.
- Create a new repository using goodluck as a template.
- Clone the newly created repository.
npm installthe build tools.
npm startthe development server.
Production builds are bundled into a single
.js file and optimized for
size. You can find them in
npm run build
goodluck is a template for creating small browser games. Apart from the game loop and the rendering pipeline, goodluck doesn't give you much more code. We like to think of goodluck as a set of good practices, architecture decisions, and tools.
Keep the scope small. Always start with the MVP version of each feature.
Write code just for this game. Your goal is to ship a game, not build an engine.
Write data-driven procedural code. Keep a strict separation between data (components) and logic (systems). Forgo object-oriented concepts like inheritance and polymorphism.
Prefer simple code. Write code that can be easily understood and reasoned about. Always measure the performance impact of new code.
goodluck implements the entity-component-system (ECS) architecture:
Entities are indices into arrays storing component data. Furthermore, a special array called
worldstores masks defining which components are enabled for which entities. Component masks are implemented using bitflags, which limits the total number of available components to 32. This should still be plenty for small and even medium-sized games.
Components are simple objects storing data, and only data. No logic goes into components. Each component defines an interface describing its data.
Systems store the game logic which runs for entities which have certain components enabled. Systems are executed either in
fixed_update(guaranteed to run with the delta of 16 ms), or in
frame_updatewhich runs once per animation frame, as menaged by the browser.
Interfaces describe the shapes of components. The data is then stored in plain object literals matching these shapes.
const enumsact as non-iterable
enums. They are replaced by their number value during compilation.
typealiases offer a way to create discriminated type unions. A closed typed system works well for goodluck because the code is only written with the current project in mind, and you have the total control over all types used across the project.