Stuck on Tetris cause i did it differently, help?
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!
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
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!
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!
All I did was make a ton of constants with the various block positions. Worked fine once I got the little typos out.
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
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
Popular Topics
Advertisement