1
\$\begingroup\$

Making a simple game in Love 2D framework where if I click on an object then it disappears.

Do I check to see if I've clicked the enemy inside a function in the enemy object? Or just in my main.lua? Currently I have this code in my main.lua:

function love.mousepressed(x, y, button)
   if button == "l" then
      for i,b in ipairs(bugs) do
         if b:isClicked(x, y) then
            table.remove(bugs, i)
         end
      end
   end
end

Is there a standard design pattern on where this code should belong?

\$\endgroup\$
1
\$\begingroup\$

What I do is make each entity handle its own collisions in its update function. This may or may not be practical depending on your project...But for me, it works and makes it easier to manage collisions when there's multiple instances of an object.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.