![]() |
Routines |
| Prev: 25470 | Up: Map | Next: 25569 |
|
Used by the routine at UpdateBugCommon.
Checks whether the bug being updated (IX) is touching any of the four leaf objects. If it is on top of an active leaf, the leaf is marked as being eaten and it returns straight away, so only one leaf is eaten at a time.
|
||||
| LeafCollision | 25514 | LD HL,24212 | HL=Leaf_1_State (the first leaf object). | |
| 25517 | LD B,4 | Set the leaf counter to 4. | ||
| 25519 | LD DE,8 | DE=8 (the size of an object, used to move onto the next leaf). | ||
| LeafCollision_Loop | 25522 | PUSH HL | Stash the address of the leaf on the stack. | |
| 25523 | LD A,(HL) | If the current leaf is not active, jump to LeafCollision_Next. | ||
| 25524 | AND A | |||
| 25525 | JR Z,LeafCollision_Next | |||
|
Is the leaf within 9 pixels of the bug horizontally?
|
||||
| 25527 | INC HL | A=the X position of the leaf. | ||
| 25528 | LD A,(HL) | |||
| 25529 | SUB (IX+1) | Subtract the X position of the bug. | ||
| 25532 | JP P,LeafCollision_Test_X | Make the horizontal distance positive. | ||
| 25535 | NEG | |||
| LeafCollision_Test_X | 25537 | CP 10 | Jump to LeafCollision_Next if the leaf is 10 or more pixels away. | |
| 25539 | JR NC,LeafCollision_Next | |||
|
Is the leaf within 9 pixels of the bug vertically?
|
||||
| 25541 | INC HL | A=the Y position of the leaf. | ||
| 25542 | LD A,(HL) | |||
| 25543 | SUB (IX+2) | Subtract the Y position of the bug. | ||
| 25546 | JP P,LeafCollision_Test_Y | Make the vertical distance positive. | ||
| 25549 | NEG | |||
| LeafCollision_Test_Y | 25551 | CP 10 | Jump to LeafCollision_Next if the leaf is 10 or more pixels away. | |
| 25553 | JR NC,LeafCollision_Next | |||
|
The bug is on the leaf, so the leaf starts to shrink away.
|
||||
| 25555 | INC HL | Skip the colour attribute to point to the leaf animating flag. | ||
| 25556 | INC HL | |||
| 25557 | LD A,1 | Write 1 to the animating flag and the "being eaten" flag of the leaf (see UpdateLeaf). | ||
| 25559 | LD (HL),A | |||
| 25560 | INC HL | |||
| 25561 | LD (HL),A | |||
| 25562 | POP HL | Restore the address of the leaf from the stack. | ||
| 25563 | RET | Return. | ||
|
Move onto the next leaf object.
|
||||
| LeafCollision_Next | 25564 | POP HL | Restore HL from the stack. | |
| 25565 | ADD HL,DE | Add the object size to move onto the next leaf. | ||
| 25566 | DJNZ LeafCollision_Loop | Decrease the leaf counter by one and loop back to LeafCollision_Loop until all four leaves have been checked. | ||
| 25568 | RET | Return. | ||
| Prev: 25470 | Up: Map | Next: 25569 |