Race game is a smaller 2D SFML project I did to challange my self with collisions. The game includes a track creator which means that if the player makes a complex map or a simple map my game still has to handle it in a good way. One big goal I set from the start was pixel perfect collision detection which sounded like a fun and tricky subject.
Track Creator
This work by placing vertices and then drawing edges between them. First you make a outer track then an inner track. More features are planned like being able to make intersection or bridges.
Pixel Perfect Collision
The first approch to this was to follow the walls of the track and place a box collider for every pixel, this lead to performance issues quite quickly. This lead to me making a system for turning them on and off based on distance altough this system was quite slow and very hard to work with. So after learning of matrices in a math course I adapted them to be my collision detection. This work by having four very long lines paralell to the cars shape. Then solving these matrices to find how far away the solution is and if the distance from soultion is negative or zero you have a hit.