rocket.js

a little game engine that'll take you over the moon

A component-entity system with a library of game utilities makes building data-driven games a snap! Game logic is decomposed into simple systems each responsible for one moving piece. Adding or swapping features is a breeze.

        Rocket = require 'rocket-engine'

rocket = new Rocket

# 1. define components as functions that assign values...
rocket.component 'position', (cmp, options) ->
  cmp = {x: options.x ? 0, y: options.y ? 0}
# ...or as default value objects
rocket.component 'velocity', {x: 0, y: 0}

# 2. define systems that operate on keys with specific components
rocket.systemForEach 'move',
  # required components for a key
  ['position', 'velocity'],
  # function to call for each key that has all components
  (rocket, key, position, velocity) ->
    position.x += velocity.x
    position.y += velocity.y

# 3. add keys that contain components
rocket.key {
  spaceship : null # label, for filtering
  velocity  : null # use default component values
  position  : {x: WIDTH / 2, y: HEIGHT / 2}
}
      

See it in action: