28: Planning Revisited
I thought it’d be weird to drop a hardware post in this week as I’ve not finished the Tevris game yet, so this week’s post will continue the Tetris theme and then there will be a Cardboctober Week 4 round-up at the end.
I think Tevris is a very good example of a beginner game development exercise for this reason as it provides a lot of 2-dimensional array manipulation, collision algorithms and very testable rules.
The one thing that constantly blocks me (hoho!) with building Tevris is the collision detection. Tetris is a game that has been around for a long time, and all of it’s game logic is codified in various languages. The collision algorithm should be simple to drop in – but with Tevris it hasn’t worked out that way yet.
I keep hitting walls (hoho!.. alright I’ll stop.) with off-by-one errors, and general weirdness. I think this is down to a lack fo structure/planning upfront in the build of the game, which is why I’ve written it from scratch a couple of times as I find a new challenge, and why I’m in the process of another complete re-write.
Planning revisited
The tetris board is a 2-dimensional array that is 10 cells wide and 22 cells tall. Though it’s 22 cells tall, we only actually use 20 of them as the playable area (with 2 used for buffering the top of a shape without being out of bounds).

There are 7 different types of piece in a traditional tetris game: I, T, L, J, Z, S and O. Here is how each of them look in the default rotation:

The marked square in the middle of each piece is the point that the piece will be rotated around.

When spawning, a random piece with a random rotation is placed at the top of the board. This piece is positioned so that the marked square is at the top/center of the board:

The piece can be moved along the x-axis by the player. The piece will automatically drop 1 block at an interval along the y-axis, but can also be manually moved downwards on the y-axis.
If the piece gets to the left or right edge of the board, the piece should not be drawn beyond the edge of the board.
If the piece collides with a filled square on the board, it should be merged with the board.
If the piece reaches the bottom row of the board, it should be merged with the board.

So now that I’ve got that written down somewhere, I can continue with my big re-write and hopefully have something working by the end of Cardboctober!
Cardboctober Week 4 recap:
Day 22
Day 23
- Planning Tetrominoes in VR (Max)
- iOS North (Pete)
Day 24
- Basic Game Board (Max)
- Bullet time (Pete)
Day 25
- Creating and Moving Pieces (Max)
- Smart device pairing (Pete)
Day 26
- Rotating Pieces (Max)
- Laser battle (Pete)
Day 27
- Moving with gaze 💩 (Max)
- Hairy ball (Pete)
Day 28
- This post (Max)
- Beer (Pete)
Cardboctober day 28
Check out all of my other Cardoctober posts here: /cardboctober.