iDevGames Forums
Slopes in Side-Scrollers - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Slopes in Side-Scrollers (/thread-7751.html)

Slopes in Side-Scrollers - Bachus - May 21, 2002 12:36 AM

Has anybody ever seen a tutorial on how to do sloping surfaces in 2D side-scrollers? Or better yet, does anyone have the source-code to a Mac game that had sloping surfaces?

I'm mostly having a hard time figuring out how to do the collision detection. Since my game is tile-based the easiest way to handle collision detection is to check the sprite against the tile. If the tile is non-passable, don't let the sprite enter the tile. However, sprites need to be able to enter part of a sloped tile. And the character needs to be able to over-shoot the tile by a bit other wise the character will look like it's floating in mid-air. It just really makes my head hurt thinking about the whole thing.

If you have no idea what I'm talking about when I say sloped-surfaces play Ferazel's Wand. It's got slopes up the wazoo.

Slopes in Side-Scrollers - Carlos Camacho - May 21, 2002 01:50 AM

I don't know the tools you are using, but did you look at Spriteworld?

Slopes in Side-Scrollers - Bachus - May 21, 2002 03:54 AM

Oops, I guess I should have mentioned what I was using. I'm using Project Builder and coding in Obj-C for Cocoa. I've used parts of SpriteWorld in the past and I don't think it has what I'm looking for. Actually, let me check on that real quick...

Nope, I couldn't find any info on sloped surfaces in either SpriteWorld or SAT. However, I did remember that Abuse has sloped surfaces and I have the source for that. Too bad the source is absolute hell to look at.

Slopes in Side-Scrollers - kainsin - May 21, 2002 08:13 AM

Now it comes time to move from fully tile-based programming ( can move/can't move logic ) to pixel-based collision detection.

Simply put, you're going to want to try to make it so that when the character-object moves, instead of just saying "Hit a tile", say "Hit this much of a tile: [a rectangle of intersection between the player-object and the tile]".

Now take that rectangle of intersection and test all of the pixels of the player-object with the overlapping, non-transparent, pixels of the tile. If any of them overlap ( or are one pixel away from overlapping if you're doing pre-emtive collision detection ), then there was a collision and you can stop the player-object from moving.

Slopes in Side-Scrollers - swcrissman - May 21, 2002 03:47 PM

If you still want to do simple tile collision detection, you could simply assign a series of height values to the terrain in each terrain tile, and then draw the character at the tile's y location plus that height offset. This would allow you to simply do tile collision detection, if I'm thinking correctly.

For instance, say you want your terrain to be able to slope and you want to divide each tile up into say, 20 possible positions. Each tile then would have 20 tile height values associated with it. When a player moved onto a tile, first you'd check and see if they are able to land on it, using the same formula you are using now. Okay, so they've landed, now how far are they across the x axis of the tile? 50%? Okay, so look at the 10th height value and see how high above the base of the tile you should draw the character. Say you find a 10. Great, when you draw the character, draw him at the level of the tile, +10 y pixels.

Now, assuming the slope is going up and to the right, as the character moves further across the tile, the y value offsets associated with the tile will increase a bit, so he'll be drawn a bit higher than before.

I've never done this kind of stuff, so maybe I'm way off base, but it seems possible to do it this way. I don't know how complex your game is, but assuming its fairly simple, then this should work fine. If you're doing something complex, you probably just want to move on to doing per pixel checking. Basically, doing it this way doesnt add slopes to your game engine, it just makes your renderer draw the character as though he is moving along a slope. Obviously, the more accurate you want things to look, the more divisions you'll need in your array of heights for each tile.

If you're bouncing things off the ground, this will work pretty terribly, as everything will bounce as though the ground is flat, but be drawn as though its hitting a slope. Obviously not what you'd want to happen, but if you're just making a mario style game where you just need to see if the character is on the ground or not, this should be fine.


Slopes in Side-Scrollers - Carlos Camacho - May 21, 2002 05:26 PM

You might also pick Chris D's brain since he made a side-scroller "Death from Above."

Slopes in Side-Scrollers - Griggs - May 21, 2002 10:58 PM

swcrissman, I have used that very technique sucessfully. Just remember to check the vertical lookup table (basically just a simple array) when calculating the collision before the player has already entered it when falling. Otherwise the last update could bring the player only a couple pixels down, which after falling faster than that in the last frame looks awfully strange.

Slopes in Side-Scrollers - Bachus - May 22, 2002 07:43 AM

Thanks everyone! The height lookup table is similar to idea that I had. Each tile whould have a slope (rise over run) that would be used to calculate the vertical acceleration of the sprite. The lookup table is probably a more complicated way to go, but may be faster as it should take less calculations.

I'll try everything and hopefully find the best way through sheer experimentation.

Slopes in Side-Scrollers - Unregistered - Jun 5, 2002 08:06 PM

You know, I have to add a little bit of brevity... You could just make the player's sprite really, really, really big. ^_^

alternately, the super mario bros approach could be followed-- don't make anything that is less than a tile large. ^_^