![]() |
Routines |
| Prev: 39086 | Up: Map | Next: 39180 |
|
Used by the routines at CreateShot, UpdatePickupEntity, UpdateFoamEntity, UpdateWhirlerEntity, UpdateBatEntity and UpdateSaucerEntity.
Chooses the direction in which an entity should head to move towards the player. If the direction (bits 4 and 5 of field 32 of the entity) is already the right one it is left alone, otherwise the new direction is set along with a random value in bits 1-3.
|
||||||||
| FacePlayer | 39123 | LD B,0 | Clear the direction bits in B. | |||||
| 39125 | LD A,(46402) | Fetch the first byte of the first coordinate of the player from 46402. | ||||||
| 39128 | SUB (IX+2) | Subtract the first byte of the first coordinate of the entity. | ||||||
| 39131 | JR NZ,FacePlayer_FirstDone | Jump to FacePlayer_FirstDone if they are different. | ||||||
| 39133 | LD A,(46403) | Fetch the second byte of the first coordinate of the player from 46403. | ||||||
| 39136 | SUB (IX+3) | Subtract the second byte of the first coordinate of the entity. | ||||||
| FacePlayer_FirstDone | 39139 | JR NC,FacePlayer_Second | Jump to FacePlayer_Second if the player is not before the entity on the first coordinate. | |||||
| 39141 | LD B,16 | Set bit 4 of the direction. | ||||||
| FacePlayer_Second | 39143 | LD A,(46405) | Fetch the first byte of the second coordinate of the player from 46405. | |||||
| 39146 | SUB (IX+5) | Subtract the first byte of the second coordinate of the entity. | ||||||
| 39149 | JR NZ,FacePlayer_SecondDone | Jump to FacePlayer_SecondDone if they are different. | ||||||
| 39151 | LD A,(46406) | Fetch the second byte of the second coordinate of the player from 46406. | ||||||
| 39154 | SUB (IX+6) | Subtract the second byte of the second coordinate of the entity. | ||||||
| FacePlayer_SecondDone | 39157 | LD A,B | Fetch the direction. | |||||
| 39158 | JR NC,FacePlayer_Compare | Jump to FacePlayer_Compare if the player is not before the entity on the second coordinate. | ||||||
| 39160 | XOR %00110000 | Flip bits 4 and 5 of the direction. | ||||||
| FacePlayer_Compare | 39162 | LD B,A | Keep the direction in B. | |||||
| 39163 | LD A,(IX+32) | Read field 32 of the entity. | ||||||
| 39166 | AND %00110000 | Use bits 4 and 5. | ||||||
| 39168 | XOR B | Compare them with the new direction. | ||||||
| 39169 | RET Z | Return if the entity is already heading that way. | ||||||
| 39170 | LD A,(24474) | Fetch the low byte of the random seed from RandomNumber_Seed. | ||||||
| 39173 | AND %00001110 | Use bits 1-3. | ||||||
| 39175 | OR B | Add the new direction. | ||||||
| 39176 | LD (IX+32),A | Store it in field 32 of the entity. | ||||||
| 39179 | RET | Return. | ||||||
| Prev: 39086 | Up: Map | Next: 39180 |