From 74b7eb885d008dfa26a490b2b434bcbb4dfebb91 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Thu, 14 Apr 2016 08:31:01 -0600 Subject: [PATCH] Optimized collision checks. Like wtf why didn't I do it this way before? --- Oversimplified.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Oversimplified.js b/Oversimplified.js index b1d8122..f28cc88 100644 --- a/Oversimplified.js +++ b/Oversimplified.js @@ -995,16 +995,10 @@ Oversimplified.GameObjectsAtPoint = function (x, y) { var objectsAtPoint = []; for (var obj in Oversimplified.O) { var object = Oversimplified.O[obj]; - for (var i = 0; i < 2 * object.xBound; i++) { - for (var j = 0; j < 2 * object.yBound; j++) { - var xToCheck = (object.x - object.xBound) + i; - var yToCheck = (object.y - object.yBound) + j; - - if (xToCheck == x && yToCheck == y) - { - objectsAtPoint.push(object); - } - } + if (x <= object.x + object.xBound && x >= object.x - object.xBound && + y <= object.y + object.yBound && y >= object.y - object.yBound) + { + objectsAtPoint.push(object); } }