I'm watching a tutorial on how to make Tetris and I'm completely lost trying to understand how to represent the different rotations of pieces.
The tutorial references the 2009 Tetris Design Guide, particularly the slide on Tetrimino Facings:
Relevant Code in the video starts at 1:10:27
The below code represent tuples indicating coordinates at which every piece rotates around.
Kind::O => &[(0, 0), (0, 1), (1, 0), (1, 1)],
Kind::I => &[(-1, 0), (0, 0), (1, 0), (2, 0)],
Kind::T => &[(-1, 0), (0, 0), (1, 0), (0, 1)],
Kind::L => &[(-1, 0), (0, 0), (1, 0), (1, 1)],
Kind::J => &[(-1, 1), (-1, 0), (0, 0), (1, 0)],
Kind::S => &[(-1, 0), (0, 0), (0, 1), (1, 1)],
Kind::Z => &[(-1, 1), (0, 1), (0, 0), (1, 0)],
Can someone explain to me this representation system please?
Example with J [(-1, 1), (-1, 0), (0, 0), (1, 0)]
:
(y)
3
2
1 A
0 B C D
-1
-1 0 1 2 (x)
where
A = (-1, 1)
B = (-1, 0)
C = ( 0, 0)
D = ( 1, 0)
(0,0)
(here C
) is the center of rotation.
To rotate, do this transform for each block :
(x, y)
=> (-y, x)
(x, y)
=> (y, -x)