![]() |
Routines |
| Prev: 56690 | Up: Map | Next: 56783 |
|
Used by the routine at UpdateDirection.
Works out which of the four directions an object has to face to move towards the player, using the axis along which the player is furthest away.
|
||||||||||||
|
Find the axis along which the player is furthest away.
|
||||||||||||
| FindDirectionToPlayer | 56729 | LD HL,(48271) | Work out the distance along the X axis from the object to the player. | |||||||||
| 56732 | LD E,(IX+1) | |||||||||||
| 56735 | LD D,(IX+2) | |||||||||||
| 56738 | AND A | |||||||||||
| 56739 | SBC HL,DE | |||||||||||
| 56741 | PUSH HL | Stash the signed distance on the stack. | ||||||||||
| 56742 | BIT 7,H | Make it positive, and keep it in DE. | ||||||||||
| 56744 | CALL NZ,NegateHL | |||||||||||
| 56747 | EX DE,HL | |||||||||||
| 56748 | LD HL,(48273) | Work out the distance along the Y axis from the object to the player. | ||||||||||
| 56751 | LD C,(IX+3) | |||||||||||
| 56754 | LD B,(IX+4) | |||||||||||
| 56757 | AND A | |||||||||||
| 56758 | SBC HL,BC | |||||||||||
| 56760 | PUSH HL | Stash the signed distance on the stack. | ||||||||||
| 56761 | BIT 7,H | Make it positive. | ||||||||||
| 56763 | CALL NZ,NegateHL | |||||||||||
| 56766 | AND A | Compare it with the distance along the X axis, and start with the direction up the screen. | ||||||||||
| 56767 | SBC HL,DE | |||||||||||
| 56769 | LD A,0 | |||||||||||
| 56771 | POP HL | Restore the distances from the stack. | ||||||||||
| 56772 | POP DE | |||||||||||
| 56773 | JR NC,FindDirectionToPlayer_Sign | Jump to FindDirectionToPlayer_Sign if the player is further along the Y axis. | ||||||||||
| 56775 | INC A | Use the direction to the right, and use the distance along the X axis. | ||||||||||
| 56776 | EX DE,HL | |||||||||||
|
Reverse the direction if the player is at a negative distance.
|
||||||||||||
| FindDirectionToPlayer_Sign | 56777 | BIT 7,H | Return if the player is not at a negative distance. | |||||||||
| 56779 | RET Z | |||||||||||
| 56780 | ADD A,2 | Use the opposite direction, and return. | ||||||||||
| 56782 | RET | |||||||||||
| Prev: 56690 | Up: Map | Next: 56783 |