summaryrefslogtreecommitdiff
path: root/src/systems
diff options
context:
space:
mode:
authorLogan Hunt <loganhunt@simponic.xyz>2022-04-02 16:13:23 -0600
committerLogan Hunt <loganhunt@simponic.xyz>2022-04-02 16:13:23 -0600
commitac89bd1bed71aa473b50717ce682e9d7f06837bb (patch)
tree3b258a85622c98d3472677278769e911dd43339f /src/systems
parent5a55b5fa0c678ff03842d2adec8543e754546718 (diff)
downloadbbiy-ac89bd1bed71aa473b50717ce682e9d7f06837bb.tar.gz
bbiy-ac89bd1bed71aa473b50717ce682e9d7f06837bb.zip
Fix out-of-bounds issues
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/physics.js4
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));
}
}
}