Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
    
Are you making a tetris clone? And are you using the physics engine for collisions? –  muhuk Mar 25 '13 at 23:31
1  
Have you tried it? A hundred collision checks every second is nothing. Don't solve problems you don't have! :) –  Anko Mar 26 '13 at 11:03
    
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. –  C. Griffin Mar 26 '13 at 13:06
    
Are these blocks fixed to a grid? What do you mean by them having different sizes? Screenshots or drawings would help. –  Anko Apr 17 '13 at 15:14
1  
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. –  Anko Apr 26 '13 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
end
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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