Jump to content
  • Advertisement


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.

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
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 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;

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



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


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


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.

[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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!