Jump to content
  • Advertisement

Archived

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

Draco5869

Stuck on Tetris cause i did it differently, help?

This topic is 5496 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

Alrighty, i''ve made a tetris using a game engine from a book that i''ve been reading. I have everything done so that i can create all the blocks, have them float down, move ''em, stop on other''s, etc. But, i can''t rotate them. The way that i''ve seen people do it is use maps like 0100 and use that, but i didn''t draw my blocks using that method. So, is there a way i can rotate them w/o writing every single combination? ----------------------------------------------------------- Like a sponge!

Share this post


Link to post
Share on other sites
Advertisement
Every block in tetris can be stored in a 4x4 array. Just write code to take on array and rotate the contents into another.

Try storing your blocks like this.


typedef struct
{
bool used[4][4]; // Indicates whether this element in the 4x4 grid is used.
} Block;


You can *almost* just swap the array indices around! Try to figure it out using the following examples...

block_out.used[1][3] = block_in.used[0][1];
block_out.used[0][2] = block_in.used[1][0];


Why you shouldn''t use iostream.h - ever! | A Good free online C++ book

Share this post


Link to post
Share on other sites
So should i re-write the creattion of the blocks so that i create a matching two-dimensional array w/ them ALONG w/ just drawing them out using a for loop. Actualy, this is quickly sounding plausible.

-----------------------------------------------------------
Like a sponge!

Share this post


Link to post
Share on other sites
Okay, i got the fact that you can do that to rotate them but that only switches them like:

1110
0100
0000
0000 to

1000
1100
1000
0000 and back. I''ve been trying this for awhile and i can find no way to make them rotate from top to right and right to bottom and bottom to left. PLEASE help =(

-----------------------------------------------------------
Like a sponge!

Share this post


Link to post
Share on other sites
All I did was make a ton of constants with the various block positions. Worked fine once I got the little typos out.

Share this post


Link to post
Share on other sites
Well, if you know how to rotate a block 90 degrees, what happens when you rotate that rotated block again?

smart_idiot got it, you just write a rotate_block function that will rotate any shaped block 90 degrees. Then you can just call it over and over when the player presses the rotate button.

Also remember that a player cannot rotate a block if the new rotated shape intersects with the background.


Why you shouldn''t use iostream.h - ever! | A Good free online C++ book

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!