Prev: 642D Up: Map Next: 6473
644D: Check Bug Flower Collision
Used by the routines at UpdateLeech, UpdateMidges and UpdateSlug.
Checks whether a bug is touching the flower, using a window that is wider for a slug than it is for the midges and the leech. It also only counts when the bug is below the top of the flower.
Input
IX Bug object
Output
E 00 No collision
E 01 Collision
BugFlowerCollision 644D LD E,$00 E=00 (no collision).
644F LD HL,$5E8D HL=State_Flower_Pos_X (the X position of the flower).
Calculate the horizontal distance between the flower and the bug.
6452 LD A,(HL) A=flower X position.
6453 SUB (IX+$01) Subtract the bug X position.
6456 ADD A,$09 Add 09 (so a bug up to 09 pixels to the right of the flower gives zero).
6458 BIT 3,(IX+$00) Jump to BugFlowerCollision_Narrow if the bug is not a slug (bit 3 of the type is set for the midges and the leech).
645C JR NZ,BugFlowerCollision_Narrow
645E CP $24 Compare A with 24 (the width of the window for a slug).
6460 JR BugFlowerCollision_TestX Jump to BugFlowerCollision_TestX.
BugFlowerCollision_Narrow 6462 CP $1C Compare A with 1C (the width of the window for the other bugs).
BugFlowerCollision_TestX 6464 RET NC Return if the bug is too far away horizontally.
Is the bug below the top of the flower?
6465 INC HL Increment HL by one to point to the flower Y position.
6466 LD A,(HL) Halve the flower Y position.
6467 SRL A
6469 LD D,(IX+$02) Halve the bug Y position into D.
646C SRL D
646E SUB D Subtract the halved bug Y position from the halved flower Y position.
646F RET NC Return if the flower is not above the bug.
6470 LD E,$01 E=01 (collision).
6472 RET Return.
Prev: 642D Up: Map Next: 6473