Tuesday, December 3, 2013

Ramps are weird

So I've got most of the real core of Robo-Ninja complete. Not that that means I'm anywhere near complete. The basic core (map loading, characters moving and animating, collisions, etc) is the easy (and fun) part. The details are what takes all the time.

Anyway, after getting the basics of collisions working, I suddenly decided (for reasons I haven't really figured out) that I needed to add ramps. I wish I would have been smart enough to think of that earlier, as my design for collisions didn't really take ramps into account. And ramps are weird.

Overall, wall collisions are pretty easy, although slightly harder in a game like Robo-Ninja than they were in Anguna. In Anguna, you just check for collisions, and revert the character's position if he collided with a wall.  There were a few other gotchas, (type of wall, since you can sometimes walk over water. Or checking vertical collisions separate from horizontal so you could "slide" diagonally across a wall), but it was easy.  In Robo-Ninja, vertical collisions need to work similarly (walls above you will suddenly stop any upward velocity. Walls below will stop downward velocity). But horizontal collisions will make your guy suddenly switch directions.

Now ramps. Now we've got a collision that, being a diagonal ramp, is suddenly a vertical AND horizontal collision at the same time. And it should not only change your vertical velocity (stopping downward momentum), but also your position (as it needs to nudge you up vertically if you are moving left, but not send you jumping up in the air). And the tiny magic intersection tile between ramp tiles is really a normal tile. Which meant if Robo-Ninja moved a tiny bit too far forward in each frame, he'd collide with THAT tile instead of the actual ramp tile, and decide to turn around and run the other way.

I can't tell you how many times I kept bouncing off that highlighted tile until I  stopped being dumb and fixed my code.
Anyway, none of that should actually be hard. But it would have been a whole lot easier if I had decided I wanted ramps BEFORE implementing the rest of my collision code, so I would have actually designed with that in mind. Oh well. It works now.

Now I'm on to items/powerups, and the UI associated with them.

No comments: