Jump to content
• Advertisement

#### Archived

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

# DirectX and tetris...

This topic is 6043 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´m doing a simple tetris game with directX and C++. I have some problems... My pieces are made of a class object that contains x and y values, that draws the bitmap and so on. That object resides in a array of objects so they are easy to keep track of. I want to make the "gamefield" an 2d array. The pieces don´t fall down step by step, they slide down. The pieces are also made up by an array: shape[4][4] and so on. Here is the problem: How do I know when a piece fills up a place in the gamefield array? When it changes from a 0 to 1. I want to know the current array position for the piece. Both column and row. Could somebody help me please? Thanks.

#### Share this post

##### Share on other sites
Advertisement
i''m not certain if this is what you mean, but i''ll try:
your pieces fall less than the height of a "brick" each frame, right?
you could have the falling block divide it''s y-coordinate by the size of a grid square (plus add/subtract an offset, see next sentence) to see which grid square it is in. depending on how you draw the pieces, the offset would be different (i.e. if your (x,y) is the top-left corner, you''d need a different offset then if the piece is centered at (x,y)). for that, you''ll have to calculate and/or trial-and-error for yourself.
then, you can have the brick check the main game grid to see if it''s new grid-coordinates are in a valid square, otherwise it just landed.

--- krez (krezisback@aol.com)

#### Share this post

##### Share on other sites
I''m in the process of making a tetris game in OpenGL. The main mechanics work, now I just have to pretty it up. Point being, if some of you would like to check it out, feel free. I''ll also do what I can to answer some questions.

Click Here to download it.

- Mike

#### Share this post

##### Share on other sites
Thanks for the help krez!

#### Share this post

##### Share on other sites
Anybody else? I need as much help as I can get.

#### Share this post

##### Share on other sites
quote:
Original post by Joppe
Anybody else? I need as much help as I can get.

Like I said, I've written a tetris game. It's not pretty (yet) but it works properly. Check it out and let me know if you have any questions about how I did it.

- Mike

EDIT: wasn't working, fixed it. The version online is fully functional (except for the options, which doesn't take away from the game)

Edited by - mkaltner on January 4, 2002 6:44:31 PM

#### Share this post

##### Share on other sites
mkaltner:

looks good, but how do you rotate the blocks?

#### Share this post

##### Share on other sites
Try this site
www.c-coding.net
on the download section you will find a tetris game with full source code, that''s my first try to rite a game with DirectX. You may find it usefull.

#### Share this post

##### Share on other sites
quote:
Original post by masonium
mkaltner:

looks good, but how do you rotate the blocks?

Well, like you, I'm storing the blocks in a 2d array. Each element is either 0 or 1 indicating where to draw a block.

My game pieces are stored in a class called CGamePiece which also contain a CVector class (the 2d array). CGamePiece also needs to know the size of the piece.

Example:

0 1 0 0
1 1 1 0
0 0 0 0
0 0 0 0

The max size of this piece is 3.

So when you rotate:

 ` void CVector::Rotate(int nSize){ int i,j; CVector rot; switch(nSize) { case 4: for(i=0;i<4;i++) { for(j=0;j<4;j++) { rot.SetAt(i,j, GetAt(j,i)); } } break; case 3: for(i=0;i<3;i++) { for(j=0;j<3;j++) { rot.SetAt(i,2-j, GetAt(j,i)); } } break; // pieces with the size of 2 (square) don't rotate case 2: return; break; } Clear(); for (i=0;i

Hope this helps.

- Mike

EDIT: When I get some time, I'll tell you how I did the detection of when the game piece has stopped moving and so on. =)

Edited by - mkaltner on January 5, 2002 3:28:12 PM

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

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

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631780
• Total Posts
3002314
×

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