Small Tetris Question

Started by
3 comments, last by Antheus 15 years, 5 months ago
I'm curious if you can give me an idea for a more effective way to go about drawing the blocks that are already down. My current idea is to have a spot an array to correspond with a specific row and column. And each time through the draw method I will take the array, run it through a for loop, and draw a square for each spot in the array that isn't "empty". While this way would work, it seems as though there would be a "better" way to go about it. If anyone has any ideas\suggestions it would be appreciated.
Advertisement
Quote:Original post by DarkZlayer
I'm curious if you can give me an idea for a more effective way to go about drawing the blocks that are already down.

My current idea is to have a spot an array to correspond with a specific row and column. And each time through the draw method I will take the array, run it through a for loop, and draw a square for each spot in the array that isn't "empty".

While this way would work, it seems as though there would be a "better" way to go about it. If anyone has any ideas\suggestions it would be appreciated.


The other approach that occurs to me would be to keep a list (or array) of all the blocks, and when it's time to draw, loop through the blocks and draw them. Each block would need to know its position, shape, and orientation, but you probably already need something like that for your gameplay code.

Of course it gets a little trickier when blocks get pieces knocked out of them (when rows get cleared), but you could break the block into small pieces when that happens.

That being said, I think the number of spaces in a Tetris screen is few enough that your approach would work fine.

Good luck,
Geoff
Worrying about optimizing a Tetris game? Will you even notice? Might you introduce new bugs if you improperly implement the optimization? Have you noticed poor performance that optimization would alleviate?

I don't know if it's true that pre-mature optimization is the root of all evil, but when I optimize my game, I want to be able to see that my efforts weren't fruitless.
Thanks gdunbar I ended up doing it the way I was thinking about doing it. Turns out it wasnt' as much of a hassle at all. Thinking about it seemed like it'd be worse. haha


Splinter of Chaos: It's not so much about optimizing it's performance rather than I have a perfectionist type attitude. A lot of the time when programming I tell myself "there is probably a better way to do this". This in the end causes me to stop working on projects so I need to get over this attitude and worrying about make the code "perfect" (if that was possible haha) and just get it working.

Quote:Original post by DarkZlayer

Splinter of Chaos: It's not so much about optimizing it's performance rather than I have a perfectionist type attitude. A lot of the time when programming I tell myself "there is probably a better way to do this". This in the end causes me to stop working on projects so I need to get over this attitude and worrying about make the code "perfect" (if that was possible haha) and just get it working.


The correct approach would be to analyze the rendering API/hardware, then choose the method based on that.

If you're using OGL/DX-based approach then one method may work that would not be ideal for GDI, or when accessing framebuffer directly, or when going back old B800/A000 methods that original Tetris used.

In order to find optimal way you need to evaluate the costs of each part - updating the block layout, cost of parsing this information, cost of drawing or deleting piece of screen (pixel/texture/sprite/character), cost of operations themselves, architecture cost and much more.

As it happens, Tetris is such a trivial case that quality of end result will depend predominantly on overhead.


But main decision to be made is simply - do you draw entire screen on each update, or do you merely try to update what has changed.

This topic is closed to new replies.

Advertisement