I have a really simple sprite I am trying to move around in a kind of triangle wave shape. so it is constantly moving left but alternates between moving up and down.
This is the code I have
so I am updating the X position every frame which is great. the code looks up the first number in the vertpos look up table but I can't work out how to make the code load subsequent numbers from the vertpos table so my sprite just moves diagonally down. I tried this
Which I thought would increment the x counter and move to the next number in the table each time the subroutine was called but no luck. Does anyone have any ideas?
Thanks guys!
This is the code I have
Code:
movesprites:
LDA $0203 ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$01 ; A = A - 1
STA $0203 ; save sprite X position
LDA $0200 ; load sprite Y position
CLC ; make sure the carry flag is clear
ADC vertpos ; A = A plus vertposvalue
STA $0200 ; save sprite Y position
rts
vertpos:
.db $01,$01,$01,$01,$01,$01,$01,$01,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
LDA $0203 ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$01 ; A = A - 1
STA $0203 ; save sprite X position
LDA $0200 ; load sprite Y position
CLC ; make sure the carry flag is clear
ADC vertpos ; A = A plus vertposvalue
STA $0200 ; save sprite Y position
rts
vertpos:
.db $01,$01,$01,$01,$01,$01,$01,$01,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
so I am updating the X position every frame which is great. the code looks up the first number in the vertpos look up table but I can't work out how to make the code load subsequent numbers from the vertpos table so my sprite just moves diagonally down. I tried this
Code:
LDA $0200 ; load sprite Y position
CLC ; make sure the carry flag is clear
ldx #01
ADC vertpos, x ; A = A plus vertposvalue
STA $0200 ; save sprite Y position
inx
CLC ; make sure the carry flag is clear
ldx #01
ADC vertpos, x ; A = A plus vertposvalue
STA $0200 ; save sprite Y position
inx
Which I thought would increment the x counter and move to the next number in the table each time the subroutine was called but no luck. Does anyone have any ideas?
Thanks guys!