diff options
author | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-02 16:13:23 -0600 |
---|---|---|
committer | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-02 16:13:23 -0600 |
commit | ac89bd1bed71aa473b50717ce682e9d7f06837bb (patch) | |
tree | 3b258a85622c98d3472677278769e911dd43339f /src/systems/physics.js | |
parent | 5a55b5fa0c678ff03842d2adec8543e754546718 (diff) | |
download | bbiy-ac89bd1bed71aa473b50717ce682e9d7f06837bb.tar.gz bbiy-ac89bd1bed71aa473b50717ce682e9d7f06837bb.zip |
Fix out-of-bounds issues
Diffstat (limited to 'src/systems/physics.js')
-rw-r--r-- | src/systems/physics.js | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/systems/physics.js b/src/systems/physics.js index c9b6cf7..0da8b9d 100644 --- a/src/systems/physics.js +++ b/src/systems/physics.js @@ -2,10 +2,12 @@ game.system.Physics = () => { const update = (elapsedTime) => { for (let id in game.entities) { const entity = game.entities[id]; - if (entity.hasComponent("momentum")) { + 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.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)); } } } |