View Single Post
AsLan^
Not a tame lion...
 
Join Date: May 2004
Location: Narnia
 
2005-11-17, 04:13

Here's a good one,

Does anyone know an algorithm to find the center of a tetris block ?

I'm storing my blocks as x, y coordinates in multiples of 20, so the square looks like this:

blockOneX = 0;
blockOneY = 0;

blockTwoX = 20;
blockTwoY = 0;

blockThreeX = 0;
blockThreeY = 20;

blockFourX = 20;
blockFourY = 20;

and the three way looks like this:

blockOneX = 20;
blockOneY = 0;

blockTwoX = 0;
blockTwoY = 20;

blockThreeX = 20;
blockThreeY = 20;

blockFourX = 40;
blockFourY = 20;

Now, when I'm showing the next piece that the player will get, I want it to show up centered in a box on the side. The only problem is, I'm having trouble finding the center of the shape to make the correction when I draw it in my window (short of specifying the correction for each shape individually).

So, anybody come across this before ? I'm going to work on some more mundane parts of the game in the meantime.
  quote