Prev: 29417 Up: Map Next: 29477
29429: Check Bug Robbie Collision
Used by the routine at UpdateBugCommon.
Tests whether a bug is touching Robbie. Robbie only counts when his state is 1 or 2 (empty-handed or carrying a can), so a collision cannot happen while he is exploding.
The two collide when their X positions differ by less than 16 and their Y positions are close enough. The vertical limit is 18 when Robbie is lower down the screen than the bug, or the bug's height (from *IX+7) when the bug is lower down.
Input
IX Bug object
Output
E 0 No collision
E 1 Collision
BugCollision 29429 LD HL,24172 HL=State_Robbie_Active (Robbie).
29432 LD E,0 E=0 (the default result, no collision).
29434 LD A,(HL) Fetch Robbie's state.
29435 AND %00111111 Keep only bits 0-5.
29437 DEC A Decrease the state of Robbie by one (zero if he is empty-handed).
29438 JR Z,BugCollision_X Jump to BugCollision_X if Robbie is empty-handed (state 1).
29440 DEC A Decrease A by one again.
29441 RET NZ Return if Robbie is not carrying a can (state 2).
Check the horizontal distance.
BugCollision_X 29442 INC HL A=Robbie's X position (from State_Robbie_Pos_X).
29443 LD A,(HL)
29444 SUB (IX+1) Subtract the bug's X position.
29447 JP P,BugCollision_Test_X Make sure the difference is positive.
29450 NEG
BugCollision_Test_X 29452 CP 16 Return if the difference is 16 or more.
29454 RET NC
Check the vertical distance.
29455 INC HL Move on to Robbie's Y position.
This entry point is used by the routine at CreateBug.
BugCollision_Y 29456 LD A,(HL) A=Robbie's Y position (from State_Robbie_Pos_Y).
29457 SUB (IX+2) Subtract the bug's Y position.
29460 JP P,BugCollision_SetHeight Jump to BugCollision_SetHeight if Robbie is lower down the screen than the bug.
29463 NEG Make the difference positive.
29465 LD D,(IX+7) D=the bug's height (from *IX+7).
29468 JR BugCollision_Test_Y Jump to BugCollision_Test_Y.
BugCollision_SetHeight 29470 LD D,18 D=18.
BugCollision_Test_Y 29472 CP D Return if the difference is D or more.
29473 RET NC
A collision has been detected.
See Immunity.
29474 LD E,1 E=1.
29476 RET Return.
Prev: 29417 Up: Map Next: 29477