title: Rectangular collision system not working in love2d
body: <p>I'm trying to create the base architecture for managing objects and collisions in a simple game in the Love2d framework.  All of the objects are stored in a table (<code>objects:activeObjects</code>) and then a loop in the <code>objects:calculateCollisions()</code> function iterates through all of the objects.  With each iteration, another nested loop checks to see if that object overlaps with any of the other objects in the same table.  At the end of <code>objects:calculateCollisions()</code>, each object will ideally have a table containing references to all of the objects it overlaps with at the current point in time.  However, the objects always have empty collision tables.<br><br>Right now there are two test objects: one which moves with your mouse, and one which always stays in the top-right corner.  The two objects should, to the user, disappear simultaneously when they overlap, but, as mentioned before, the <code>collidingObjects</code> tables are always empty.<br><br>
  I have Three source files:<br>
  <code>main.lua</code>:<br> <a href="http://pastebin.com/xuGBSv2j" rel="nofollow">http://pastebin.com/xuGBSv2j</a><br>
  <code>objects.lua</code> (where most of the important stuff is written, and probably where the problem is):<br> <a href="http://pastebin.com/sahB6GF6" rel="nofollow">http://pastebin.com/sahB6GF6</a><br>
  <code>customObjects.lua</code> (where the constructors for the two test objects are defined):<br></p>
  
  <pre><code>function objects:newCollidingObject(x, y)
      local result = self:newActiveObject(x, y, 50, 50)
      result.id = "collidingObject"
      function result:collide(other)
          if other.id == "collidingObject" then self.remove = true end
      end
      return result
  end
  function objects:newMovingObject(x, y)
      local result = self:newCollidingObject(x, y)
      function result:act()
          self.x = love.mouse.getX()
          self.y = love.mouse.getY()
      end
      return result
  end
  </code></pre>
  
  <p>Sorry, I couldn't post more than two hyperlinks.</p>
  
  <p>EDIT: After some more debugging, I've narrowed down the problem to the <code>collidesWith(obj)</code> function.  It seems to always return false.<br>Here is the code:<br></p>
  
  <pre><code>function result:collidesWith(obj)
      if self.bottom &lt; obj.top then return false end
      if self.top &gt; obj.bottom then return false end
      if self.right &lt; obj.left then return false end
      if self.left &gt; obj.right then return false end
      return true
  end
  </code></pre>