Tetris technical Questions...
Hey,
Ok I have a few questions.
First: Well I''m pretty pretty new to programming and I am trying to make a Tetris game. My first question is how would I check to see if any of the tiles are forming a row, and then how would I make it disapear. Do I create the shapes will lots of square sprites and move them together. Also, how the heck would I no when to stop a tile from going down becuase it is on a different tile. But the main question is how would I rotate the tiles when the user tells them to rotate.
Im using DirectX 7.0a and Visual C++ 6.0. If anyone can help me I would appreciate that. Thanks...
Later,
James
Click on the programming section here at gamedev.net and go to the Direct X section, then look for the "Code on the Cob" articles, that''s everything your looking for right there, more or less.
------------
- outRider -
------------
- outRider -
I´m starting similiar project also.
I planned to use big array.
In directX i´d use DXBLTFX to do rectangles but here´s some code.
I planned to use big array.
In directX i´d use DXBLTFX to do rectangles but here´s some code.
class Tile { //Constructors and such not interested now private: enum TILE_STATE{die,stationary,going_down}; enum TILE_COLOT{WHITE=0xFFFFFF...} }; Tile ** game_array; //Create multidimensional games array; while(!game) { if(!Current_Block->GiveDropping())//Block is set of tiles { Current_Block=BlockList.AddBlock() Current_Block->Randomize();//Sets color & shape Current_Block->Drop(); } if(Curren_Block->Landed()) { Current_Block->SetState(stationary); Current_Block->SetDrop(false); //Test for tile destroying } }
* Checking if row is full:
char board[BOARD_WIDTH][BOARD_HEIGHT];
for( y = 0; y < BOARD_HEIGHT; y++ )
{
rowIsFull = true;
for( x = 0; x < BOARD_WIDTH; x++ )
{
if( !board[x][y] )
{
rowIsFull = false;
break;
}
}
if( rowIsFull )
{
// remove row
memmove( board[y], board[y-1], y*BOARD_WIDTH );
memset( board[0], 0, BOARD_WIDTH );
y--;
}
}
* Rotating tile
Use something like this to define your tiles...
char tile[4][9] =
{
{
0,1,0, // up
1,1,1,
0,0,0
},
{
0,1,0, // right
0,1,1,
0,1,0
},
{
0,0,0, // down
1,1,1,
0,1,0
},
{
0,1,0, // left
1,1,0,
0,1,0
}
}
char* curTile = tile[0];
int curTileIndex;
if( rotate pressed )
{
curTileIndex++;
if( curTileIndex > 3 ) curTileIndex = 0;
curTile = tile[curTileIndex];
}
----
Cheers
char board[BOARD_WIDTH][BOARD_HEIGHT];
for( y = 0; y < BOARD_HEIGHT; y++ )
{
rowIsFull = true;
for( x = 0; x < BOARD_WIDTH; x++ )
{
if( !board[x][y] )
{
rowIsFull = false;
break;
}
}
if( rowIsFull )
{
// remove row
memmove( board[y], board[y-1], y*BOARD_WIDTH );
memset( board[0], 0, BOARD_WIDTH );
y--;
}
}
* Rotating tile
Use something like this to define your tiles...
char tile[4][9] =
{
{
0,1,0, // up
1,1,1,
0,0,0
},
{
0,1,0, // right
0,1,1,
0,1,0
},
{
0,0,0, // down
1,1,1,
0,1,0
},
{
0,1,0, // left
1,1,0,
0,1,0
}
}
char* curTile = tile[0];
int curTileIndex;
if( rotate pressed )
{
curTileIndex++;
if( curTileIndex > 3 ) curTileIndex = 0;
curTile = tile[curTileIndex];
}
----
Cheers
i wrote a version of tetris a couple of months ago the code + program is here
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement