hidden_objects.asm 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. IsPlayerOnDungeonWarp:
  2. xor a
  3. ld [wWhichDungeonWarp], a
  4. ld a, [wd72d]
  5. bit 4, a
  6. ret nz
  7. call ArePlayerCoordsInArray
  8. ret nc
  9. ld a, [wCoordIndex]
  10. ld [wWhichDungeonWarp], a
  11. ld hl, wd72d
  12. set 4, [hl]
  13. ld hl, wd732
  14. set 4, [hl]
  15. ret
  16. ; if a hidden object was found, stores $00 in [$ffee], else stores $ff
  17. CheckForHiddenObject:
  18. ld hl, $ffeb
  19. xor a
  20. ld [hli], a
  21. ld [hli], a
  22. ld [hli], a
  23. ld [hl], a
  24. ld de, $0
  25. ld hl, HiddenObjectMaps
  26. .hiddenMapLoop
  27. ld a, [hli]
  28. ld b, a
  29. cp $ff
  30. jr z, .noMatch
  31. ld a, [wCurMap]
  32. cp b
  33. jr z, .foundMatchingMap
  34. inc de
  35. inc de
  36. jr .hiddenMapLoop
  37. .foundMatchingMap
  38. ld hl, HiddenObjectPointers
  39. add hl, de
  40. ld a, [hli]
  41. ld h, [hl]
  42. ld l, a
  43. push hl
  44. ld hl, wHiddenObjectFunctionArgument
  45. xor a
  46. ld [hli], a
  47. ld [hli], a
  48. ld [hl], a
  49. pop hl
  50. .hiddenObjectLoop
  51. ld a, [hli]
  52. cp $ff
  53. jr z, .noMatch
  54. ld [wHiddenObjectY], a
  55. ld b, a
  56. ld a, [hli]
  57. ld [wHiddenObjectX], a
  58. ld c, a
  59. call CheckIfCoordsInFrontOfPlayerMatch
  60. ld a, [hCoordsInFrontOfPlayerMatch]
  61. and a
  62. jr z, .foundMatchingObject
  63. inc hl
  64. inc hl
  65. inc hl
  66. inc hl
  67. push hl
  68. ld hl, wHiddenObjectIndex
  69. inc [hl]
  70. pop hl
  71. jr .hiddenObjectLoop
  72. .foundMatchingObject
  73. ld a, [hli]
  74. ld [wHiddenObjectFunctionArgument], a
  75. ld a, [hli]
  76. ld [wHiddenObjectFunctionRomBank], a
  77. ld a, [hli]
  78. ld h, [hl]
  79. ld l, a
  80. ret
  81. .noMatch
  82. ld a, $ff
  83. ld [$ffee], a
  84. ret
  85. ; checks if the coordinates in front of the player's sprite match Y in b and X in c
  86. ; [hCoordsInFrontOfPlayerMatch] = $00 if they match, $ff if they don't match
  87. CheckIfCoordsInFrontOfPlayerMatch:
  88. ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
  89. cp SPRITE_FACING_UP
  90. jr z, .facingUp
  91. cp SPRITE_FACING_LEFT
  92. jr z, .facingLeft
  93. cp SPRITE_FACING_RIGHT
  94. jr z, .facingRight
  95. ; facing down
  96. ld a, [wYCoord]
  97. inc a
  98. jr .upDownCommon
  99. .facingUp
  100. ld a, [wYCoord]
  101. dec a
  102. .upDownCommon
  103. cp b
  104. jr nz, .didNotMatch
  105. ld a, [wXCoord]
  106. cp c
  107. jr nz, .didNotMatch
  108. jr .matched
  109. .facingLeft
  110. ld a, [wXCoord]
  111. dec a
  112. jr .leftRightCommon
  113. .facingRight
  114. ld a, [wXCoord]
  115. inc a
  116. .leftRightCommon
  117. cp c
  118. jr nz, .didNotMatch
  119. ld a, [wYCoord]
  120. cp b
  121. jr nz, .didNotMatch
  122. .matched
  123. xor a
  124. jr .done
  125. .didNotMatch
  126. ld a, $ff
  127. .done
  128. ld [hCoordsInFrontOfPlayerMatch], a
  129. ret
  130. INCLUDE "data/hidden_objects.asm"