Archived

This topic is now archived and is closed to further replies.

The best way to do collision detection for tetris?

This topic is 5848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I myself am writing a tetris game too, I use a 2D array which is filled with 0''s and everytime a Tetraminoes stops falling I write a 1''s to the array at the positions of where the Tetraminoes is located...so then you just check every turn if the shape hit''s a 1 etc....

Chris

Share this post


Link to post
Share on other sites

You could just track the position of your piece by coordinates, then instead of updating an array every turn, you grab the input, if it is <- or -> you test (btw, by test I mean test if the next move you are going to make, not the move you just made) for a horizontal collision, if it is down (held), you check for vertical collision (based on your updated "speed") and then if there is a collision you you discontinue motion (in the indicated direction) in that segment. If the motion is a vertical collision, you stop the piece and then update your array. If you had multiple pieces going at once, you could update the array every turn, but that wouldn''t really be tetris now, would it?
Anyhow, it worked for me quite well and I hope it works for you.

Share this post


Link to post
Share on other sites