Advertisement
Guest User

Untitled

a guest
Jan 26th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Code for making shop items solid, and for detecting if player is in range to purchase the item
  2.  
  3. ; Note, when starting the below fragment
  4. ; X should be the shopkeeper sprite index
  5. ; Y should be applicable offset .item_offsets
  6.  
  7. ;check if player link is on same layer as shopkeeper
  8. LDA $00EE : CMP $0F20, X; BNE .no_interaction  
  9.  
  10. JSR Setup_LinksHitbox
  11. JSR Setup_ShopItemCollisionHitbox
  12. JSL Utility_CheckIfHitBoxesOverlapLong
  13. BCC .no_contact
  14.     JSR Sprite_HaltSpecialPlayerMovementCopied
  15. .no_contact
  16. JSR Setup_ShopItemInteractionHitbox
  17. JSL Utility_CheckIfHitBoxesOverlapLong
  18. BCC .no_interaction
  19.     ;TODO Check if player is pressing A Button (by checking $F6). If so try to buy item
  20. .no_interaction
  21.  
  22. ;--------------------
  23.  
  24. Setup_ShopItemCollisionHitbox:
  25. ;The complications with XBA are to handle the fact that nintendo likes to store
  26. ;high and low bytes of 16 bit postion values seperately :-(
  27.  
  28.     ; load shopkeeper X (16 bit)
  29.     LDA $0D30, X : XBA : LDA $0D10, X
  30.  
  31.     REP #$20 ; set 16-bit accumulator
  32.     !ADD .item_offsets, Y
  33.     !ADD.w #$0002 ; a small negative margin
  34.     ; TODO: add 4 for a narrow item
  35.     SEP #20 ; set 8-bit accumulator
  36.  
  37.     ; store hitbox X
  38.     STA $04 : XBA : STA $0A
  39.  
  40.     ;load shopkeeper Y (16 bit)
  41.     LDA $0D20, X : XBA : LDA $0D00, X
  42.  
  43.     REP #$20 ; set 16-bit accumulator
  44.     !ADD .item_offsets+2, Y
  45.     SEP #20 ; set 8-bit accumulator
  46.  
  47.     ; store hitbox Y Low: $05, High $0B
  48.     STA $05 : XBA : STA $0B
  49.  
  50.     LDA.b #12: STA $06 ; Hitbox width, always 12 for existing (wide) shop items
  51.     ; TODO: for narrow sprite store make width 4 (i.e. 8 pixels smaller)
  52.  
  53.     LDA.b #14: STA $07 ; Hitbox height, always 14
  54. RTS
  55.  
  56. ; Adjusts the already set up collision hitbox to be a suitable interaction hitbox
  57. Setup_ShopItemInteractionHitbox:
  58.  
  59.     ; collision hitbox has left margin of -2, we want margin of 8 so we subtract 10
  60.     LDA $04; !SUB.b #$0A; STA $04
  61.     LDA $0A; SBC.b #$00; STA $0A ; Apply borrow
  62.  
  63.     ; collision hitbox has 0 top margin, we want a margin of 8 so we subtract 8
  64.     LDA $05; !SUB.b #$08; STA $05
  65.     LDA $0B; SBC.b #$00; STA $0B ; Apply borrow    
  66.  
  67.     ; We want a width of 32 for wide or 24 for narrow, so we add 20
  68.     LDA $06: !ADD.b #20: STA $06 ; Hitbox width
  69.  
  70.     LDA.b #40: STA $07 ; Hitbox height, always 40
  71. RTS
  72.  
  73. ; Following is a copy of procedure $3770A (Bank06.asm Line 6273)
  74. ; because there is no long version available
  75. Setup_LinksHitbox:
  76.     LDA.b #$08 : STA $02
  77.                      STA $03
  78.        
  79.         LDA $22 : ADD.b #$04 : STA $00
  80.         LDA $23 : ADC.b #$00 : STA $08
  81.        
  82.         LDA $20 : ADC.b #$08 : STA $01
  83.         LDA $21 : ADC.b #$00 : STA $09    
  84. RTS
  85.  
  86. ; The following is a copy of procedure Sprite_HaltSpecialPlayerMovement (Bank1E.asm line 255)
  87. ; because there is no long version available
  88. Sprite_HaltSpecialPlayerMovementCopied:
  89.         PHX      
  90.         JSL Sprite_NullifyHookshotDrag
  91.         STZ $5E ; Set Link's speed to zero...
  92.         JSL Player_HaltDashAttackLong
  93.         PLX
  94. RTS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement