Public Group

#### Archived

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

# Tetris Source

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

## 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 on other sites
A Google search produced 132,000 hits.

Maybe one of them is what you''re looking for.

##### Share on other sites
i''ve googled for it, and sifted thru many sourcecodes to. i can''t find one tetris source though that does it with the method i''m looking for.

##### 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]

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 47
• ### Forum Statistics

• Total Topics
632636
• Total Posts
3007573
• ### Who's Online (See full list)

There are no registered users currently online

×