How does Tetris work?

Blitz3D Forums/Blitz3D Beginners Area/How does Tetris work?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

The best way to find out is to try. I remember when I first wrote my Tetris (called Twatris!) clone, I sat and thought things like:

"Right, I know where the shape is, how do I see if it's about to land on a block in the playarea?"

That ended up being the most complex part of the whole program. Pen and paper was used to figure the logic for that one!

If you loop through the shape%() array and compare it with the playarea%() array (but one 'block' below current chape's position) and you see a 1 there, you know you're about to land the shape. If you've looped through the whole shape%() array and a 1 never appeared, you know you're safe to lower the shape on the next update.


pseudocode

safetodrop=true
for y=0 to 3
for x=0 to 3
if playarea(x + current_shape_x , y + current_shape_y + 1) = 1 and shape(x,y) = 1 then safetodrop = false (there is an obstruction, we're about to land).
next
next

You have to cater for when the shape is at the bottom of the playarea (so that you dont try and check the playarea() array for a y position out of bounds). Essentially though, that's how you 'do' Tetris.

checking for filled lines in the playarea is quite simple and shouldn't present much of a problem.