From af7dcd70c89525d01bc6dc6467be64283b61771a Mon Sep 17 00:00:00 2001 From: Taizo 'Tsa6' Simpson Date: Tue, 22 Aug 2017 12:36:10 -0400 Subject: [PATCH] Added margin system to enemy rendering, fixing alignment issues --- index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index e8b65b0..356a378 100644 --- a/index.js +++ b/index.js @@ -1033,11 +1033,13 @@ window.onload = function () { // Draw enemies for (let i in Game.enemies) { + let margin = .25 //A ratio of the width of a tile. .25 margins with 32 px tiles leave a 8 px margin on all sides, with the body being 16px x 16px let enemy = Game.enemies[i] - let rx = (enemy.x * mt) + mt / 8 - let ry = (enemy.y * mt) + mt / 8 + let rx = (enemy.x + mt) + mt * margin + let ry = (enemy.y * mt) + mt * margin + let w = mt - (mt * margin * 2) ctx.fillStyle = enemy.icon - ctx.fillRect(rx, ry, 16, 16) + ctx.fillRect(rx, ry, w, w) // health bars let hx = rx - 6