Jump to content
  • Advertisement

Archived

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

pizza box

Help with Tetris Function

This topic is 5995 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 creating a Tetris-clone in C++ using DirectDraw4. The main gameplay area consists of an array of integers 10x15 that will hold either a 1 or 0 to determine if that place if occupied. I have created a function to test if a line is full, and then to clear the line, but I am having a problem thinking of a solution on how to lower the whole grid by one step. Heres an example: 0 0 0 0 0 0 1 0 1 1 1 0 1 1 1 1 <- I want to clear out this line 1 1 0 1 I call the function and it sets all the numbers to 0 0 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 <- Set to zero to clear out the line 1 1 0 1 Now my problem is how to lower all the numbers above the line so they fall down one step. I''m probably overlooking a really simple solution, but I keep getting stuck here. Thanks for any input.

Share this post


Link to post
Share on other sites
Advertisement
Two for loops should solve your problem.
For example, if Lines[10][15] is an array of all of your lines, and ErasedRow is an integer specifiying the row you just cleared, you should be able to shift each row down by doing the following:

for (int i=ErasedRow; i>0; i--)
for (int j=0; j<15; j++)
Lines[i-1][j] = Lines[j];

Then you just need to clear your top row.

Share this post


Link to post
Share on other sites

  • Advertisement
×

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!