blob: d72b1a07af8a54be97dd11d7f651c02ed7cba0ed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
game.system.Physics = () => {
const update = (elapsedTime, entities, changedIds) => {
for (let id in entities) {
const entity = entities[id];
if (entity.hasComponent("momentum") && entity.hasComponent("appearance")) {
const {dx, dy} = entity.components.momentum;
entity.components.position.x += dx * elapsedTime;
entity.components.position.y += dy * elapsedTime;
entity.components.position = clamp(entity.components.position, game.canvas.width - entity.components.appearance.width, game.canvas.height - entity.components.appearance.height);
}
}
return new Set();
}
return { update };
}
|