menhera-ecs

0.0.3 • Public • Published

Install

$ yarn menhera menhera-ecs

Example

import Mhr from "menhera";
import ECS from "menhera-ecs";
 
let moveSystem = {
  system: {},
  methods: {
    update() {
      let entities = this.engine.get(["Position", "Velocity"]);
      entities.forEach(e => {
        console.log(e);
        e.Position.x += e.Velocity.x;
        e.Position.y += e.Velocity.y;
      });
    }
  }
};
 
let recycleSystem = {
  system: {},
  methods: {
    update() {
      let entities = this.engine.get(["~Components"]);
      entities.forEach(e => {
        let cps = [...e["~Components"], "~Components"];
        this.engine.removeComponents(cps, e);
      });
    }
  }
};
 
let Entities1 = {
  entity: {},
  components: {
    Name: "Entities1",
    Position: {
      x: 1,
      y: 1
    },
    Velocity: {
      x: 1,
      y: 1
    }
  }
};
 
let Entities2 = {
  entity: {},
  components: {
    Name: "Entities2",
    Position: {
      x: 1,
      y: 1
    },
    Velocity: {
      x: 2,
      y: 2
    }
  }
};
 
Mhr.$use({
  _mount: {
    ECS
  },
  _run: {
    Systems: [testSystem, moveSystem, recycleSystem],
    Entities: [Entities1, Entities2]
  }
});
 
setInterval(() => {
  ECS.update();
}, 1000 / 60);

Readme

Keywords

none

Package Sidebar

Install

npm i menhera-ecs

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

5 kB

Total Files

5

Last publish

Collaborators

  • vaiii