gakimball / ecs

Another Entity Component System

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ecs

Work in progress, not published yet.

Entity Component System

Travis npm

Installation

npm install ecs

Usage

Create a new ECS:

const System = require('ecs');

const sys = new System();

Create components:

function Living() {
  this.health = 5;
}

function Location() {
  this.x = 0;
  this.y = 0;
}

Create entity templates:

const Player = [
  [Living, {
    health: 100,
  }],
  Location,
];

const Gremlin = [
  Living,
  Location,
];

Create entities:

const player = sys.create(Player);
const gremlin = sys.create(Gremlin, [[Location, { x: 5, y: 5 }]]);

Query entities:

const player = sys.getSingle(Player);
const alive = sys.get(Living);
const existing = sys.get(Living, Gremlin);

Inspect entities:

const player = sys.getSingle(Player);
player.has(Living); // => true
player.has(Living, Evil); // => false
player.get(Living).health;

Modify entities:

function OnFire() {};

const player = sys.getSingle(Player);
player.add(OnFire);
player.remove(OnFire);

Destroy entities:

const player = sys.getSingle(Player);
sys.destroy(player);

API

Local Development

git clone https://github.com/gakimball/ecs
cd ecs
npm install
npm test

License

MIT © Geoff Kimball

About

Another Entity Component System

License:MIT License


Languages

Language:JavaScript 100.0%