Stuck on Tetris cause i did it differently, help?

Started by
5 comments, last by Draco5869 20 years, 9 months ago
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!
-----------------------------------------------------------Like a sponge!
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
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!
-----------------------------------------------------------Like a sponge!
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!
-----------------------------------------------------------Like a sponge!
All I did was make a ton of constants with the various block positions. Worked fine once I got the little typos out.
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
You need to reverse one side, i.e., x = y, and y = 3-x, or x = 3-y and y = x.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
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

This topic is closed to new replies.

Advertisement