Prev: 57740 Up: Map Next: 57970
57780: Check Bubble Contact
Checks whether an object is touching one of the four bubbles (the object records that start at First_Bubble_Record and have the type 88 to 91).
No bubble is touched if bit 4 or bit 5 of the countdown in byte 10 is set. This is the case for Sabreman for a while after he has started to fall, and it lets him get away from a bubble.
An object touches a bubble when the two are in the same room, the x positions differ by less than 13 and the y position of the object is between zero and 14 pixels above the y position of the bubble.
When there is contact the result in C has bit 2 and bit 1 set (a bubble is always taken as being under the object). Bit 7 is set if the object is to the right of the bubble. Bits 5 and 0 are set if the x positions differ by 10 or more, which means that the object is not near the middle of the bubble. Otherwise the y position of the object is set to 14 less than that of the bubble so that it stands on it, and bit 4 of E and bit 4 of the contact flags (byte 11) are set.
If the object is Sabreman (the type is between 9 and 27) and he is touching a bubble while he is near the top of the room (the y position is less than 72) then the bubble pushes him up. In a room with a ceiling he starts tumbling (see Start_Tumbling_Downwards), which draws him and ends the handler that called this routine. In a room with no ceiling he moves into the room above, if his y position is less than 44. The y position then becomes 175 the first bubble record becomes a copy of the record of Sabreman as a bubble (88) at the y position 184 and the new room is drawn.
Input
IX Object record
E Flags of the room (see Read_World_Map)
Output
B 160 less the y position of the object (valid when there is contact)
C Contact result
E Flags of the room, with bit 4 set if the object stands on a bubble
Check_Bubble_Contact 57780 LD C,0 Set the contact result to zero.
57782 LD A,(IX+10) Fetch the countdown.
57785 AND %00110000 Keep only bits 4 and 5.
57787 RET NZ Return if either of them is set.
57788 PUSH DE Stash the flags of the room.
57789 LD HL,36698 Point HL at First_Bubble_Record.
57792 LD DE,16 Set DE to the size of an object record.
57795 LD B,4 Set a counter in B for the four bubble records.
Check_Bubble_Contact_Loop 57797 LD A,(HL) Fetch the type of the record.
57798 AND %11111100 Ignore the two low bits.
57800 CP 88 Jump to Check_Bubble_Contact_Found if the record holds a bubble.
57802 JR Z,Check_Bubble_Contact_Found
Check_Bubble_Contact_Next_Record 57804 ADD HL,DE Move on to the next record.
57805 DJNZ Check_Bubble_Contact_Loop Decrease the record counter and loop back for the next record.
57807 LD C,0 Clear the contact result, as no bubble was touched.
57809 POP DE Restore the flags of the room.
57810 RET Return.
Check_Bubble_Contact_Skip 57811 POP HL Discard the address of the bubble record.
57812 JR Check_Bubble_Contact_Next_Record Jump to Check_Bubble_Contact_Next_Record to try the next bubble.
Check_Bubble_Contact_Found 57814 PUSH HL Stash the address of the bubble record.
57815 LD C,0 Clear the contact result.
57817 INC HL Point HL at the x position of the bubble.
57818 LD A,(HL) Fetch the x position of the bubble.
57819 SUB (IX+1) Jump to Check_Bubble_Contact_Check_Width if the object is not to the right of the bubble.
57822 JP P,Check_Bubble_Contact_Check_Width
57825 NEG Make the difference positive.
57827 SET 7,C Set bit 7 of the contact result, as the object is to the right of the bubble.
Check_Bubble_Contact_Check_Width 57829 CP 13 Jump to Check_Bubble_Contact_Skip if the difference is 13 or more.
57831 JR NC,Check_Bubble_Contact_Skip
57833 CP 10 Jump to Check_Bubble_Contact_Check_Room if the difference is less than 10.
57835 JR C,Check_Bubble_Contact_Check_Room
57837 SET 5,C Set bit 5 of the contact result.
57839 SET 0,C Set bit 0 of the contact result.
Check_Bubble_Contact_Check_Room 57841 INC HL Point HL at the room x of the bubble.
57842 LD A,(HL) Fetch the room x of the bubble.
57843 CP (IX+2) Jump to Check_Bubble_Contact_Skip if the bubble is in a different room x.
57846 JR NZ,Check_Bubble_Contact_Skip
57848 INC HL Point HL at the y position of the bubble.
57849 LD A,(HL) Fetch the y position of the bubble.
57850 SUB (IX+3) Subtract the y position of the object.
57853 CP 15 Jump to Check_Bubble_Contact_Skip if the object is more than 14 above the bubble, or below it.
57855 JR NC,Check_Bubble_Contact_Skip
57857 INC HL Point HL at the room y of the bubble.
57858 LD A,(HL) Fetch the room y of the bubble.
57859 CP (IX+4) Jump to Check_Bubble_Contact_Skip if the bubble is in a different room y.
57862 JR NZ,Check_Bubble_Contact_Skip
57864 DEC HL Point HL at the y position of the bubble again.
57865 SET 2,C Set bit 2 of the contact result (contact).
57867 SET 1,C Set bit 1 of the contact result (the object is on top).
57869 BIT 0,C Jump to Check_Bubble_Contact_Set_Height if the object is not near the middle of the bubble.
57871 JR NZ,Check_Bubble_Contact_Set_Height
57873 LD A,(HL) Fetch the y position of the bubble.
57874 SUB 14 Subtract 14.
57876 LD (IX+3),A Set the y position of the object, so that it stands on the bubble.
Check_Bubble_Contact_Set_Height 57879 LD A,(IX+3) Fetch the y position of the object.
57882 SUB 160 Subtract 160.
57884 NEG Negate it.
57886 LD B,A Store the result in B.
57887 POP HL Discard the address of the bubble record.
57888 POP DE Restore the flags of the room to E.
57889 BIT 0,C Jump to Check_Bubble_Contact_Check_Type if the object is not near the middle of the bubble.
57891 JR NZ,Check_Bubble_Contact_Check_Type
57893 SET 4,E Set bit 4 of the flags of the room (the floor).
57895 SET 4,(IX+11) Set bit 4 of the contact flags (standing).
Check_Bubble_Contact_Check_Type 57899 LD A,(IX+0) Fetch the type of the object.
57902 CP 28 Return if the type is 28 or more.
57904 RET NC
57905 CP 9 Return if the type is less than 9.
57907 RET C
57908 LD A,(IX+3) Fetch the y position of the object.
57911 CP 72 Return if it is 72 or more.
57913 RET NC
57914 BIT 0,E Jump to Check_Bubble_Contact_Tumble if the room has a ceiling.
57916 JR NZ,Check_Bubble_Contact_Tumble
57918 CP 44 Return if the y position is 44 or more.
57920 RET NC
57921 DEC (IX+4) Move Sabreman to the room above.
57924 LD (IX+3),175 Set his y position to 175.
57928 LD B,241 Set B to 241 which is 160 less the new y position.
57930 PUSH DE Stash the flags of the room.
57931 PUSH BC Stash the contact result and B.
57932 LD DE,36698 Point DE at First_Bubble_Record.
57935 LD HL,36634 Point HL at Sabreman_Record.
57938 LD BC,15 Set a counter of 15 bytes.
57941 LDIR Copy the record of Sabreman to the bubble record.
57943 LD A,184 Set the y position of the bubble to 184.
57945 LD (36701),A Store the y position of the bubble.
57948 LD A,88 Set the type of the bubble to 88.
57950 LD (36698),A Store the type of the bubble.
57953 LD A,1 Set the redraw flags of the bubble to 1.
57955 LD (36713),A Store the redraw flags of the bubble.
57958 LD A,70 Set the attribute of the bubble to 70 (yellow).
57960 LD (36703),A Store the attribute of the bubble.
57963 CALL Draw_Room Draw the room.
57966 POP BC Restore the contact result and B.
57967 POP DE Restore the flags of the room.
57968 RET Return.
Check_Bubble_Contact_Tumble 57969 POP HL Discard the return address, so that the handler of Sabreman that called this routine stops here.
Prev: 57740 Up: Map Next: 57970