Movement refactor

This commit is contained in:
2026-02-18 16:56:16 -05:00
parent 7a8fb73f84
commit a59424b3ef
2 changed files with 38 additions and 29 deletions

BIN
plat.nes

Binary file not shown.

67
plat.s
View File

@@ -333,6 +333,7 @@ jump_pressed_last_frame: .res 1
frame_counter: .res 1
last_frame_jumped: .res 1
last_frame_moving: .res 1
.segment "CODE"
main:
@@ -514,6 +515,9 @@ movement:
lda player_status
and #%11111110
sta player_status
lda frame_counter
sta last_frame_moving
:
jsr btn_left
@@ -521,31 +525,41 @@ movement:
beq :+
ldx #1
lda horizontal_speed
ora #%10000000
eor #%11111111
clc
adc #1
sta player_vel_x
lda player_status
ora #%00000001
sta player_status
lda frame_counter
sta last_frame_moving
:
cpx #1
cpx #1 ; skip decay if right or left pressed
beq @end
lda frame_counter
and #1
clc
sbc last_frame_moving
and #3
cmp #0
bne @end
lda #0
cmp player_vel_x
lda player_vel_x
and #%01111111
cmp #0
beq @end ; If player_vel_x = 0, skip decay
; If player_vel_x > 0, decrement
bpl :+
lda player_vel_x
and #%10000000
; If player_vel_x positive, decrement
bne :+
lda player_vel_x
sec
sbc #16
stx player_vel_x
sta player_vel_x
jmp @end
:
; Else if player_vel_x < 0, increment
@@ -603,7 +617,7 @@ movement:
bne :+
; 0: right
lda player_vel_x
and #%01110000
and #%01111111
clc
ror
clc
@@ -612,7 +626,9 @@ movement:
ror
clc
ror
sta var_n ; pixels
clc
adc player_pos_x
sta player_pos_x ; add pixels
lda player_vel_x
and #%00001111
@@ -633,19 +649,19 @@ movement:
:
; 1: left
lda player_vel_x
and #%01110000
clc
sec
ror
sec
ror
sec
ror
sec
ror
clc
ror
clc
ror
clc
ror
eor #%11111111
clc
adc #1
sta var_n ; pixels
ora #%10000000
adc player_pos_x
sta player_pos_x ; add pixels
lda player_vel_x
and #%00001111
@@ -662,17 +678,10 @@ movement:
bmi @end_sub_subpos ; so skip if subpos is bigger than result
ldx player_pos_x
dex
stx player_pos_x
;stx player_pos_x
@end_sub_subpos:
:
lda player_pos_x
clc
adc var_n ; add pixels
sta player_pos_x
; load x pos, filter blocks, check up and down