Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Does a collision check on two rectangles
- ; input: TouchTopA/B, TouchLeftA/B, TouchWidthA/B, TouchHeightA/B
- ; output: carry (rectangles are overlapping)
- .proc ChkTouchGeneric
- ; http://atariage.com/forums/topic/71120-6502-killer-hacks/page-3?&#entry1054049
- ; X positions
- lda TouchWidthB
- add TouchWidthA ; carry is clear afterwards
- adc #<-1 ; so this subtracts 1
- sta TouchTemp2 ; now carry is set
- lda TouchWidthB
- sbc #1
- sta TouchTemp
- clc
- lda TouchLeftA
- sbc TouchLeftB ; Note will subtract n-1
- sbc TouchTemp ;#SIZE2-1
- adc TouchTemp2 ;#SIZE1+SIZE2-1 ; Carry set if overlap
- bcc No
- ; Y positions
- lda TouchHeightB
- add TouchHeightA ; carry is clear afterwards
- adc #<-1 ; so this subtracts 1
- sta TouchTemp2 ; now carry is set
- lda TouchHeightB
- sbc #1
- sta TouchTemp
- clc
- lda TouchTopA
- sbc TouchTopB ; Note will subtract n-1
- sbc TouchTemp ;#SIZE2-1
- adc TouchTemp2 ;#SIZE1+SIZE2-1 ; Carry set if overlap
- bcc No
- sec
- rts
- No:
- clc
- rts
- .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement