Collision Course

I got collision to work in Paper Zeppelin yesterday, and now when you crash your little dude into the ground it does something. It’s kind of cute and it works like I thought it would. Also, I got ground to work, which brought up some interesting things. First of all, making the ground tiles 100 x 100 is way to damn big. I’m thinking that the resolution of PZ levels just got a lot higher. Second, and more importantly, it is really starting to look like a game now. I managed a kind of scrolling by making all the ground move to the left at a constant speed. Enemies move a faster speed, and it gives the impression that the world is scrolling smoothly by. TTT didn’t have any scrolling, and this new hotness makes me a very happy panda.
But that’s not really what this post is about. It occurred to me that this diary starts quite a bit after I had the initial insight into how collision systems in 2D could work in Thief, and I thought that now would be a good time to tell that story while also exploring the basic concepts of collision in a video game. So yeah, I’m going to get all talky.
Originally, way back in the proverbial day (I would say around diary entry number -25 or so) I had finally managed to get the little Zero character to animate and had worked out the basics for how the levels would be designed. I figured that if I made a series of rectangles, they could represent the level platforms.
For this, Blitz Basic had a cute function that allowed me to check if a sprite was touching a rectangle (technically if it was overlapping). So I threw considerable energy trying to get that to work, and it never did, not really. So it would let Zero stand on top of a rectangle, but it all fell straight to shit as soon as he touched another rectangle. There didn’t seem to be a way to get multiple rectangles to work right. He would touch a rectangle and find himself placed on top of it no matter what. So I tried to create a conditional system that asked questions like, “Are you above the rectangle? Okay, are you to the left of it? The right? Underneath?” But then you would hit a corner and I would die a little inside.
Clearly, there was a way to do this. What I eventually came up with is to create a box of rectangles around the player. Then I could check to see if those rectangles were touching the rectangles in the level. Basically, Zero never touched them, but his invisible force field did. Since each rectangle only had a single condition that was either true or not, it became much easier to track the collision of those rectangles. It also allowed multiple things to touch at the same time, which is why in TTT you can run into a wall.
Other parts of Thief were designed to work with pixel collision. Basically with that you take two different pictures (usually with a mask color that the computer ignores) and see if any of the pixels in those pictures are overlapping. This system is how combat kept track of hitting. Again, since the easiest and most basic concept for collision is an on/off proposition, this kind is useful, but limited. Especially if you want to have any kind of static collision like touching a floor.
Getting it back to Paper Zeppelin, I created a function that checks to see if rectangles are overlapping. I plug in 8 variables, representing the X,Y,W and H of each rectangle and then check to see if any of the first set happens to be inside any of the second. Granted, if I have really odd shapes I may get a weird overlap where that isn’t technically true (say a really wide but short and a really tall but thin set) but it works well enough for my purposes.

– Today the plan is to finish off the Collision system and add the rest of the ground pieces. The document says that different ground could reset the player in different directions, but now I’m just going have a standard collision set and make all the ground behave the same way. It seems like a better solution really. I am going to keep the different kinds of ground though, since it should be a simple addition and will make the levels look better.
The thinking is that I want a border on the ground that shows the actual boundary. But I really don’t want to keep track of that when I’m putting the levels together. So I’m going to add a little to the ground creation function that checks to see what the area around the ground piece looks like. So a piece with ground on three sides will create ground that only has a border on the open side, while a piece that is open on all sides will have a full border.
Admittedly it’s a bit of gold plating when the thing isn’t even built yet, but since that’s what the end product will entail, completely finishing that since I’m building it isn’t too bad. Well, almost completely. From a prettiness standpoint I’m also going to build in a randomizer for the colors to create variations of greens. But I can actually wait for that.

Leave a Reply

Your email address will not be published. Required fields are marked *