🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

deleting objects

Started by
2 comments, last by llvllatrix 18 years, 1 month ago
Hi. I am trying to create a simple 2D tetris game for my school project and I am having troubles coming up with a function to delete the line which has been filled in. I saw the NeHe's Lesson #21 and tried to imitate how he used the vline and hline to keep checking. Any suggestion will be greatly appreciated. Thanks in advance.
Advertisement
Since this is for school (generally frowned upon), I'm not going to give you a complete solution. Such a solution depends highly on your implementation, anyway. So I'm going to assume you are representing your playfield as something that can be viewed as a 2D array of boolean values -- either there is a part of a block here, or there is not.

Once you've determined that a line is full and should be deleted, it should be a fairly simple matter to go through every block that is a part of that line and mark is as "empty." It should be very similar to how you go through every block that is part of the line and look to see if it is empty or filled.

You can then procede to manually shift the blocks above it down, or simply continue on your way and let the usual "falling" logic move the blocks for you (if possible).

There are various optimizations you could make, of course, but this should get you started.
But wouldn't that take up too much memory?

As you go on the game, if you simply move the filled line out of the screen, it still would be stored in the memory and as the game proceed it will be slowed and slowed.

Especially, for my school computer which doesn't have a great video card (we have TNT2 38MB)
The size of the array does not change. All you change is the value at a given position in the array. For example, lets say you have a 3x3 playing grid. If 1 represents a block and 0 empty space:

// Test grid:0 0 11 1 11 0 1// To delete the middle line, just set the middle row to 1's:0 0 10 0 01 0 1// And then, on the next update, the game finds that the 1// doesnt have any support and can be moved down.0 0 00 0 11 0 1


The trick to making games is mostly trying to store the current state of the game. Once you find an elegant way to do it the rest of the game tends to follow easily.

With regards to your preformance issues speed usually has nothing to do with memory. How fast your game runs is in general preportional to the largest number of nested loops in the update path. This type of preformance analysis is called BigOh analysis.

Cheers,
- llvllatrix

This topic is closed to new replies.

Advertisement