views:

349

answers:

4

I'm making a Tetris Clone in C# with XNA, and I'm unsure of how to actually implement the blocks.

I don't think that making the shapes as images will work (because parts are removed when lines are formed), so I Have blocks to make up the pieces like This.

Unfortunately, I don't know how to actually define the blocks to make the pieces, nor do I know how to manipulate them to make them rotate, etc.

Edit: I would also need assistance in learning how to make the Tetris Grid too.

+1  A: 

Use a boolean matrix to model the state of the screen. Each piece is itself another smaller boolean matrix.

Rotating a piece is as simple as playing with the coordinates a little bit (I left this to you).

About how to render, just draw a piece tile for each true value in your matrix ored with the current falling piece shifted and rotated.

fortran
+1  A: 

I haven't created tetris before, but after some thinking, I believe that I would use a simple matrix to create my pieces. For example, your whole game board would be one big matrix. A subset of that matrix, say a 4x4 block of it, would be a game piece. Which parts of that 4x4 block would be filled would be determined by which particular piece you want to create. Each part of the matrix can have a boolean flag that would indicate if it's filled or not. This is a very simplistic view of it, but I think it's a viable solution.

Aaron
+1  A: 

For the blocks, I would strongly suggest working in 3D. You can still make the game look like 2D by locking the camera etc, but you will benefit a lot from working in vector graphics. Your blocks will be simple cubes (flat or with some depth) that you rotate and move around the screen.

For the grid, look at @fortran's and @aaron's answers, a boolean matrix will do the trick.

Peter Lillevold
+1  A: 

Maybe this link to Coding4Fun will help. It's in german, but you should be able to get the source code and take a look on how about the problem is solved here.

Just to be sure, here the direct download link.

Oliver