Collision Detection
Understand how to detect collisions between tetrominoes and the game board boundaries in Tetris. Learn to create checks that prevent blocks from passing through walls, the floor, or other blocks, ensuring smooth and realistic gameplay.
We'll cover the following...
We'll cover the following...
Tetris would not be a particularly exciting game if all the blocks could pass through each other, or if the walls and floor did not stop them. So, instead of randomly moving the tetromino, we’ll check for potential collisions first, and we only move the tetromino if it’s safe. We have a few different collisions to consider.
We have a collision when the tetromino:
- Hits the floor
- Moves left or right into a wall
- Hits a block on the board
- Rotates and the new rotation hits a wall or block
There are no helper functions in Canvas for ...