Saturday, August 13, 2011

I have to create a Tetris game in Java. How do I define bounds? Here is what my code looks like so far.?

Hi, I've never made a tetris clone but I've thought about it some. The important thing is that each piece is really composed of individual squares. It is these squares that should be checked for bounds.. this will make things a whole lot simpler. Or another way to put it is that there really are no pieces - just squares. So when you hit the left or right arrow keys you're really moving 4 separate squares in tandem. For example if one of the falling squares discovers a 'resting' square beneath it, then it will stop falling along with the 3 other falling squares. And it's the same if an individual falling square discovers a floor or wall grid value. It's the same for rotation.. if the projected location for a rotated square is 'full' then the rotation must not be carried out. Otherwise it is free to rotate along with the 3 other related squares (and all 4 squares must be bounds tested before the rotation is allowed to happen).

No comments:

Post a Comment