DirectX and tetris...
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.
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)
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)
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
Click Here to download it.
- Mike
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
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.
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.
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<WIDTH;i++) { for (j=0;j<HEIGHT;j++) { SetAt(i,j,rot.GetAt(i,j)); } }}
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement