[Tetris Game Algorithm]
ghetto-boyz
Posted messages
12
Status
Member
-
twintris -
twintris -
Hello everyone!
I have a project to create a Tetris game and I have no idea how to do it!
I'm not asking for a complete source of the game but just an algorithm or just an idea on how to do it!
I need it as close as possible and I thank you for your help!
See you!
I have a project to create a Tetris game and I have no idea how to do it!
I'm not asking for a complete source of the game but just an algorithm or just an idea on how to do it!
I need it as close as possible and I thank you for your help!
See you!
4 answers
Having made one, I can give you some hints.
A matrix for the play area, filled with booleans.
Each piece is a 4x4 matrix.
For example:
0100
0100
0100
0100
for a line or
0000
0110
0110
0000
for a square.
The piece is redrawn with every movement (movement, rotation).
Every time a piece can no longer descend, you check if you have a complete line. If so, you destroy the line and shift the rest of the pieces down.
It's not very complicated to do, however there are subtleties, especially regarding redrawing your play area after destroying 1 or more lines. That's where the real difficulty lies.
Good luck!
A matrix for the play area, filled with booleans.
Each piece is a 4x4 matrix.
For example:
0100
0100
0100
0100
for a line or
0000
0110
0110
0000
for a square.
The piece is redrawn with every movement (movement, rotation).
Every time a piece can no longer descend, you check if you have a complete line. If so, you destroy the line and shift the rest of the pieces down.
It's not very complicated to do, however there are subtleties, especially regarding redrawing your play area after destroying 1 or more lines. That's where the real difficulty lies.
Good luck!