Prev: B43E Up: Map Next: B4CD
B46A: Check Object Contact
Used by the routine at Check_Decoration_Contact.
Checks whether the object at IX touches the object at IY, which is an obstacle. The bytes 0A to 0E of the obstacle record are not used for movement. Instead they describe the size of the obstacle: its half width (byte 0A), the width of its middle (byte 0B), its height (byte 0C), the depth from the top at which the object counts as being beside it (byte 0D) and the offset of the middle from its x position (byte 0E). The y position of an obstacle is the position of its bottom.
The result is returned in C. Bit 2 is set if the objects touch. Bit 7 is set if IX is on the right of the middle of the obstacle. Bit 0 is set if IX is outside the width of the middle. Bit 1 is set if the bottom of IX is in the top part of the obstacle (so that it is standing or landing on it).
When the object touches the top of the obstacle, bit 4 of its contact flags is set (so it is standing on it) unless it is a weapon pickup (see Handle_Weapon_Pickup) or it is outside the width of the middle. An obstacle of type 88 is handled by Check_Rock_Formation_Contact instead.
Input
IX Object record
IY Obstacle record
Output
C Contact result
AF' A0 less the y position of the top of the obstacle
Check_Object_Contact B46A LD C,$00 Clear the contact result.
B46C LD A,(IY+$00) Fetch the type of the obstacle.
B46F AND A Return if the obstacle record is empty.
B470 RET Z
B471 BIT 0,(IY+$0F) Return if the obstacle has just been created.
B475 RET NZ
B476 CP $88 Jump to Check_Rock_Formation_Contact if the obstacle is a type 88 object.
B478 JP Z,Check_Rock_Formation_Contact
B47B LD A,(IY+$01) Fetch the x position of the obstacle.
B47E ADD A,(IY+$0E) Add the offset of its middle.
B481 SUB (IX+$01) Jump to Check_Object_Contact_Test_Distance if the object is on the left of the middle of the obstacle.
B484 JP P,Check_Object_Contact_Test_Distance
B487 NEG Make the distance positive.
B489 SET 7,C Set bit 7 of the result, as the object is on the right.
Check_Object_Contact_Test_Distance B48B CP (IY+$0A) Jump to Check_Object_Contact_None if the distance is too great for them to touch.
B48E JR NC,Check_Object_Contact_None
B490 CP (IY+$0B) Jump to Check_Object_Contact_Test_Height if the object is inside the width of the middle.
B493 JR C,Check_Object_Contact_Test_Height
B495 SET 0,C Set bit 0 of the result, as the object is outside the middle.
Check_Object_Contact_Test_Height B497 LD A,(IY+$03) Fetch the y position of the obstacle.
B49A SUB (IX+$03) Jump to Check_Object_Contact_None if the object is below the bottom of the obstacle.
B49D JP M,Check_Object_Contact_None
B4A0 PUSH AF Stash the distance.
B4A1 LD A,(IY+$03) Work out the y position of the top of the obstacle.
B4A4 SUB (IY+$0C)
B4A7 SUB $A0 Subtract it from A0.
B4A9 NEG
B4AB EX AF,AF' Keep the result in AF'.
B4AC POP AF Restore the distance.
B4AD CP (IY+$0C) Jump to Check_Object_Contact_None if the distance is the height of the obstacle or more.
B4B0 JR NC,Check_Object_Contact_None
B4B2 SET 2,C Set bit 2 of the result, as the objects touch.
B4B4 CP (IY+$0D) Return if the distance is less than the depth in byte 0D of the obstacle.
B4B7 RET C
B4B8 SET 1,C Set bit 1 of the result, as the object is on top of the obstacle.
B4BA LD A,(IX+$00) Fetch the type of the object.
B4BD AND %11111100 Reset the two low bits.
B4BF CP $68 Return if the object is a weapon pickup.
B4C1 RET Z
B4C2 BIT 0,C Return if the object is outside the width of the middle.
B4C4 RET NZ
B4C5 SET 4,(IX+$0B) Set bit 4 of the contact flags of the object, as it is standing on the obstacle.
B4C9 RET Return.
This entry point is used by the routine at Check_Rock_Formation_Contact.
Check_Object_Contact_None B4CA LD C,$00 Clear the result, as the objects do not touch.
B4CC RET Return.
Prev: B43E Up: Map Next: B4CD