player_state.asm 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. ; only used for setting bit 2 of wd736 upon entering a new map
  2. IsPlayerStandingOnWarp:
  3. ld a, [wNumberOfWarps]
  4. and a
  5. ret z
  6. ld c, a
  7. ld hl, wWarpEntries
  8. .loop
  9. ld a, [wYCoord]
  10. cp [hl]
  11. jr nz, .nextWarp1
  12. inc hl
  13. ld a, [wXCoord]
  14. cp [hl]
  15. jr nz, .nextWarp2
  16. inc hl
  17. ld a, [hli] ; target warp
  18. ld [wDestinationWarpID], a
  19. ld a, [hl] ; target map
  20. ld [hWarpDestinationMap], a
  21. ld hl, wd736
  22. set 2, [hl] ; standing on warp flag
  23. ret
  24. .nextWarp1
  25. inc hl
  26. .nextWarp2
  27. inc hl
  28. inc hl
  29. inc hl
  30. dec c
  31. jr nz, .loop
  32. ret
  33. CheckForceBikeOrSurf:
  34. ld hl, wd732
  35. bit 5, [hl]
  36. ret nz
  37. ld hl, ForcedBikeOrSurfMaps
  38. ld a, [wYCoord]
  39. ld b, a
  40. ld a, [wXCoord]
  41. ld c, a
  42. ld a, [wCurMap]
  43. ld d, a
  44. .loop
  45. ld a, [hli]
  46. cp $ff
  47. ret z ;if we reach FF then it's not part of the list
  48. cp d ;compare to current map
  49. jr nz, .incorrectMap
  50. ld a, [hli]
  51. cp b ;compare y-coord
  52. jr nz, .incorrectY
  53. ld a, [hli]
  54. cp c ;compare x-coord
  55. jr nz, .loop ; incorrect x-coord, check next item
  56. ld a, [wCurMap]
  57. cp SEAFOAM_ISLANDS_4
  58. ld a, $2
  59. ld [wSeafoamIslands4CurScript], a
  60. jr z, .forceSurfing
  61. ld a, [wCurMap]
  62. cp SEAFOAM_ISLANDS_5
  63. ld a, $2
  64. ld [wSeafoamIslands5CurScript], a
  65. jr z, .forceSurfing
  66. ;force bike riding
  67. ld hl, wd732
  68. set 5, [hl]
  69. ld a, $1
  70. ld [wWalkBikeSurfState], a
  71. ld [wWalkBikeSurfStateCopy], a
  72. jp ForceBikeOrSurf
  73. .incorrectMap
  74. inc hl
  75. .incorrectY
  76. inc hl
  77. jr .loop
  78. .forceSurfing
  79. ld a, $2
  80. ld [wWalkBikeSurfState], a
  81. ld [wWalkBikeSurfStateCopy], a
  82. jp ForceBikeOrSurf
  83. INCLUDE "data/force_bike_surf.asm"
  84. IsPlayerFacingEdgeOfMap:
  85. push hl
  86. push de
  87. push bc
  88. ld a, [wSpriteStateData1 + 9] ; player sprite's facing direction
  89. srl a
  90. ld c, a
  91. ld b, $0
  92. ld hl, .functionPointerTable
  93. add hl, bc
  94. ld a, [hli]
  95. ld h, [hl]
  96. ld l, a
  97. ld a, [wYCoord]
  98. ld b, a
  99. ld a, [wXCoord]
  100. ld c, a
  101. ld de, .asm_c41e
  102. push de
  103. jp hl
  104. .asm_c41e
  105. pop bc
  106. pop de
  107. pop hl
  108. ret
  109. .functionPointerTable
  110. dw .facingDown
  111. dw .facingUp
  112. dw .facingLeft
  113. dw .facingRight
  114. .facingDown
  115. ld a, [wCurMapHeight]
  116. add a
  117. dec a
  118. cp b
  119. jr z, .setCarry
  120. jr .resetCarry
  121. .facingUp
  122. ld a, b
  123. and a
  124. jr z, .setCarry
  125. jr .resetCarry
  126. .facingLeft
  127. ld a, c
  128. and a
  129. jr z, .setCarry
  130. jr .resetCarry
  131. .facingRight
  132. ld a, [wCurMapWidth]
  133. add a
  134. dec a
  135. cp c
  136. jr z, .setCarry
  137. jr .resetCarry
  138. .resetCarry
  139. and a
  140. ret
  141. .setCarry
  142. scf
  143. ret
  144. IsWarpTileInFrontOfPlayer:
  145. push hl
  146. push de
  147. push bc
  148. call _GetTileAndCoordsInFrontOfPlayer
  149. ld a, [wCurMap]
  150. cp SS_ANNE_5
  151. jr z, .ssAnne5
  152. ld a, [wSpriteStateData1 + 9] ; player sprite's facing direction
  153. srl a
  154. ld c, a
  155. ld b, 0
  156. ld hl, .warpTileListPointers
  157. add hl, bc
  158. ld a, [hli]
  159. ld h, [hl]
  160. ld l, a
  161. ld a, [wTileInFrontOfPlayer]
  162. ld de, $1
  163. call IsInArray
  164. .done
  165. pop bc
  166. pop de
  167. pop hl
  168. ret
  169. .warpTileListPointers:
  170. dw .facingDownWarpTiles
  171. dw .facingUpWarpTiles
  172. dw .facingLeftWarpTiles
  173. dw .facingRightWarpTiles
  174. .facingDownWarpTiles
  175. db $01,$12,$17,$3D,$04,$18,$33,$FF
  176. .facingUpWarpTiles
  177. db $01,$5C,$FF
  178. .facingLeftWarpTiles
  179. db $1A,$4B,$FF
  180. .facingRightWarpTiles
  181. db $0F,$4E,$FF
  182. .ssAnne5
  183. ld a, [wTileInFrontOfPlayer]
  184. cp $15
  185. jr nz, .notSSAnne5Warp
  186. scf
  187. jr .done
  188. .notSSAnne5Warp
  189. and a
  190. jr .done
  191. IsPlayerStandingOnDoorTileOrWarpTile:
  192. push hl
  193. push de
  194. push bc
  195. callba IsPlayerStandingOnDoorTile
  196. jr c, .done
  197. ld a, [wCurMapTileset]
  198. add a
  199. ld c, a
  200. ld b, $0
  201. ld hl, WarpTileIDPointers
  202. add hl, bc
  203. ld a, [hli]
  204. ld h, [hl]
  205. ld l, a
  206. ld de, $1
  207. aCoord 8, 9
  208. call IsInArray
  209. jr nc, .done
  210. ld hl, wd736
  211. res 2, [hl]
  212. .done
  213. pop bc
  214. pop de
  215. pop hl
  216. ret
  217. INCLUDE "data/warp_tile_ids.asm"
  218. PrintSafariZoneSteps:
  219. ld a, [wCurMap]
  220. cp SAFARI_ZONE_EAST
  221. ret c
  222. cp UNKNOWN_DUNGEON_2
  223. ret nc
  224. coord hl, 0, 0
  225. ld b, 3
  226. ld c, 7
  227. call TextBoxBorder
  228. coord hl, 1, 1
  229. ld de, wSafariSteps
  230. lb bc, 2, 3
  231. call PrintNumber
  232. coord hl, 4, 1
  233. ld de, SafariSteps
  234. call PlaceString
  235. coord hl, 1, 3
  236. ld de, SafariBallText
  237. call PlaceString
  238. ld a, [wNumSafariBalls]
  239. cp 10
  240. jr nc, .asm_c56d
  241. coord hl, 5, 3
  242. ld a, " "
  243. ld [hl], a
  244. .asm_c56d
  245. coord hl, 6, 3
  246. ld de, wNumSafariBalls
  247. lb bc, 1, 2
  248. jp PrintNumber
  249. SafariSteps:
  250. db "/500@"
  251. SafariBallText:
  252. db "BALL×× @"
  253. GetTileAndCoordsInFrontOfPlayer:
  254. call GetPredefRegisters
  255. _GetTileAndCoordsInFrontOfPlayer:
  256. ld a, [wYCoord]
  257. ld d, a
  258. ld a, [wXCoord]
  259. ld e, a
  260. ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
  261. and a ; cp SPRITE_FACING_DOWN
  262. jr nz, .notFacingDown
  263. ; facing down
  264. aCoord 8, 11
  265. inc d
  266. jr .storeTile
  267. .notFacingDown
  268. cp SPRITE_FACING_UP
  269. jr nz, .notFacingUp
  270. ; facing up
  271. aCoord 8, 7
  272. dec d
  273. jr .storeTile
  274. .notFacingUp
  275. cp SPRITE_FACING_LEFT
  276. jr nz, .notFacingLeft
  277. ; facing left
  278. aCoord 6, 9
  279. dec e
  280. jr .storeTile
  281. .notFacingLeft
  282. cp SPRITE_FACING_RIGHT
  283. jr nz, .storeTile
  284. ; facing right
  285. aCoord 10, 9
  286. inc e
  287. .storeTile
  288. ld c, a
  289. ld [wTileInFrontOfPlayer], a
  290. ret
  291. GetTileTwoStepsInFrontOfPlayer:
  292. xor a
  293. ld [$ffdb], a
  294. ld hl, wYCoord
  295. ld a, [hli]
  296. ld d, a
  297. ld e, [hl]
  298. ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
  299. and a ; cp SPRITE_FACING_DOWN
  300. jr nz, .notFacingDown
  301. ; facing down
  302. ld hl, $ffdb
  303. set 0, [hl]
  304. aCoord 8, 13
  305. inc d
  306. jr .storeTile
  307. .notFacingDown
  308. cp SPRITE_FACING_UP
  309. jr nz, .notFacingUp
  310. ; facing up
  311. ld hl, $ffdb
  312. set 1, [hl]
  313. aCoord 8, 5
  314. dec d
  315. jr .storeTile
  316. .notFacingUp
  317. cp SPRITE_FACING_LEFT
  318. jr nz, .notFacingLeft
  319. ; facing left
  320. ld hl, $ffdb
  321. set 2, [hl]
  322. aCoord 4, 9
  323. dec e
  324. jr .storeTile
  325. .notFacingLeft
  326. cp SPRITE_FACING_RIGHT
  327. jr nz, .storeTile
  328. ; facing right
  329. ld hl, $ffdb
  330. set 3, [hl]
  331. aCoord 12, 9
  332. inc e
  333. .storeTile
  334. ld c, a
  335. ld [wTileInFrontOfBoulderAndBoulderCollisionResult], a
  336. ld [wTileInFrontOfPlayer], a
  337. ret
  338. CheckForCollisionWhenPushingBoulder:
  339. call GetTileTwoStepsInFrontOfPlayer
  340. ld hl, wTilesetCollisionPtr
  341. ld a, [hli]
  342. ld h, [hl]
  343. ld l, a
  344. .loop
  345. ld a, [hli]
  346. cp $ff
  347. jr z, .done ; if the tile two steps ahead is not passable
  348. cp c
  349. jr nz, .loop
  350. ld hl, TilePairCollisionsLand
  351. call CheckForTilePairCollisions2
  352. ld a, $ff
  353. jr c, .done ; if there is an elevation difference between the current tile and the one two steps ahead
  354. ld a, [wTileInFrontOfBoulderAndBoulderCollisionResult]
  355. cp $15 ; stairs tile
  356. ld a, $ff
  357. jr z, .done ; if the tile two steps ahead is stairs
  358. call CheckForBoulderCollisionWithSprites
  359. .done
  360. ld [wTileInFrontOfBoulderAndBoulderCollisionResult], a
  361. ret
  362. ; sets a to $ff if there is a collision and $00 if there is no collision
  363. CheckForBoulderCollisionWithSprites:
  364. ld a, [wBoulderSpriteIndex]
  365. dec a
  366. swap a
  367. ld d, 0
  368. ld e, a
  369. ld hl, wSpriteStateData2 + $14
  370. add hl, de
  371. ld a, [hli] ; map Y position
  372. ld [$ffdc], a
  373. ld a, [hl] ; map X position
  374. ld [$ffdd], a
  375. ld a, [wNumSprites]
  376. ld c, a
  377. ld de, $f
  378. ld hl, wSpriteStateData2 + $14
  379. ld a, [$ffdb]
  380. and $3 ; facing up or down?
  381. jr z, .pushingHorizontallyLoop
  382. .pushingVerticallyLoop
  383. inc hl
  384. ld a, [$ffdd]
  385. cp [hl]
  386. jr nz, .nextSprite1 ; if X coordinates don't match
  387. dec hl
  388. ld a, [hli]
  389. ld b, a
  390. ld a, [$ffdb]
  391. rrca
  392. jr c, .pushingDown
  393. ; pushing up
  394. ld a, [$ffdc]
  395. dec a
  396. jr .compareYCoords
  397. .pushingDown
  398. ld a, [$ffdc]
  399. inc a
  400. .compareYCoords
  401. cp b
  402. jr z, .failure
  403. .nextSprite1
  404. dec c
  405. jr z, .success
  406. add hl, de
  407. jr .pushingVerticallyLoop
  408. .pushingHorizontallyLoop
  409. ld a, [hli]
  410. ld b, a
  411. ld a, [$ffdc]
  412. cp b
  413. jr nz, .nextSprite2
  414. ld b, [hl]
  415. ld a, [$ffdb]
  416. bit 2, a
  417. jr nz, .pushingLeft
  418. ; pushing right
  419. ld a, [$ffdd]
  420. inc a
  421. jr .compareXCoords
  422. .pushingLeft
  423. ld a, [$ffdd]
  424. dec a
  425. .compareXCoords
  426. cp b
  427. jr z, .failure
  428. .nextSprite2
  429. dec c
  430. jr z, .success
  431. add hl, de
  432. jr .pushingHorizontallyLoop
  433. .failure
  434. ld a, $ff
  435. ret
  436. .success
  437. xor a
  438. ret