Archived

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

Tetris Source

This topic is 5000 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 remember from highschool some tetris source code that I saw. I''ve written a tetris game before but only for windows GDI and it was rather cheesed. I''m working on making a new tetris clone with SDL so that I can hone my polishing skills. Things like menu''s and pretty graphics with animations and such. The technique that I remember being used in this source I saw was a 3 dimensional array. The third dimension being used for each rotation. The method that I remember using was the algorithm that moved all the blocks in the 4x4 array into their new 90 degree turned positions. I rather like the three dimensional approach as it just requires an iteration of an integer value rather than an algorithm to process rotations. I''ve searched this forum from head to toe though trying to find tetris code similar to this, but it seems its not common. Does anyone know where I can find some code like this that I can study? I would like a few things cleared up with collision detection and a few other issue''s i''ve been having.

Share this post


Link to post
Share on other sites
If you want to use a three dimensional array do something like this:

const int BLOCK_SIZE = 4;
const int NUM_ROTATIONS = 4;
int block[NUM_ROTATIONS][BLOCK_SIZE][BLOCK_SIZE];

Then in your block creation code just fill the array as necessary.

eg

...

//first rotation
block[0][0][0] = 0;
block[0][1][0] = 0;

...

//second rotation
block[1][0][0] = 0;

etc
etc


Then to access a specific blocks rotation all you do is:

for( i = 0; i < BLOCK_SIZE; i++ )
for( j = 0; j < BLOCK_SIZE; j++ )
{
currentBlock[ currentRotation ][ i ][ j ];
}


Hope that helps.
Pete

[edited by - pete_2004 on April 4, 2004 6:40:43 AM]

[edited by - pete_2004 on April 4, 2004 6:41:17 AM]

Share this post


Link to post
Share on other sites