From c48a2bb9344cf09b517e83fad04e5cf656573853 Mon Sep 17 00:00:00 2001 From: Alex Bezuska Date: Fri, 1 Jan 2016 10:39:52 -0500 Subject: [PATCH 1/3] add system to show hitboxes and collisions visually --- lib/systems/show-hitboxes.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 lib/systems/show-hitboxes.js diff --git a/lib/systems/show-hitboxes.js b/lib/systems/show-hitboxes.js new file mode 100644 index 0000000..65cd215 --- /dev/null +++ b/lib/systems/show-hitboxes.js @@ -0,0 +1,14 @@ +"use strict"; + +module.exports = function(ecs, game) { + game.entities.registerSearch("showHitBoxes", ["showHitBox", "size", "position", "collisions"]); + ecs.addEach(function drawRectangles(entity, context) { + context.strokeStyle = "white"; + if (game.entities.get(entity, "collisions").length > 0) { + context.strokeStyle = "red"; + } + var position = game.entities.get(entity, "position"); + var size = game.entities.get(entity, "size"); + context.strokeRect(Math.floor(position.x), Math.floor(position.y), size.width, size.height); + }, "showHitBoxes"); +}; From f52ccd9db79aca4c288ab717f78e04b5b5f82848 Mon Sep 17 00:00:00 2001 From: Alex Bezuska Date: Fri, 1 Jan 2016 13:18:49 -0500 Subject: [PATCH 2/3] add working showHitBoxes false --- lib/systems/show-hitboxes.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/systems/show-hitboxes.js b/lib/systems/show-hitboxes.js index 65cd215..a26ae00 100644 --- a/lib/systems/show-hitboxes.js +++ b/lib/systems/show-hitboxes.js @@ -3,12 +3,14 @@ module.exports = function(ecs, game) { game.entities.registerSearch("showHitBoxes", ["showHitBox", "size", "position", "collisions"]); ecs.addEach(function drawRectangles(entity, context) { - context.strokeStyle = "white"; - if (game.entities.get(entity, "collisions").length > 0) { - context.strokeStyle = "red"; + if (game.entities.get(entity, "showHitBoxes")) { + context.strokeStyle = "white"; + if (game.entities.get(entity, "collisions").length > 0) { + context.strokeStyle = "red"; + } + var position = game.entities.get(entity, "position"); + var size = game.entities.get(entity, "size"); + context.strokeRect(Math.floor(position.x), Math.floor(position.y), size.width, size.height); } - var position = game.entities.get(entity, "position"); - var size = game.entities.get(entity, "size"); - context.strokeRect(Math.floor(position.x), Math.floor(position.y), size.width, size.height); }, "showHitBoxes"); }; From 0993c83a68b06f101de9c52e700fdf21fa27d5a1 Mon Sep 17 00:00:00 2001 From: Alex Bezuska Date: Fri, 1 Jan 2016 14:00:47 -0500 Subject: [PATCH 3/3] fix typo --- lib/systems/show-hitboxes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/systems/show-hitboxes.js b/lib/systems/show-hitboxes.js index a26ae00..18b7e52 100644 --- a/lib/systems/show-hitboxes.js +++ b/lib/systems/show-hitboxes.js @@ -3,7 +3,7 @@ module.exports = function(ecs, game) { game.entities.registerSearch("showHitBoxes", ["showHitBox", "size", "position", "collisions"]); ecs.addEach(function drawRectangles(entity, context) { - if (game.entities.get(entity, "showHitBoxes")) { + if (game.entities.get(entity, "showHitBox")) { context.strokeStyle = "white"; if (game.entities.get(entity, "collisions").length > 0) { context.strokeStyle = "red";