Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.0 kB
2
Indexable
Never

.global p2RemainingJumpsDecrease

p2RemainingJumpsDecrease:
    @ Save registers, if necessary
    @ For example, push registers to the stack

    @ Set player2_jumping to true (1)
    ldr r0, =player2_jumping
    mov r1, #1
    str r1, [r0]

    @ Set player2_velocity_y to -20
    ldr r0, =player2_velocity_y
    mov r1, #-20
    str r1, [r0]

    @ Decrement player2_remaining_jumps
    ldr r0, =player2_remaining_jumps
    ldr r1, [r0]
    sub r1, r1, #1
    str r1, [r0]

    @ Restore registers, if necessary
    @ For example, pop registers from the stack

    @ Return
    bx lr

.global handlePlayer2Jump

handlePlayer2Jump:
    @ Save registers that will be modified
    push {r4, r5, lr}

    @ Load player2_y into r4 and player2_velocity_y into r5
    ldr r4, =player2_y      @ Load player2_y (assuming it's at address r0)
    ldr r5, =player2_velocity_y      @ Load player2_velocity_y (assuming it's at address r1)

    @ Add player2_velocity_y to player2_y
    add r4, r4, r5

    @ Increment player2_velocity_y by 1
    add r5, r5, #1

    @ Ensure player2_y stays above the invisible floor
    ldr r6, =INVISIBLE_FLOOR      @ Load floor into r6 (assuming it's at address r2)
    ldr r7, =PLAYER_HEIGHT      @ Load height into r7 (assuming it's at address r3)
    sub r8, r6, r7    @ Calculate floor - height
    cmp r4, r8        @ Compare player2_y with floor - height
    bge no_jump       @ Branch if greater than or equal (no jump)

    @ Store the updated player2_y and player2_velocity_y values back to memory
    str r4, [r0]
    str r5, [r1]

    @ Restore saved registers and return
    pop {r4, r5, pc}


no_jump:
    @ If player2_y is below floor - height, set player2_y to floor - height
    mov r4, r8

    @ Reset player2_jumping to false
    mov r9, #0        @ Assuming player2_jumping is in r9
    ldr r0, =player2_jumping
    str r9, [r0]

    @ Reset player2_remaining_jumps to 2
    mov r10, #2       @ Assuming player2_remaining_jumps is in r10
    ldr r0, =player2_remaining_jumps
    str r10, [r0]