Blind Blocks: 13 hours in...

Andrei Marks · September 11, 2011

Well, so far my source code for the game is a sea of red text, for all my commented out experiments and tests. I’ll have to clean it up. Yesterday I finished side collisions and clearing lines, and thought about how I’d get the tetronimos down and rotating. I also added a preliminary drawing for the sonar, which I’ll have to improve and figure out how to add the proper collision detection to.

I did experience a moment of doubt about the approach I was taking when I considered I could probably just redo the whole thing with just a grid data structure and not even worry about collision detection. But then I decided it was all just part of the learning experience, and that it would help out with what I have in mind for the game after the familiar Tetris elements have been taken care of.

blindblocks13hoursBlock Composition

As for design decisions I made, I decided to keep the whole system pretty modular, with each tiny block as an atom. So the larger tetronimos aren’t individual shapes, they’re just groups of four blocks that drop together.

As soon as one of these sets of blocks hits the floor or the topside of another block, the blocks drop out of being the “current block” and join a list of “down blocks.” So the mass of blocks on the floor is really just a disaggregated mass of blocks.

Block Removal

Having individual blocks makes it easier for removal of lines, because I just take their centers and compare them to an invisible grid of centers. If the program notices that the list of down blocks contains a whole row from the comparison grid, it removes them. My next things to work on on that end are the removal of multiple lines at a time and then the “gravity” effect of moving all the blocks that need to be moved downward.

Tetronimo Rotation

Currently, I plan on creating each of the blocks in their original position up top, before they drop down. Block rotation is then simply handled by a list of relative translation coordinates. How many grid spaces up/down and over does each block in the tetromino go.

One of the things that is somewhat frustrating is knowing that there are conceivably ways to do it that would be easier. For instance, I’m sure there is some mathematical equation for rotation around a central point that could condense the amount of code I use in rotation. However, I don’t know what that equation is and I don’t know how what the tools needed to implement it are. Perhaps one day I’ll learn about it, but for now I’m just trying to hack the program out of what I already know.

Back to it!

Twitter, Facebook