diff --git a/src/2d.js b/src/2d.js index cfe66fa..0cc7b3b 100644 --- a/src/2d.js +++ b/src/2d.js @@ -30,7 +30,7 @@ export class Circle { b.o.addTo(v.adjust(b.r - bd)); return true; } -} +}; export class Vec2 { constructor(x, y) { @@ -120,4 +120,4 @@ export class Vec2 { cross(y) { return this.x * y.y - this.y * y.x; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/components.js b/src/components.js new file mode 100644 index 0000000..84af5b5 --- /dev/null +++ b/src/components.js @@ -0,0 +1,18 @@ +import { Circle } from '../src/2d.js'; + +export class Motion { + constructor(p, v) { + this.position = p; + this.velocity = v; + } +}; + +export class CollisionBox { + constructor(r) { + this.r = r; + } + + shape(o) { + return new Circle(o, this.r); + } +}; \ No newline at end of file diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..cb18c29 --- /dev/null +++ b/src/main.js @@ -0,0 +1,16 @@ +import { Vec2 } from '../src/2d.js'; +import { Motion, CollisionBox } from '../src/components.js'; +import { EntityRegistry } from '../src/ecs.js'; + +function main() { + let registry = new EntityRegistry(); + let tank = registry.create(); + registry.assign(tank, new Motion(new Vec2(0, 0), new Vec2(1, 1))); + registry.assign(tank, new CollisionBox(1)); + registry.forEach([Motion], (id, motion) => { + motion.position.addTo(motion.velocity); + }); + console.log(`motion: ${JSON.stringify(registry.get(tank, Motion))}`); +} + +main(); \ No newline at end of file