views:

270

answers:

4

Hey,

For university we're supposed to write a game (the language is modula2 little chance you know it). Each tetromino is defined through a central piece and 3 relative pieces, Now when it comes to rotation i just rotate the relative blocks (linear algebra).

What i am asking myself is how to handle the rotations a user does when the piece has already "landed" because than the user has a little time left to move his pieve quickly into the desired position but in tetris versions all over the web you can "rotate over" other pieces, but i dont seem to get it with my rotation.

Over what piece do i need to rotate? are there guidelines? Thanks

+2  A: 

If I understand your question correctly, there is no right answer. Whether you can "move through" other pieces depends on the guidelines for your particular assignment; it's possible to write code that allows it and code that doesn't.

Lord Torgamus
+5  A: 

The Tetris Wiki specifies one way these so-called wall kicks are done:

A wall kick happens when a player rotates a piece when no space exists in the squares where that tetromino would normally occupy after the rotation. To compensate, the game sets a certain number of alternative spaces for the tetromino to look. [...] The simplest wall kick algorithm [...] is to try moving the tetromino one space to the right, and then one space to the left, and fail if neither can be done.

There are other ways, such as the one specified by the Super Rotation System mandated by the Tetris Guideline. That system uses a set of tables to determine the possible wall kicks.

Thomas
+1 for sharing the existence of the Tetris Wiki.
Cheeso
A: 

Considering that field the tetris pieces fall are a matrix

1) If you want to give a little time for the user to rotate it and using your algorithm

  • Set a timer that starts when your lowest block is on a line adjacent to a line which the same column already has a piece.
  • If the user try to move that piece before the timer ends, check if there is a block on a line and column on which could be the place of one of the blocks of the movable piece. If it is already filled you can't move it

2) If you want to give a little time for the user to rotate it and using other algorithm

  • you can consider your block as a 3x3 cube and rotate it though the 2x2 block even if that doesn't exists on the piece (for example on a piece with the L format). So you just need to do what I said on the 2nd button of (1), and it should be fine! Thats an easier algorithm IMHO.
Diego Dias
A: 

First of, you might want to clarify the terms in your question. In the first paragraph it seems that a "piece" is what others might call a "tile"; i.e., each tetromino is composed of four "pieces" or "tiles". But then at the end of the paragraph you call it a "block". And then, in the second paragraph it seems that "piece" is synonymous with "tetromino": "the piece has landed", "move his piece". So in your question, what do you mean? Perhaps "Which tile should the tetromino rotate around?"

If that is indeed your question, the answer is it's implementation-defined. If you try different versions of the game, you may see that in some, the "I" piece will wobble left-right or up-down as you put it through two rotations (the rotation tile is fixed on the tetromino), and in others it will not (the rotation toggles between the two center tiles such that a CW rotation will have the same effect as a CCW rotation). The "S" and "Z" pieces will similarly either wobble or not. If they don't wobble, though, you might find that a piece will be able to rotate when it's against the left wall but not if it's against the right, even though the situations should be symmetrical. And the square piece, if you leave it with a fixed rotation tile, will rotate around a corner when in all likelihood you want it to (appear to) not rotate at all. I've never seen an implementation that doesn't at least take care of that!

Paul Richter