Craters is a modular JavaScript framework reimplemented in TypeScript for HTML5 game development in a spartan-programmer's way
npm install cratersWorld, Entity, System, Query).KeyboardEvent.code.bash
npm install craters
`Usage
$3
`typescript
import { EntityComponentSystem as ECS, RenderLoop } from "craters";// 1. Define Components
class Position extends ECS.Component {
constructor(public x: number, public y: number) { super(); }
}
class Velocity extends ECS.Component {
constructor(public dx: number, public dy: number) { super(); }
}
// 2. Define System
class MovementSystem extends ECS.System {
public execute(delta: number): void {
// Query entities with Position and Velocity
const query = this.world.createQuery([Position, Velocity]);
query.entities.forEach(entity => {
const pos = entity.getComponent(Position);
const vel = entity.getComponent(Velocity);
pos.x += vel.dx * delta;
pos.y += vel.dy * delta;
});
}
}
// 3. Setup World
const world = new ECS.World();
world.registerSystem(new MovementSystem());
// 4. Create Entity
const player = world.createEntity();
player.addComponent(new Position(0, 0));
player.addComponent(new Velocity(1, 0));
// 5. Run Loop
const loop = new RenderLoop((delta) => {
world.execute(delta);
});
``_Also, please don't edit files in the "dist" subdirectory as they are generated via Grunt. You'll find source code in the "src" subdirectory!_