Jump to content
• Advertisement

#### Archived

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

# first-game-questions (tetris)

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

Hello! I''m trying to program my first game, it''s a tetris clone. My question is about rotating the blocks. I''m programming every block as four individual squares. The problem is that I don''t really know how to rotate the block. So if someone has a smart and simple idea on how to do that, I would really appreciate if you tried to explain it to me. Thanks /Erik

#### Share this post

##### Share on other sites
Advertisement
Are you using DirectX?

X4J

#### Share this post

##### Share on other sites
no i''m not using direct x, i''m using allegro.

#### Share this post

##### Share on other sites
Erik,

Here is how I did it. The area where the pieces fall is a matrix of numbers (ie. 1 means there is a square there and 0 means there isn't). I defined a struct as follows:

struct Piece {
int * axis;
int square1[2];
int square2[2];
int square3[2];
};

This struct keeps track of one square of each piece (called the axis). The axis points to somewhere in the matrix that represents the screen (this is the matrix that I mentioned just a moment ago). Square1, square2, and square3 are the other 3 squares of the piece. They are int arrays of length 2 that store how far in the x direction and how far in the y direction each square is from the axis. Confused yet? Here's an example. Think of this piece:
   +  +++       (I call it the T)   ^ This is the axis square.

So the other squares are {0,-1}, {-1,0}, and {1,0} because they are either on the same x or y line (the 0s) or are one space away (the 1s and -1s). Each square is defined like this { (this square's x location - axis's x location) , (this square's y location - axis's y location) }.

The benefit of this data structure is that when you want to rotate a piece, all you have to do is switch the x and y of each square (checking for whether it is positive or negative). For instance when we rotate the T piece shown above to the right (clockwise), the {0,-1} square becomes {1,0}, the {-1,0} square becomes {0,-1} and the {1,0} square becomes {0,1}. Then, when you want to draw the piece, you just look to wherever the axis is pointing in the matrix, draw it, then move to the location of each square relative to the axis and draw them.

I hope this wasn't too confusing.

FragLegs

Edited by - FragLegs on July 23, 2001 4:32:01 PM

#### Share this post

##### Share on other sites
Thank you! I will try that

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
15
3. 3
4. 4
5. 5
• Advertisement

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633269
• Total Posts
3011148
• ### Who's Online (See full list)

There are no registered users currently online

×

## 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!