Tetriminos (Shapes)
In this Tetris game, I use 7 shapes. While some versions only include 5 shapes, I’ve added two extra ones: the J and S shapes, which are mirror opposites of the L and Z shapes, respectively.
Each shape consists of 4 blocks, and each block is called a Mino (short for monomino). A group of 4 Minos forms a Tetrimino (also known as Tetromino or Tetramino). For consistency, I’ll use the term Tetrimino throughout this article.
Coordinate System
- Coordinate Transformation:
- The function offsets input coordinates:
- x becomes x + 36
- y becomes y - 12
- This allows negative coordinates (e.g., (-36, 12) maps to the original (0, 0)).
- Purpose:
- Centering (0, 0) simplifies calculations for symmetric gameplay elements (e.g., rotating Tetriminos around the origin).
- Negative coordinates enable intuitive positioning relative to the new origin.
Rotation and Translation
v = (x, y) , T = (x', y') then v' = v + T = (x + x', y + y')
so, v = (0,0) T = (0, 12) move to v' = (0+0, 0+12) = (0,12)
v = (x, y), R = (cos Φ - sin Φ, sin Φ + cos Φ) then v' = R . v
v' = (x cos Φ - y sin Φ, x sin Φ + y cos Φ)
we rotate Tetrimino only by 90 degrees so cos Φ = 0, and sin Φ = -1 so final rotation vector is
v' = (y * -1, x * 1), anticlockwise
v' = (y * 1, x * -1), clockwise
so (2,3), clockwise rotation is (3*1, 2*-1) = (3, -2)
Let's take a line shape Tetrimino as an example and discuss how we have implemented in game.
We always draw Tetrimino at the center of axis so that while rotating it will rotate by its own center of body. Initial coordinates of line are (0, 2), (0, 1), (0, 0), and (0, -1).
Coordinates after clockwise rotation are (-1,0), (0, 0), (1, 0), and (2, 0).
Coordinates after translating by (-3, 7) are (-4,7), (-3, 7), (-2, 7), and (-1, 7).
No comments:
Post a Comment