Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Calculation of new camera position with lerp smoothing,
- ; assuming 256-pixel screen width and 12.4 fixed-point math
- ; caution: not tested
- .proc calc_new_camera_pos
- camtarget_lo = $00
- camtarget_hi = $01
- ; Step 1: Find the position that the camera seeks.
- lda player_x
- sta camtarget_lo
- lda player_xhi
- ldy player_facing ; 0 for right, 1 for left
- sec
- sbc camera_target_by_facing
- bcs not_off_left_side
- lda #0
- sta camtargetlo
- sec
- not_off_left_side:
- sta camtargethi
- ; Step 2: Find the distance that the camera must move
- ; to reach this position.
- lda camtarget_lo
- sbc camera_lo
- sta camtarget_lo
- lda camtarget_hi
- sbc camera_hi
- ; and divide by 4 for smoothing
- cmp #$80
- ror a
- ror camtarget_lo
- cmp #$80
- ror a
- ror camtarget_lo
- sta camtarget_hi
- ; Step 3: Add this to produce the camera's new position.
- ; The bit shifted out of camtarget_lo into carry can be used
- ; for free
- lda camtarget_lo
- adc camera_lo
- sta new_camera_lo
- lda camtarget_hi
- adc camera_hi
- sta new_camera_hi
- rts
- .pushseg
- .segment "RODATA"
- camera_target_by_facing:
- .byte 6 ; When facing right, put 6 blocks to player's left
- .byte 10 ; When facing left, put 10 blocks to player's left
- .popseg
- .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement