diff --git a/lib/systems/show-hitboxes.js b/lib/systems/show-hitboxes.js new file mode 100644 index 0000000..18b7e52 --- /dev/null +++ b/lib/systems/show-hitboxes.js @@ -0,0 +1,16 @@ +"use strict"; + +module.exports = function(ecs, game) { + game.entities.registerSearch("showHitBoxes", ["showHitBox", "size", "position", "collisions"]); + ecs.addEach(function drawRectangles(entity, context) { + if (game.entities.get(entity, "showHitBox")) { + 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"); +};