Coder Social home page Coder Social logo

piesku / peskenstein Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 1.52 MB

I'm live tweeting the development of a simple Wolfenstein3D clone: https://twitter.com/stas/status/1273951079139545092

Home Page: https://piesku.com/peskenstein/play/

License: ISC License

TypeScript 98.78% HTML 0.43% Makefile 0.20% JavaScript 0.60%

peskenstein's Introduction

๐Ÿคž Goodluck

A hackable template for creating small and fast browser games.

Use-Cases

Goodluck is great for:

  • Learning game programming and game design.
  • Prototyping gameplay ideas.
  • Building size-constrained games.
  • Experimenting with algorithms and APIs.
  • Modeling problems through animated simulations.

Getting Started

Goodluck is not a typical library. You don't install it via npm install. Instead, use it as a template: generate a new repository from it, 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.

Design Principles

Goodluck is a template for creating small browser games which fit in a few kilobytes. 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. Write code that you need just for this game. Don't design extensible abstractions. Your goal is to ship a game, not to build an engine.

  2. Write data-driven code. Goodluck uses the ECS architecture; separate the data (components) from the logic (systems).

  3. Prefer simple procedural code and closed type systems. Instead of designing class inheritance hierarchies, use union types and switch between the variants.

Tech Overview

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

  1. Entities are indices into arrays storing component data. A special array called Mask 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. Component data is stored in arrays in World instances.

  3. Systems store the game logic which runs for entities which have certain components enabled. Systems are executed in a deterministic order in Game#Update, once per animation frame, as managed 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.

Creating a New Project

When you're ready to start a new project, copy or rename one of the existing examples to src. NewProject2D and NewProject3D are two minimal examples which can provide a good general base for your work. WebGL2 is like NewProject3D but it uses WebGL2 which isn't supported in Safari nor iOS.

Feel free to copy components and systems from other examples as needed, but keep in mind that you might need to adjust the code slightly to make it work for your use-case.

When copying components, remember to add corresponding Has enum variants in components/com_index.ts. If the added components store data, make room for it in World in world.ts.

Once you've copied everything you need, feel free to remove all other project directories in the repository! It's completely yours to hack and customize.

Optimized Builds

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

  1. (Optional) Edit the EXAMPLE path in play/Makefile if you called your source directory something other than src.
  2. make -C play
  3. Open play/index.html in the browser.

peskenstein's People

Contributors

stasm avatar

Stargazers

Antonis Geralis avatar Jarek avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.