In my first post, I was happy that I managed to create and render the Tetrominos, make them interact with the walls and floor of the grid, and make them fall down. In this update, I added the core mechanics: random spawning of tetrominos, creating “the stack”, freezing tetrominos when they hit the floor or the stack, line clearing logic, fast drop.

Learning:
- Tetris is a lot harder to make! At least when comparing it to something like flappy bird. The line clear logic was difficult to wrap my head around especially since there exists three variants [link]. I implemented the naive version by first identifying all rows that are filled and can be cleared, and then creating an “offset array”, that stores by how much each line needs to move down after a line clear. So all rows above a single line clear move down by 1, all rows above 2 line clears move down by 2 and so on. Rotation of tetrominos against the wall is still not perfect. Still need to wrap my head around building wall kicks.
- Having said that, I loved how fairly easy it was to improve the experience with few lines of code; like using lerp function to build a slight acceleration when switching from normal speed to fast drop speed. Also, instead of complete random spawning of tetrominos, I could implement the 7-bag random spawning using few lines of code and array methods like shuffle and pop.
- Separating game logic (using array of “block” objects) from block rendering logic (using TileMapLayer and TileSets) makes it very easy to make changes in future. I added a block class that stores the tile information and helps me easily create different tiles and colors for each tetromino and the stack.
- Still need to get better at debugging. I made a grave mistake in the code by directly assigning value of one block object to another (instead of deep copying) and that took half a day to figure out and fix.
Next Steps:
- Advanced mechanics (“sticky” line clear logic, wall kicks, DAS), scoring system, game over logic.
- Build my own graphics and sounds
- Make my own “Twist” to the classic game. Currently I’m thinking on the lines of Tetris meets Wordle. I have not seen a good adaptation of it online yet. Open to suggestions.
Time spent so far 15 hours.
Still having a lot of fun. Lots of gratitude to this community for solving my doubts and encouraging me to continue to learn.