How to reduce moon processing? or muti hash?

1

I have a table with several tables of 5 positions where the first two are the position in a Cartesian plane.

    --Table with water collors
colors = {{r=15,g=94,b=156},{r=35,g=137,b=218},{r=28,g=163,b=236},{r=90,g=188,b=216},{r=116,g=204,b=244}}
points = {}
for i=1,10000 do
    j = love.math.random(1,table.getn(colors)-1)
    table.insert(points,{i,i,colors[j].r,colors[j].g,colors[j].b})

I'm making a method to change the position (the first two positions of the vector) of this object, but for this I need to know if it has any object on top of the other, ie if the first two values of the table match the value of another table, I'm assuming that comparing one by one is impractical, I thought of using oxey as the key to a hash, but I do not know if that's possible, does anyone know of any alternatives?

    
asked by anonymous 27.12.2017 / 18:32

1 answer

0

Physics collision detection is very labor intensive, and the Löve2D documentation advises you to only use this if you are sure that what you want to do needs physics (like a pinball game I once did).

One simple trick you can do is the following:

  • Divide your screen into 4 quadrants, each with a table of objects that are in that quadrant
  • Control the placement of objects by changing them from table when they switch quadrant
  • For a given object you know which quadrant to see if it collides with the others in that quadrant by checking the four quants of the bounding box
  • This form is very simple to implement and should offer the performance you are looking for. Otherwise there is another library in Löve2D called a bump that allows you to check a collision, it is simpler than physics and it is indicated to make a character walk on a platform for example, but it is much more complicated to use than this strategy here .

        
    16.01.2018 / 14:29