Fix out-of-bounds issues
This commit is contained in:
parent
5a55b5fa0c
commit
ac89bd1bed
@ -2,10 +2,12 @@ game.system.Physics = () => {
|
|||||||
const update = (elapsedTime) => {
|
const update = (elapsedTime) => {
|
||||||
for (let id in game.entities) {
|
for (let id in game.entities) {
|
||||||
const entity = game.entities[id];
|
const entity = game.entities[id];
|
||||||
if (entity.hasComponent("momentum")) {
|
if (entity.hasComponent("momentum") && entity.hasComponent("appearance")) {
|
||||||
const {dx, dy} = entity.components.momentum;
|
const {dx, dy} = entity.components.momentum;
|
||||||
entity.components.position.x += dx * elapsedTime;
|
entity.components.position.x += dx * elapsedTime;
|
||||||
entity.components.position.y += dy * elapsedTime;
|
entity.components.position.y += dy * elapsedTime;
|
||||||
|
entity.components.position.x = Math.max(0, Math.min(game.canvas.width - entity.components.appearance.width, entity.components.position.x));
|
||||||
|
entity.components.position.y = Math.max(0, Math.min(game.canvas.height - entity.components.appearance.height, entity.components.position.y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user