ty-ecs

1.0.2 • Public • Published

Tiny-ECS

tiny ECS(Entity Component System) for js

install

yarn add ty-ecs

example

import ecs from 'ty-ecs'
 
const ECS = new ecs()
 
ECS.S({
    name: 'moveSystem',
    components: ['position','velocity'],
    checkComponents: true,
    updateEach:(entity)=>{
        console.log(entity)
        entity['position'].x += entity['velocity'].x
        entity['position'].y += entity['velocity'].y
    }
}).S({
    name: 'ForceDamageSystem', 
    components: ['health'],
    checkComponents: true,
    updateEach:(entity)=>{
        entity['health'].hp -= 10
    }
}).S({
    name: 'DeadSystem', 
    components: ['health'],
    checkComponents: true,
    updateEach:(entity)=>{
        if(entity['health'].hp <= 0){
            console.log(entity['name'], 'is dead')
            delete entity['health']
            delete entity['velocity']
        }
    }
})
 
ECS.E({
    name:'player1',
    health:{
        hp: 50,
    },
    position: {
        x: 0,
        y: 0
    },
    velocity: {
        x: 1,
        y: 1
    }
}).E({
    name: 'player2',
    health:{
        hp: 100
    },
    position: {
        x: 0,
        y: 0
    },
    velocity: {
        x: 100,
        y: 100
    }
})
 
setInterval(() => {
    ECS.tick()
},1000)
 

Readme

Keywords

none

Package Sidebar

Install

npm i ty-ecs

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

236 kB

Total Files

7

Last publish

Collaborators

  • vaiii
  • koishi