Thanks to a plethora of online resources, I have been able to create a metasprite made up of four sprites that move together around the room based on joystick input. I am trying to keep them contained within the screen area. Up, right, and down are all successfully working. However, whenever I press Left, the game freezes in the emulator. If I remove the three lines of code that check for position before moving, it works fine. This checking position method works in ALL the other directions, so I'm not sure why left is crashing things.
For brevity, I'll just provide a working piece of the code (for Down) and then the problem piece (left). Let me know if you need more in order to help track down the issue!
Code: Select all
MovePlayerDown: ;; THIS IS WORKING FINE, as are all directions except left. LDA buttons AND #%00000100 ;; if down is pressed BEQ movePlayerLeft ;; if these things are not true, jump to movePlayerLeft LDX $0200 ;;Load the player's Y position into X CPX #$D4; compare the Y value to bottom of screen BCS movePlayerLeft ;; if the player is too close to the bottom, skip the rest of the code and jump to movePlayerLeft ;;Move Player part...need to move all four sprites LDA $0200 CLC ADC #playerWalkSpeed STA $0200 LDA $0204 CLC ADC #playerWalkSpeed STA $0204 LDA $0208 CLC ADC #playerWalkSpeed STA $0208 LDA $020C CLC ADC #playerWalkSpeed STA $020C movePlayerLeft: ;; You'll notice, this is coded the same way, yet causes the game to freeze. LDA buttons AND #%00000010 ;; if left is pressed BEQ movePlayerUp ;; if these things aren't true, jump to movePlayerUp ;;;;;;;;THIS IS THE PROBLEM;;;;;;;;;;; LDX $0203 ;; load the x value into X CPX #$08 ;; Compare X to position towards the left of the screen BCC movePlayerUp ;; if close to the edge, skip the rest and jump down to movePlayerUp ;;;;;;;;;;END PROBLEM;;;;;;;;;;;;;;;;;;; ;;Move Player part...need to move all four sprites LDA $0203 SEC SBC #playerWalkSpeed STA $0203 LDA $0207 SEC SBC #playerWalkSpeed STA $0207 LDA $020B SEC SBC #playerWalkSpeed STA $020B LDA $020F SEC SBC #playerWalkSpeed STA $020F