Advertisement
NovaYoshi

collision detection in joshdown

Apr 12th, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; swap using just A + stack
  2. .macro swapa mema, memb
  3.   lda mema
  4.   pha
  5.   lda memb
  6.   sta mema
  7.   pla
  8.   sta memb
  9. .endmacro
  10.  
  11. .proc ChkTouch16x16 ; Carry is set if collision is detected between TouchLeftA,TouchTopA and TouchLeftB,TouchTopB
  12.   jsr :+
  13.   swapa TouchLeftA, TouchLeftB
  14.   swapa TouchTopA,  TouchTopB
  15.   jsr :+
  16.   clc ; no collision
  17.   rts
  18. : lda TouchLeftB
  19.   add #16
  20.   sta TouchRight
  21.   lda TouchTopB
  22.   add #16
  23.   sta TouchBottom
  24.  
  25.   lda TouchLeftA
  26.   cmp TouchLeftB
  27.   bcc :+
  28.  
  29.   lda TouchLeftA
  30.   cmp TouchRight
  31.   bcs :+
  32.  
  33.   lda TouchTopA
  34.   cmp TouchTopB
  35.   bcc :+
  36.  
  37.   lda TouchTopA
  38.   cmp TouchBottom
  39.   bcs :+
  40.   pla
  41.   pla
  42.   sec ; collision detected
  43. : rts
  44. .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement