1.0.2 • Published 6 years ago

ty-ecs v1.0.2

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

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)
1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago