Mega Man style ladders (4.5.9 platform module) ***UPDATED***

baardbi

Well-known member

Thanks to dale coop for a fix to this code!

Ever since the first NESmaker I have not been completely happy with how ladders are handled in platform games. I want my character to stop moving when I release the D-pad. I also want my player to snap to the ladder, so that he doesn't climb up the very left or right edge of the ladder. As far as I know this should work in any of the platform modules.

Here's what I did:

1. In the middle of the input scripts climbLadderUp and climbLadderDown put the following code after these lines:

;; there is a ladder under my feet..
LDA Object_y_hi,x
CLC
ADC #$01 ;; ladder speed
STA Object_y_hi,x


LDA tileX
AND #%11110000
;; Add or subtract player offset here if
;; you need to adjust the player position
;;
;; -- Subtract offset:
; SEC
; SBC #0 ;; Player x position
;
;; -- Or add offset:
; CLC
; ADC #0 ;; Player x position
;;
STA Object_x_hi,x

Your player will now snap to the ladder perfectly every time.

So now for the animation part. You need to have two action states for your player reserved for climbing. One for the climb animation and one for "idle climb". Use action state 3 for the actual climb animation and action state 4 for the "idle climb" (you can use one of the climb frames or make your own idle climb frame).

2. In the input script changeActionToStop change the part under changeToStop_NoDpadPressed to this:

changeToStop_NoDpadPressed:
GetActionStep temp
CMP #$03 ; Are we climbing?
BNE normalIdle
ChangeActionStep temp, #$04 ;; assumes that "climb idle" is in action 4
JMP doneChangeToStop
normalIdle:
ChangeActionStep temp, #$00 ;; assumes that "idle" is in action 0
doneChangeToStop:
RTS

3. In the Input Editor you need to add the changeActionToStop script to "release UP" and "release DOWN" on the D-pad. It should look like this:
Skjermbilde.PNG

That's it! Your player should now snap to the ladders and stop the animation when the D-pad is released.

Let me know if I missed something or if I made a mistake when writing this tutorial.
 

Attachments

  • Skjermbilde2.PNG
    Skjermbilde2.PNG
    27.9 KB · Views: 402
Last edited:

Peter Schmitz

Active member
awesome :) now - it would be great if someone could solve the collision problem when landing on the ground - so that the player doesn't stop 1 pixel above the ground and land afterwards.
 

baardbi

Well-known member
awesome :) now - it would be great if someone could solve the collision problem when landing on the ground - so that the player doesn't stop 1 pixel above the ground and land afterwards.
That's easy. The ladder script is using the player height for a check. So depending on how tall your player sprite is you might have to adjust a value in the climbLadderDown script. Look for this line at the top of the script:

ADC #32 ;; height of player plus arbitrary number to check. (if player is #$10 pixels tall, maybe put #$12 here to check just below his feet).
 

Peter Schmitz

Active member
That's easy. The ladder script is using the player height for a check. So depending on how tall your player sprite is you might have to adjust a value in the climbLadderDown script. Look for this line at the top of the script:

ADC #32 ;; height of player plus arbitrary number to check. (if player is #$10 pixels tall, maybe put #$12 here to check just below his feet).
good to know, but maybe I should have clarified - what I meant is the jumping and landing in general - nothing to do with climbing the ladder ;) If you haven't noticed yet - in the platformer module - every time you jump your player object stops one pixel above the ground before reaching the ground. It is evident in your clip above. Don't ask me why - but I kinda find it annoying. Unfortunately, my knowledge of 6502 is still very limited so I don't really know where to start looking for a solution.
 

kevintron

Active member
I'm having a little issue using multiple ladders. When I try to move down a ladder it will sometimes transport me to the top of the previous ladder I used and drop me down it. Moving up seems to work fine though. Its only a problem with multiple ladders but I got donkey-kong-like thing going on. Curious if anyone might know why this is happening. I tried to adjust the player height check but that didn't seem to do anything to change the issue. I'm using the arcade style platform model. It works great on single ladder levels.
 

baardbi

Well-known member
I'm having a little issue using multiple ladders. When I try to move down a ladder it will sometimes transport me to the top of the previous ladder I used and drop me down it. Moving up seems to work fine though. Its only a problem with multiple ladders but I got donkey-kong-like thing going on. Curious if anyone might know why this is happening. I tried to adjust the player height check but that didn't seem to do anything to change the issue. I'm using the arcade style platform model. It works great on single ladder levels.
It doesn't work properly if you have ladders right next to each other. There needs to be at least one other tile type between ladders.
 

kevintron

Active member
These were 10 apart but there where like 6 ladders in a single screen and most lines had 2 ladders. Just too much going on. Never an issue climbing up though. I had to take it out of my current project. Kept the idle climb state so this is still a win for me. Plus I'm sure I'll use this down the road in a more suited project.
 

baardbi

Well-known member
I'm having a little issue using multiple ladders. When I try to move down a ladder it will sometimes transport me to the top of the previous ladder I used and drop me down it. Moving up seems to work fine though. Its only a problem with multiple ladders but I got donkey-kong-like thing going on. Curious if anyone might know why this is happening. I tried to adjust the player height check but that didn't seem to do anything to change the issue. I'm using the arcade style platform model. It works great on single ladder levels.
You were right. There was something missing from the tile code. I'll update this tutorial with the correct tile code. Thanks for the feedback.
 

Peter Schmitz

Active member
hey baardbi - could you explain what the following does?
Code:
LDA tileX
AND #%11110000
STA ladderX

Especially the AND line. Would like to make the character move always in the center of the null tile in the maze module. Just like in the original Legend of Zelda. Kinda thought that I can borrow some code of your snapping to ladder code ;)
 

baardbi

Well-known member
hey baardbi - could you explain what the following does?
Code:
LDA tileX
AND #%11110000
STA ladderX

Especially the AND line. Would like to make the character move always in the center of the null tile in the maze module. Just like in the original Legend of Zelda. Kinda thought that I can borrow some code of your snapping to ladder code ;)
I'll try to explain without getting too technical lol.

That part is masking out the upper four bits of the tileX byte. That means that when using AND like that and storing the result in a new variable, the lower four bits are all 0 (since anything AND'ed with 0 is 0). So the reason I'm doing that is to get the exact pixel value of the left side of the tile. Tiles are always placed in a 16 x 16 pixel grid. So I'm removing any pixel value below 16. That's what makes the player snap to the ladder when doing this:

LDA ladderX
STA Object_x_hi,x

Because the ladderX value now cantains the X pixel value of the left side of the ladder tile. So basically I transfer that position to the player X position.

I hope that made sense.
 

Peter Schmitz

Active member
I'll try to explain without getting too technical lol.

That part is masking out the upper four bits of the tileX byte. That means that when using AND like that and storing the result in a new variable, the lower four bits are all 0 (since anything AND'ed with 0 is 0). So the reason I'm doing that is to get the exact pixel value of the left side of the tile. Tiles are always placed in a 16 x 16 pixel grid. So I'm removing any pixel value below 16. That's what makes the player snap to the ladder when doing this:

LDA ladderX
STA Object_x_hi,x

Because the ladderX value now cantains the X pixel value of the left side of the ladder tile. So basically I transfer that position to the player X position.

I hope that made sense.
it kinda does - thanks. Now I just have to figure out how to make the character snap to a null tile when moving up and down ;)
 

Jonny

Well-known member
You were right. There was something missing from the tile code. I'll update this tutorial with the correct tile code. Thanks for the feedback.
Did you ever figure this one out?

I changed the climbUp / climbDown addition to...
Code:
LDA tileX
AND #%11110000
STA ladderX
STA Object_x_hi,x
Seems to work ok by setting the ladderX again. Tile code (exactly as above in tutorial) is still needed.
 
Last edited:

Ekenz

New member
Im using the metroidvania module with these ladder scripts and everything works perfect except when im at the top of the ladder and want to move to a jumpthroughplatform type solid on the top of the ladder, I cant just hold up to climb to the top, it continues to lock me to the ladder so I always have to jump to get out of it or move sideways. Anyway to make it so it doesnt lock when at the very top of the ladder?
 

baardbi

Well-known member
Im using the metroidvania module with these ladder scripts and everything works perfect except when im at the top of the ladder and want to move to a jumpthroughplatform type solid on the top of the ladder, I cant just hold up to climb to the top, it continues to lock me to the ladder so I always have to jump to get out of it or move sideways. Anyway to make it so it doesnt lock when at the very top of the ladder?
Sorry. It's hard to say. I'm sure there's a way to do that, but I haven't tested that specific combination with ladder and jump through platforms. My best advice is to try to work around that.
 

Peter Schmitz

Active member
Im using the metroidvania module with these ladder scripts and everything works perfect except when im at the top of the ladder and want to move to a jumpthroughplatform type solid on the top of the ladder, I cant just hold up to climb to the top, it continues to lock me to the ladder so I always have to jump to get out of it or move sideways. Anyway to make it so it doesnt lock when at the very top of the ladder?
Is it possible for you to make a short video / gif ?
 
I'm trying to implement this into a metroidvania module, so far it works, but my player is actually smaller that yours, he's set to a 3x3 size with a 8x16 collision on the bottom. the problem being he's snapping to the ladder but he is off center, is there something i can do to fix this?
 

baardbi

Well-known member
I'm trying to implement this into a metroidvania module, so far it works, but my player is actually smaller that yours, he's set to a 3x3 size with a 8x16 collision on the bottom. the problem being he's snapping to the ladder but he is off center, is there something i can do to fix this?
The thing is that this worked perfectly since the tiles are 2x2 graphic tiles, which makes them 16x16 pixels. It's very easy to work with. I don't have time to test it now, but I guess you could try something like this in the ladder climb scripts:

LDA ladderX
SEC
SBC #4 ;;; Sprite X offset
STA Object_x_hi,x
 
Works perfectly! for anyone else, this is how i set it up

;;; Copy the ladders X position to the player (here)
LDA tileX
AND #%11110000
STA ladderX
STA Object_x_hi,x

LDA ladderX
SEC
SBC #4 ;;; Sprite X offset
STA Object_x_hi,x
;;; (to here)


thank you very much.
 
Last edited:
Top Bottom