28 lines
452 B
JavaScript
28 lines
452 B
JavaScript
import * as world from "./world.mjs";
|
|
|
|
|
|
|
|
const entities = [];
|
|
|
|
export function create (x, y, color = "#fff") {
|
|
const entity = {
|
|
id: entities.length,
|
|
x,
|
|
y,
|
|
color,
|
|
};
|
|
entities.push(entity);
|
|
return entity;
|
|
}
|
|
|
|
export function destroy (id) {
|
|
// returns the destroyed entity, idk if that makes sense.
|
|
return entities.splice(id, 1)[0];
|
|
}
|
|
|
|
export function for_each (callback) {
|
|
entities.forEach(entity => {
|
|
callback(entity, entity.id);
|
|
});
|
|
}
|