Tetris implemented in pygame using bitboards
I've tried dabbling with both Godot and Unity, but have never progressed very far with either frameworks. When I stumbled upon DaFluffyPotato's channel, I was convinced that doing pygame was definitely a viable option. Given that I work with python during my day job, this was the natural choice to try getting started in game dev again.
I experienced several issues with using collisions to determine if a particular action can be allow; If the current tetrimino is colliding at the bottom, we should lock said tetrimino and generate a new one. What I learnt quickly is that Rects need to be overlapping before it is considered a collision, and my naive solution led to tetriminos getting locked when they are touching at the corners. On hindside, I could have easily adjusted the Rects in the relevant direction when I needed to do collision checks, but my pea brain couldn't figure this out.
Instead, I went back to bitboards, which I've used previously when trying to build a chess game. A bitboard is essentially a binary number where 1's indicate where a particular cell is occupied. A J block can essentially be represented as
001
111
What this allows me to do is I can have a number that represents the state of the board, and shift the active piece around the board to check for collisions. Once all the checks are completed, I can then translate the binary number into a set of coordinates for rendering.
-
Clearing of lines
- Identify tiles that should be removed
- Drop tiles by the number of removed lines
- Render effect of clearing lines
- Render effect of dropping tiles
- BUG: Clearing more than 1 line results in negative shift count bug
-
Game UI
- Center main game in middle of screen
- Add next piece UI
- Add stashed piece UI
- Add score counter
- Add ghost piece
-
Scoring
- Implement scoring mechanism based on lines cleared
- Render scores
- (?) scoreboard
-
Piece stash
- Allow player to stash the existing piece and call the next piece if stash is empty
- Allow player to swap the current piece with stashed piece
-
Scenes
- Add main menu screen
- Add pause screen
- (?) Add high score screen
-
Polish
- Add fancy background with falling tetriminos
- Having fancy falling tetriminos respond to user input
- L-Gad Tetriminos Pack