Hi everyone! I've been trying to apply screen clamping to prevent the player sprite from wrapping around the edges. I came up with code that i thought was very simple but it does not work very well. The clamping works on left and right, and everything works well on the left half of the screen. On the right half of the screen however, if you press left, it clamps to the left side of the screen. Just reiterating, this bug only occurs when the player is in the right half of the screen.
Any help/feedback would be greatly appreciated.
Here's the code snipit; I've also uploaded the nes file.
Any help/feedback would be greatly appreciated.
Here's the code snipit; I've also uploaded the nes file.
Code:
; Player input jsr Controller::read_controller1 lda gpad1 ; button state and #BTN_LEFT ; # not an address beq check_right ; if 0 (i.e. left not pressed), check right button dec player_x ; else decrement x dec player_x ; ***** i believe this is the problematic section ***** ; Clamp if at left edge. lda player_x cmp #$00 bpl check_right lda #$00 ; else clamp to 0 sta player_x ; ******************************************************** check_right: lda gpad1 and #BTN_RIGHT beq done_gpad1 inc player_x inc player_x ; Clamp ... lda player_x cmp #$f0 ; $f0 = 240; sprite is 16px wide and screen is 256 therefore 256-16=240 bcc done_gpad1 ; If carry clear, player < right edge there skip and no clamp lda #$f0 ; else set clamp to f0 sta player_x done_gpad1:
Statistics: Posted by dasefx — Mon Oct 14, 2024 2:00 pm — Replies 6 — Views 142