Prev: 637E Up: Map Next: 63E1
63AA: Check Bug Leaf Collision
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 63AA LD HL,$5E94 HL=Leaf_1_State (the first leaf object).
63AD LD B,$04 Set the leaf counter to 04.
63AF LD DE,$0008 DE=08 (the size of an object, used to move onto the next leaf).
LeafCollision_Loop 63B2 PUSH HL Stash the address of the leaf on the stack.
63B3 LD A,(HL) If the current leaf is not active, jump to LeafCollision_Next.
63B4 AND A
63B5 JR Z,LeafCollision_Next
Is the leaf within 09 pixels of the bug horizontally?
63B7 INC HL A=the X position of the leaf.
63B8 LD A,(HL)
63B9 SUB (IX+$01) Subtract the X position of the bug.
63BC JP P,LeafCollision_Test_X Make the horizontal distance positive.
63BF NEG
LeafCollision_Test_X 63C1 CP $0A Jump to LeafCollision_Next if the leaf is 0A or more pixels away.
63C3 JR NC,LeafCollision_Next
Is the leaf within 09 pixels of the bug vertically?
63C5 INC HL A=the Y position of the leaf.
63C6 LD A,(HL)
63C7 SUB (IX+$02) Subtract the Y position of the bug.
63CA JP P,LeafCollision_Test_Y Make the vertical distance positive.
63CD NEG
LeafCollision_Test_Y 63CF CP $0A Jump to LeafCollision_Next if the leaf is 0A or more pixels away.
63D1 JR NC,LeafCollision_Next
The bug is on the leaf, so the leaf starts to shrink away.
63D3 INC HL Skip the colour attribute to point to the leaf animating flag.
63D4 INC HL
63D5 LD A,$01 Write 01 to the animating flag and the "being eaten" flag of the leaf (see UpdateLeaf).
63D7 LD (HL),A
63D8 INC HL
63D9 LD (HL),A
63DA POP HL Restore the address of the leaf from the stack.
63DB RET Return.
Move onto the next leaf object.
LeafCollision_Next 63DC POP HL Restore HL from the stack.
63DD ADD HL,DE Add the object size to move onto the next leaf.
63DE DJNZ LeafCollision_Loop Decrease the leaf counter by one and loop back to LeafCollision_Loop until all four leaves have been checked.
63E0 RET Return.
Prev: 637E Up: Map Next: 63E1