Help to comment this jump code so I can better understand object movement

WillElm

New member
I'm slowly learning, I've managed a pretty robust control scheme and I'm getting by. Most of the asm I've learned and actually been able to put to use involves input scripts that check for different conditions (button presses, physics byte, flags, etc.). I've dabbled in collision code but it's pretty much pure trial and error there.

I've made a few different kinds of jump scripts and can work with them in application, but I still don't really know what a lot of the asm does. I've basically commented this entire jump script as an exercise and you'll see in the comments where I'm unclear. What I'm mostly confused about is the stuff in canjump that actually makes you jump.

If anyone here wants to shed some light on this stuff, I and probably some others would really appreciate it!

Code:
; a jumps
 
   LDX player1_object
   

   ;;; let's check for if we are standing on a jumpthrough platform,
   ;;; for which "down and jump" will jump downwards through
   ;;; comment this out if you do not want that functionality
    LDA screenFlags ;; what are the screen characteristics?
    AND #%00100000 ;; does it use gravity?
    BEQ dontJump  ;; if it DOESN'T use gravity, go to end of script?
    
   LDA Object_physics_byte,x  ;; what is the current physics situation of the player?
   AND #%00001000  ;; are you on a jump through platform?
   BEQ notStandingOnJumpThroughPlatform  ;; if you're not on a jump through, check if in air in below label
   LDA gamepad
   AND #%00100000  ;; is down pressed?
   BEQ notStandingOnJumpThroughPlatform ;; if DOWN is not pressed, jump to label below
   LDA Object_y_hi,x ;; NOT SURE. Getting the player's current y position? Or speed?
   CLC ;; NOT SURE
   ADC #$09 ;;adding 9 to the y position? Or to the speed?
   STA Object_y_hi,x ;; storing the new value for use in the physics or movement code?
   JMP dontJump ;; jump to end of script
notStandingOnJumpThroughPlatform:
   
   LDA Object_physics_byte,x
   AND #%00000001  ;; are you in the air?
   BNE canJump  ;; if you're not in the air, go to below label and run jump code 
   LDA Object_physics_byte,x
   AND #%00000100 ;; no idea. "can't jump". there's a bit for that?
   BEQ dontJump
    
canJump:
    ;;; TURN OFF "STANDING ON JUMPTHROUGH PLATFORM" if it is on
    LDA Object_physics_byte,x
    AND #%11110111 ;; are all physics bit flagged BUT jump through?
    STA Object_physics_byte,x ;; if so, store that
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    LDA #$00 ;; are we just loading a generic, neutral value that we're gonna manipulate below?
    SEC ;; "set carry flag"? not sure what this does here
    SBC #JUMP_SPEED_LO ;; "subtract with carry" the jump speed constant.I get that we're referencing the constant, but why SBC?
    STA Object_v_speed_lo,x ;; store the new vertical speed.
    LDA #$00
    SEC
    SBC #JUMP_SPEED_HI
    STA Object_v_speed_hi,x ;; same as above, but using the other jump speed constant.
    ;    GetCurrentActionType player1_object
    ;    CMP #$03 ;; attack
    ;    BEQ +
    ChangeObjectState #$02, #$04
    ;   +
    PlaySound #SND_JUMP
dontJump:
    RTS
 

Mugi

Member
LDA Object_y_hi,x this is the Y position of X (in this case, player)


SEC ;; "set carry flag"? not sure what this does here
SBC #JUMP_SPEED_LO ;; "subtract with carry" the jump speed constant.I get that we're referencing the constant, but why SBC?

SEC = SEt Carry
the reason why SBC (substract with carry) is used here is because this code makes the character jump, and moving upwards is a negative value. If one would use positive values here, jumping would move them downwards.
00-7F are positive values and 80-FF are negative values. Substracting the value of #JUMP_SPEED_LO (lets pretend its 6) from #$00 results in #$FA (this is -6)
 

WillElm

New member
Thank you very much. So the part that is checking for jump through platforms...is the ADC #$09 basically just teleporting the character down to a position that is 9 (pixels?) below their current position.
 

dale_coop

Moderator
Staff member
Yep exactly, on the platform... if the down button is pressed, the player is moved 9 pixel lower than his current position.
(Object_y_hi,x is the top vertical position of the current object -here the player object-)
 

WillElm

New member
thanks! I've used what I've learned here to make a dash because for whatever reason, the one from chronicleroflegend's thread wasn't working, though the one I've made is very similar.
 

Mugi

Member
correct.
the reasoning for this is because of the way tiles are made in the nesmaker engine (16x16 pixel metatiles), moving the player down 9 pixels (one pixel more than halfway) clears the "standing on a jump through platform" flag and the tile is then treated as null (no collision.) In the event that this is not true (it can happen, depending on the object's hitbox), the fact that the object has still moved more than halfway through the tile, causes the ejection to eject the object down in the event that it is still treating it as a solid collision (you cannot be inside a solid tile, there is a code in place that will eject the object out if it is inside a solid object.)
 
Top Bottom