Tetris Source
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.
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.
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 ][ j ];<br>}<br><br><br>Hope that helps.<br>Pete <br><br><SPAN CLASS=editedby>[edited by - pete_2004 on April 4, 2004 6:40:43 AM]</SPAN> <br><br><SPAN CLASS=editedby>[edited by - pete_2004 on April 4, 2004 6:41:17 AM]</SPAN>
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 ][ j ];<br>}<br><br><br>Hope that helps.<br>Pete <br><br><SPAN CLASS=editedby>[edited by - pete_2004 on April 4, 2004 6:40:43 AM]</SPAN> <br><br><SPAN CLASS=editedby>[edited by - pete_2004 on April 4, 2004 6:41:17 AM]</SPAN>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement