Ladder Improvement/Fix?

crazygrouptrio

Active member
Anyone have any ideas how to disable right/left inputs while on a ladder (so the player can't just walk off the ladder like in the original Donkey Kong), except allow jumping off the ladder? I know it probably goes in the physics script in the LadderStuff area, but that's all I got...

I haven't made any changes to the ladder related script so its the same that comes with NESMaker at the moment.
 

mongolianmisfit

New member
I've been troubleshooting this for nearly two months with little to no success. It's been the most defeating part of my ASM journey so far.
 

jorotroid

Member
Give this a try:
When you are on a ladder, bit 1 of the variable Object_physics_byte is set, so at the beginning of your left and right input movement scripts do a check to see if that bit is clear before executing the movement code. So it would probably look something like this:

Code:
LDA Object_physics_byte,x
AND #%00000010
BEQ +
RTS
+
 

Chasersgaming

New member
Can’t you create a new object? And have it as a state for your character with the left and right inputs removed? Collision with ladder changes the state? When off the ladder change back to norm? I dunno, I haven’t work with nesmaker yet so just throwing that out there.:)
 

crazygrouptrio

Active member
jorotroid said:
Give this a try:
When you are on a ladder, bit 1 of the variable Object_physics_byte is set, so at the beginning of your left and right input movement scripts do a check to see if that bit is clear before executing the movement code. So it would probably look something like this:

Code:
LDA Object_physics_byte,x
AND #%00000010
BEQ +
RTS
+

Thanks this is close, but the player still falls when pressing left or right, and also gets stuck to the ladder. Once I climb the ladder I can't get off. Definitely a step in the right direction though.
 

mongolianmisfit

New member
I believe Nate, aka SuperNatetendo, fixed the ladder issues, but just hasn't shared the final code yet.

Might be worth reaching out to him at the original thread:
http://nesmakers.com/viewtopic.php?f=23&t=1981&fbclid=IwAR20yIEy2DZ3PHsgR6JUIoWlpGs41EklUJ2GTK5aurACDXIALOmP54gCaVk
 

crazygrouptrio

Active member
mongolianmisfit said:
I believe Nate, aka SuperNatetendo, fixed the ladder issues, but just hasn't shared the final code yet.

Might be worth reaching out to him at the original thread:
http://nesmakers.com/viewtopic.php?f=23&t=1981&fbclid=IwAR20yIEy2DZ3PHsgR6JUIoWlpGs41EklUJ2GTK5aurACDXIALOmP54gCaVk

Yeah that's where I started too, but wasn't able to implement into my game. Thanks tho!
 

SuperNatetendo

New member
Hey guys, I'm gunna throw you my relevant code for now until I actually have time to make a tutorial -

Code:
;;NATE E - ladder snap code
    
    GetCurrentActionType player1_object
    CMP #$03
    BNE noLadderSnap
    
    
    LDX player1_object
    
    LDA Object_left,x
    ADC Object_x_hi,x ;;snap to ladder
    AND #%11110000
    STA Object_x_hi,x
    
    noLadderSnap:
    
    GetCurrentActionType player1_object
    CMP #$03
    BNE endClimbAnimationCheck
    LDA gamepad
    AND #%00110000
    BNE MovingAndClimbing
    
    ;; this stores your climbing frame
    
    LDA climbingFrame
    STA Object_animation_frame,x
    JMP endClimbAnimationCheck
    
    MovingAndClimbing:
    
    ;; not moving? stay on current climbing frame
    
    LDA Object_animation_frame,x
    STA climbingFrame
    
    endClimbAnimationCheck:

In there is a variable that needs to be made called "climbingFrame" to store your climbing frame of animation.

Here's my modified(?) ladder script:

Code:
DoLadderStuff:
    CPX player1_object
    BEQ dontSkipLadderStuff
    JMP skipLadderStuff
    
dontSkipLadderStuff:
    
    ;; NATE E - long story short here: smarter check for pressing a direction on a ladder.
    ;; Checks for pressing a direction, but also makes sure you don't accidently fall off if you don't want to.
    
    GetCurrentActionType player1_object
    CMP #$03
    BNE +
    
    LDA gamepad
    AND #%11000000 ;;pressing L or R
    BEQ +
    LDA gamepad
    AND #%00110000 ;;not pressing U or D
    BNE +
    LDA Object_physics_byte,x ;;if so, reset ladder AND ground byte
    AND #%11111100
    STA Object_physics_byte,x
    JMP skipLadderStuff
    
    +
    
    LDA Object_physics_byte,x
    ORA #%00000010
    STA Object_physics_byte,x
    
    ;;below is a check for if you're far enoungh unto the ladder.
    ;;I have no idea what xHold_hi is, but it works better than Object_x_hi,x...
    
    LDA Object_right,x
    ADC xHold_hi
    AND #%11110000
    STA temp
    
    LDA Object_left,x
    ADC xHold_hi
    AND #%11110000
    STA temp1
    
    LDA temp
    CMP temp1
    BEQ dontSkipLadderSnap
    JMP skipLadderStuff
    
    dontSkipLadderSnap:
    
    LDA gamepad
    AND #%00010000 ; if up is pressed
    BEQ notPressingUpOnLadder
    GetCurrentActionType player1_object
    CMP #$03 ;; action state of climbing ladder #OBJ_INDEX_LADDER ;; compare to ladder type
    BEQ dontChangeToLadderState ;; already is in ladder state
    ChangeObjectState #$03, #$04
    
dontChangeToLadderState:
    LDA Object_y_lo,x
    SEC
    SBC #LADDER_SPEED_LO 
    STA Object_y_lo,x
    LDA Object_y_hi,x
    SBC #LADDER_SPEED_HI
    STA Object_y_hi,x
    STA yHold_hi
    CMP #BOUNDS_TOP
    BCS hasNotReachedTop
    
    LDA Object_scroll,x
    CMP xScroll_hi
    BEQ + ;; need to reverse
    ;; forward auto scroll
    LDA #%00000000
    JMP ++
+ ;; need to reverse
    LDA #%10000000
++
    ORA #$02
    STA align_screen_flag

    LDA #ALIGN_TIMER
    STA genericTimer
    LDA #$01
    STA prevent_scroll_flag
    ;JSR doTopBounds_player
hasNotReachedTop:
    
    
    JMP skipLadderStuff
notPressingUpOnLadder:
    LDA gamepad
    AND #%00100000 ; if down is pressed
    BEQ notPressingDownOnLadder

    GetCurrentActionType player1_object
    CMP #$03 ; #OBJ_INDEX_LADDER ;; compare to ladder type
    BEQ dontChangeToLadderState2 ;; already is in ladder state
    ChangeObjectState #$03, #$04
    
dontChangeToLadderState2:
    LDA Object_y_lo,x
    clc
    adc #LADDER_SPEED_LO 
    STA Object_y_lo,x
    LDA Object_y_hi,x
    adc #LADDER_SPEED_HI
    STA Object_y_hi,x
    CMP #BOUNDS_BOTTOM
    CLC
    ADC Object_bottom,x
    BCC skipLadderStuff
    LDA Object_scroll,x
    CMP xScroll_hi
    BEQ + ;; need to reverse
    ;; forward auto scroll
    LDA #%00000000
    JMP ++
+ ;; need to reverse
    LDA #%10000000
++
    ORA #$01
    STA align_screen_flag

    LDA #ALIGN_TIMER
    STA genericTimer
    LDA #$01
    STA prevent_scroll_flag
    
    
notPressingDownOnLadder:

skipLadderStuff:


    RTS

For now it's up to you to figure out exactly what's going on with the code. I don't know when I'll have the time to update/share it properly...

Obviously you'll have to write you own checks for input scripts, etc to make sure it all runs smoothly.
 
Top Bottom