card_key.asm 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. PrintCardKeyText:
  2. ld hl, SilphCoMapList
  3. ld a, [wCurMap]
  4. ld b, a
  5. .silphCoMapListLoop
  6. ld a, [hli]
  7. cp $ff
  8. ret z
  9. cp b
  10. jr nz, .silphCoMapListLoop
  11. predef GetTileAndCoordsInFrontOfPlayer
  12. ld a, [wTileInFrontOfPlayer]
  13. cp $18
  14. jr z, .cardKeyDoorInFrontOfPlayer
  15. cp $24
  16. jr z, .cardKeyDoorInFrontOfPlayer
  17. ld b, a
  18. ld a, [wCurMap]
  19. cp SILPH_CO_11F
  20. ret nz
  21. ld a, b
  22. cp $5e
  23. ret nz
  24. .cardKeyDoorInFrontOfPlayer
  25. ld b, CARD_KEY
  26. call IsItemInBag
  27. jr z, .noCardKey
  28. call GetCoordsInFrontOfPlayer
  29. push de
  30. tx_pre_id CardKeySuccessText
  31. ld [hSpriteIndexOrTextID], a
  32. call PrintPredefTextID
  33. pop de
  34. srl d
  35. ld a, d
  36. ld b, a
  37. ld [wCardKeyDoorY], a
  38. srl e
  39. ld a, e
  40. ld c, a
  41. ld [wCardKeyDoorX], a
  42. ld a, [wCurMap]
  43. cp SILPH_CO_11F
  44. jr nz, .notSilphCo11F
  45. ld a, $3
  46. jr .replaceCardKeyDoorTileBlock
  47. .notSilphCo11F
  48. ld a, $e
  49. .replaceCardKeyDoorTileBlock
  50. ld [wNewTileBlockID], a
  51. predef ReplaceTileBlock
  52. ld hl, wCurrentMapScriptFlags
  53. set 5, [hl]
  54. ld a, SFX_GO_INSIDE
  55. jp PlaySound
  56. .noCardKey
  57. tx_pre_id CardKeyFailText
  58. ld [hSpriteIndexOrTextID], a
  59. jp PrintPredefTextID
  60. SilphCoMapList:
  61. db SILPH_CO_2F
  62. db SILPH_CO_3F
  63. db SILPH_CO_4F
  64. db SILPH_CO_5F
  65. db SILPH_CO_6F
  66. db SILPH_CO_7F
  67. db SILPH_CO_8F
  68. db SILPH_CO_9F
  69. db SILPH_CO_10F
  70. db SILPH_CO_11F
  71. db $FF
  72. CardKeySuccessText:
  73. TX_FAR _CardKeySuccessText1
  74. TX_SFX_ITEM_1
  75. TX_FAR _CardKeySuccessText2
  76. db "@"
  77. CardKeyFailText:
  78. TX_FAR _CardKeyFailText
  79. db "@"
  80. ; d = Y
  81. ; e = X
  82. GetCoordsInFrontOfPlayer:
  83. ld a, [wYCoord]
  84. ld d, a
  85. ld a, [wXCoord]
  86. ld e, a
  87. ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
  88. and a
  89. jr nz, .notFacingDown
  90. ; facing down
  91. inc d
  92. ret
  93. .notFacingDown
  94. cp SPRITE_FACING_UP
  95. jr nz, .notFacingUp
  96. ; facing up
  97. dec d
  98. ret
  99. .notFacingUp
  100. cp SPRITE_FACING_LEFT
  101. jr nz, .notFacingLeft
  102. ; facing left
  103. dec e
  104. ret
  105. .notFacingLeft
  106. ; facing right
  107. inc e
  108. ret