8Bit Rogue

Moving Around

Moving Around


Now I need to handle moving around the screen. Currently, the joystick will move you areound freely, but flying doens’t make the most sense in this game, so I want to stick him to rails.

Basically, you’re free to move left and right on either the upper or lower floors, but you can only go up or down with a ladder.

Movement rails

To acomplish this, I’m going to lock the vertical movement unless you’re on a ladder. Because the ladders are drawn using the Playfield (and the floor you walk on is background), I can just check for PF-P0 collisions1 and only allow vertical movement during that time. As for horizontal movement, I need to prevent it while you’re on the ladder. I’ll have to compare Y positions and then snap the player to the floor when you start moving.

Adding vertical rails works,

except…

Because he’s still registering as colliding with the ladders, he can keep going down. I’m going to have to be more specific…

Adding in constraints on moving, and snapping to the top or bottom floor as you leave a ladder works quite well, however, now I have a problem: once you go up, you can’t get back down.

Stuck at the top of the ladder

Because the bottom-floor ladder doesn’t draw on the top floor, there’s nothing to trigger a collision, and therefore let me climb back down. I could draw an extra rung above the bottom-floor ladders, but since each screen is only going to have them conditionally, I can’t fit the extra 1 rung in my kernel if the top-floor ladder is also present.

I’ll have to manually declare three ranges of x-coordinates for each ladder, and test if they’re present to determine if you can climb up or down.

I came up with two rules:

  1. Up is simple: If you are colliding with the Playfield, you can always go up. There are no cases where you can climb up but there is no Playfield to climb on. This does mean the top of the lower ladders puts you a couple of pixels lower than the top-floor rail, but you can move horizontally onto the rail anyway, so I’m not super fussed at this stage.
  2. Down is complicated:
    1. If the bottom ladder exists AND you are between x-position 22 to 28 or 6a to 70, you can go down if your y-position is above the bottom floor*.
    2. If your position is above the top floor, you can always go down.

You’re never going to be above the top floor without a top ladder, so I don’t need any other tests there.

Let’s see how this looks now:

I think that’s good enough.

It’s nearly midnight, and I have work in the morning, so I’ll stop here tonight. I’ll add a climbing animation next.

Running animation

  1. The Atari 2600 makes things kinda trivial when it comes to collision detection, in that is does it for you in hardware: if it tries to draw two different things to the screen at once on the same pixel, it sets a register flag to true. You just need to look at those registers to see what’s colliding with what. ↩︎


Share: