-
Notifications
You must be signed in to change notification settings - Fork 9
Will Blanton edited this page Sep 13, 2019
·
1 revision
An extremely simple (~100 lines of code) Entity-Component-System implementation!
Usage:
import zero.utilities.ECS;
class Main
{
static function main()
{
ECS.register_entity('human');
ECS.register_component('human', 'position', { x: 0, y: 0 });
ECS.register_component('human', 'velocity', { x: 1, y: 0 });
ECS.register_system(new BasicMovement(), ['position', 'velocity']);
for (i in 0...10) ECS.tick();
trace(ECS.get_data('human', 'position')); // {x: 10, y: 0}
}
}
class BasicMovement implements ECS.ISystem
{
public function new() {}
public function update(dt:Float, entities:Array<String>) for (entity in entities) {
var position = ECS.get_data(entity, 'position');
var velocity = ECS.get_data(entity, 'velocity');
position.x += velocity.x;
position.y += velocity.y;
}
}
For more info, please check out the API: http://01010111.com/zerolib/