Into the Platform Game Engine (Part 2)
Hi everyone!
Last time we saw Little Ninja running and jumping, and I promised to make him walk in slopes and hang in walls (after all, we’re talking about Little Ninja™ here). Well then it’s time to learn about Little Ninja’s new moves!
Walking on slopes (terrain angles)
The first thing I’ll solve today is having the Ninja walk on different terrain angles. As of now, there are three terrain types if you remember, but Mr. Ninja can only walk on two of them as for now:

When the Ninja walks on flat terrain, his X position changes (left and right). Well, what happens when he walks on slopes? His Y position changes, too (up and down)! In the 45° slope, for every X+1 pixel he moves Y+1 pixels, while on the ~26° slope, for every X+1 pixel, he moves Y+½, (but remember that pixels can’t be divided).
An important aspect is knowing when his Y position changes. For this, we have to use the sprite’s CENTER position. Whenever the Ninja jumps on a slope his Y position must be calculated too based on his X.
![]()
New Ninja States: Wall Hang and Double Jump (somersault flip)
A Ninja that can’t hang on walls or randomly somersault in the air defying all physics laws is definitely not a skilled one!

Anyway, wall hanging was pretty simple to do: Basically, when the Ninja hits a wall and you hold the direction on the d-pad (right in that case), he’ll hang on the wall and slide.
As for the double-jump, after performing a normal jump, jumping again while hanging in mid-air makes Little Ninja perform what is normally called a “double jump”, allowing him to move a little higher and a little further too!

Well, besides these two new states and slopes, I also added background scrolling, which I’ll try to explain more detailed later on. And as always, here’s a video (well GIF actually) of Little Ninja in action!

It’s starting to feel very versatile with the new moves and I’m sure that as soon as he runs and slides things are going to get even more exciting. Stay tuned for more Ninja action!




December 15th, 2008 at 11:03 am
Hi, nice work =)
I’d like to know, if it would be possible make a ps2 port after you finish the game ^^
thanks, see ya! xD
January 26th, 2009 at 8:19 am
Hi.
First off all, congratulations for your project and this great material you post here. I’ve discovered you web site recently and I am really excited about the ideas you gave me on my own efforts. I’d like to ask you about the slope algo you described. In you example, on a 45 degree slope, you move Y + 1 for every X + 1 pixels. Considering that image. When the ninja is at the first tile of the slope, all you have to do is to increment his Y based on the X distance he walks (dx). What do you do for the next tile? You use the same algo but adds some base, so that as he walks you adjust his Y position?
Thanks in advance,
Andre
Sao Paulo – Brazil
February 11th, 2009 at 3:52 pm
What does the flashing text say lol it flashes every now and then it says FLANO !! or something like that and also fix …shows up
February 14th, 2009 at 8:37 pm
@AZanshin: It actually says “PLANO” which means “plain (terrain)” in Spanish
@Andre: Thanks! As for the next tile, the way we do it is checking the tile next to him, which may be a possible land. So, if he lands on a different tile (x % 16 != xd % 16) Little Ninja will follow the rules of the tile next to him, not the one he’s on, and as you say, adjust the Y position. Let me know if this is clear or if you need any further explanation
March 4th, 2009 at 11:38 pm
I usually don