Making an Atari game – Day 3

So I decided to take out the wall smashing code for now and work on the collision detection which has been bothering me. Remember that quick and dirty fix I did on Day 1? Well, I don’t like it. It’s just messy and not right.

I did a search online and found someone talking about collision ‘prevention’ on the AtariAge Forums. I never thought of this. This seems like it would be a lot better system. It might take up a bit more resources but should be worth it.

The difference between the two is that with collision ‘detection’ code, the collision with the wall has to happen and then you have to take the steps and send the player back to where he was before he collided with the wall. This was kind of glitchy, just knocking back the player. I mean it would kind of work but the player would stick to the walls at times, gave the walls kind of a sticky feel to them which isn’t very fun.

With collision prevention however, you just check a pixel ahead of the player in whatever direction it is heading. If there is a solid pixel (wall) there then don’t allow the player to move in that direction anymore. Sounds stupid simple and easy… However it took me all night to get it right. Trying to figure out where the Atari was placing the x and y location of my player sprite and checking all four corners of the player to make sure it could slide in between an 8 pixel wide opening. It was a lot of frustrating debugging… but….

Collision prevention
Buttery smooth collision prevention

I finally did it! Buttery smooth collision prevention! You can move that player all over the game world now, bumping into walls and gliding along side them and slipping through small openings, exactly how the player would expect it to behave. It feels so much cleaner, smooth, and fun. Really happy I decided to take the time to do this.

Next I think I might start working on what I originally planned to work on tonight. Making a random generated dungeon with multiple floors… I have an idea on how I should be able to pull this off.