Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tetris - and how to change the shape of the blocks 1

Status
Not open for further replies.

lirf

Programmer
Aug 11, 2001
1
IL
Hi all! I found a good code for tetris and played around with it, but I don;t know how you can change the shapes of it. If anyone has a code written, and could show me how to maybe change the shapes, it would be of great help...

PLEASE HELP!
 
could you shaer the code with me? I have some code, but is in BorlancC++. John Fill
1c.bmp


ivfmd@mail.md
 
I was working on a tetris clone a while ago. I plan to pick it up in a couple of weeks. The way I solved the changing of the blocks is like this -> Imagine that the playing field to which the blocks are dropped is one big grid. How can we implement this grid in code? By means of a 2-D array (playingField[y][x]). Now imagine that your prog randomly selected the long block to drop next. You know the one that looks like this "1111" (Excuse the graphics). Lets say the player wants to shift the block right. How do we do this? Well lets say our 5x5 grid looks like this and "0" means empty space ->
00000
00000
00000
00000
00000
Now when the long block is first dropped the grid (2-D array)will look like this ->
00100
00100
00100
00100
00000
Do you notice how the long block is represented by the 1's?
Now since we know where the block starts in the 2-D array index (0,2), we can shift the entire block to the right like this ->
00000
01111
00000
00000
00000 <- Of course some collison detection code will need to be written.

It's all just a matter of manipulating the contents of the 2-D array. Once you break it down into that, it all becomes very easy to implement. Now as for the graphics part, try to seperate the actual logic from the graphics. Do the manipulation in the 2-D array first, then read the 2-D array (playingField[y][x])from top to bottom blitting the right blocks where they are supposed to be. All I did was perform the neccessary adjustments to the playingField[y]x],then by means of the DirectDraw API, blitted the correct sprites onto the window by scanning through the playingField[y][x]. So if I detected a 1 then -> Blit green block at x,y coords, or if 2 was detected in playingField[y][x], then blit red block at x,y coords, or if 0 detected then empty space is found etc...It's a litte hard to digest but this is only one way to tackle the problem. Hope this helped. mlg400@blazemail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top