So I'm using a SpriteBatch to keep up with lots of small pieces for a falling-piece puzzle game. I have an array of Quads (for different color blocks), and they are randomly added to the aforementioned SpriteBatch. Right now, the game determines when the current piece has hit the ground, then that piece is stopped and a new piece spawns that the player now can control.

In order to figure out when to stop dropping the piece, I need to do a collision check. This shouldn't be hard, because I should only have to check the falling piece (unless the current falling piece causes a chain reaction). But, what type of data structure should I use? I can't use the position data of the individual Quads, because the boundary boxes will actually be a different size/shape than the pieces (think triangle pieces, but I will need to use a slightly skinnier rectangle to fit upside-down pieces in between right-side up pieces).

Should I just duplicate the (x, y) pairs using offsets with a width and height, and store them in an array, or am I missing a more obvious/efficient way? I'm guessing that the play screen could fill up with several hundred of these pieces, and if I add two player mode, double that.

EDIT: Here's what the Quad size issue is all about:

enter image description here

  • \$\begingroup\$ Are you making a tetris clone? And are you using the physics engine for collisions? \$\endgroup\$
    – muhuk
    Commented Mar 25, 2013 at 23:31
  • 1
    \$\begingroup\$ Have you tried it? A hundred collision checks every second is nothing. Don't solve problems you don't have! :) \$\endgroup\$
    – Anko
    Commented Mar 26, 2013 at 11:03
  • \$\begingroup\$ Thanks for the response. For clarity, it is not a Tetris clone (triangular pieces that can either point up or down in a staggered configuration). I'm not using the physics engine, because the Love2D page said it was overkill for a situation like this. I'm already in the process of trying it now, but part of the issue is that I need to use a quad of a different size for the collisions. If you draw a square around a triangle, there is too much dead space to allow for "proper" stacking. \$\endgroup\$
    – C. Griffin
    Commented Mar 26, 2013 at 13:06
  • \$\begingroup\$ Are these blocks fixed to a grid? What do you mean by them having different sizes? Screenshots or drawings would help. \$\endgroup\$
    – Anko
    Commented Apr 17, 2013 at 15:14
  • 1
    \$\begingroup\$ Are the triangles always aligned to that grid? If so, you could simplfy it by ignoring the fact that all of your blocks are triangular and just checking whether the location below in the grid is filled or not. \$\endgroup\$
    – Anko
    Commented Apr 26, 2013 at 14:05

1 Answer 1


Assuming all triangles are the same size I recommend you use a grid to keep track of the slots that are being occupied by a triangle. If the slot where the triangle is going to be next frame is occupied, then you have collision:

if slotThatIsNext.empty == false then
    thisSlot.empty = false
    thisSlot.triangle = thisTriangle

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .