Skip to content
A submission for js13kGames 2019
TypeScript JavaScript Other
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Add make to the CI action Sep 1, 2019
.vscode desert stage Aug 30, 2019
public Remove initial-scale=1, maximum-scale=1 Sep 13, 2019
shaders Minify shaders Sep 11, 2019
shapes
src Cull multiple components if needed Oct 14, 2019
tfu HAIRCUT TIME! Sep 13, 2019
.gitignore
.prettierrc
LICENSE Initial commit Aug 14, 2019
Makefile fix make for mac Sep 11, 2019
README.md Initial commit Aug 14, 2019
bundle_config.js Rename IIFE name from bundle_config Sep 1, 2019
minify_config.js Don't export game Sep 1, 2019
package.json Rename rollup.config.js to minify_config.js Sep 1, 2019
sed.txt Don't hash WebAudio methods Sep 13, 2019
terser_compress.txt (terser) Add hoist_funs (-76B) Sep 9, 2019
tsconfig.json Initial commit Aug 14, 2019

README.md

🤞 goodluck

A template for creating small and fast browser games.

Getting Started

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.

  1. Create a new repository using goodluck as a template.
  2. Clone the newly created repository.
  3. npm install the build tools.
  4. npm start the development server.

Production builds are bundled into a single .js file and optimized for size. You can find them in public/opt.

  1. npm run build

Design Principles

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.

  1. Keep the scope small. Always start with the MVP version of each feature.

  2. Write code just for this game. Your goal is to ship a game, not build an engine.

  3. Write data-driven procedural code. Keep a strict separation between data (components) and logic (systems). Forgo object-oriented concepts like inheritance and polymorphism.

  4. Prefer simple code. Write code that can be easily understood and reasoned about. Always measure the performance impact of new code.

Tech Overview

goodluck implements the entity-component-system (ECS) architecture:

  1. Entities are indices into arrays storing component data. Furthermore, a special array called world stores 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.

  2. Components are simple objects storing data, and only data. No logic goes into components. Each component defines an interface describing its data.

  3. 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_update which runs once per animation frame, as menaged by the browser.

goodluck is written in TypeScript, but it only uses a small subset of its features. The goal is to take advantage of the typing system and excellent editor support, while reducing any overhead in the final build. Hence, most features are strictly compile-only: they compile to zero bytes of JavaScript.

  • Interfaces describe the shapes of components. The data is then stored in plain object literals matching these shapes.

  • const enums act as non-iterable enums. They are replaced by their number value during compilation.

  • type aliases 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.

You can’t perform that action at this time.