Ladder Improvement/Fix?

Post Reply
User avatar
crazygrouptrio
Posts: 69
Joined: Fri Jan 11, 2019 2:22 pm
Location: United States
Contact:

Ladder Improvement/Fix?

Post by crazygrouptrio » Fri Apr 05, 2019 2:22 pm

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.
User avatar
mongolianmisfit
Posts: 35
Joined: Tue Feb 19, 2019 4:40 am

Re: Ladder Improvement/Fix?

Post by mongolianmisfit » Mon Apr 08, 2019 9:14 pm

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.
User avatar
jorotroid
Posts: 234
Joined: Wed Aug 08, 2018 7:48 pm
Location: California
Contact:

Re: Ladder Improvement/Fix?

Post by jorotroid » Mon Apr 08, 2019 9:31 pm

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: Select all

LDA Object_physics_byte,x
AND #%00000010
BEQ +
RTS
+
User avatar
Chasersgaming
Posts: 51
Joined: Mon Feb 04, 2019 11:46 pm
Location: London

Re: Ladder Improvement/Fix?

Post by Chasersgaming » Mon Apr 08, 2019 9:33 pm

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.:)
User avatar
crazygrouptrio
Posts: 69
Joined: Fri Jan 11, 2019 2:22 pm
Location: United States
Contact:

Re: Ladder Improvement/Fix?

Post by crazygrouptrio » Wed Apr 10, 2019 12:29 pm

jorotroid wrote:
Mon Apr 08, 2019 9:31 pm
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: Select all

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.
User avatar
mongolianmisfit
Posts: 35
Joined: Tue Feb 19, 2019 4:40 am

Re: Ladder Improvement/Fix?

Post by mongolianmisfit » Wed Apr 10, 2019 2:20 pm

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:
viewtopic.php?f=23&t=1981&fbclid=IwAR20 ... OmP54gCaVk
User avatar
crazygrouptrio
Posts: 69
Joined: Fri Jan 11, 2019 2:22 pm
Location: United States
Contact:

Re: Ladder Improvement/Fix?

Post by crazygrouptrio » Fri Apr 12, 2019 10:43 pm

mongolianmisfit wrote:
Wed Apr 10, 2019 2:20 pm
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:
viewtopic.php?f=23&t=1981&fbclid=IwAR20 ... OmP54gCaVk
Yeah that's where I started too, but wasn't able to implement into my game. Thanks tho!
User avatar
SuperNatetendo
Posts: 79
Joined: Wed Aug 08, 2018 4:51 pm

Re: Ladder Improvement/Fix?

Post by SuperNatetendo » Fri Apr 12, 2019 11:01 pm

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

Code: Select all

;;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: Select all

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.
User avatar
SuperNatetendo
Posts: 79
Joined: Wed Aug 08, 2018 4:51 pm

Re: Ladder Improvement/Fix?

Post by SuperNatetendo » Fri Apr 12, 2019 11:11 pm

For this thread, I don't know how relevant the code is at all to your problem. Sorry. :/
Post Reply