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!
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