Prev: B814 Up: Map Next: B873
B81C: Slide Actor Past Objects
Stops an actor moving through the objects of the room. The new position of the actor is tested with TestObjectOverlap against each of the objects in the layout of the room (the pointers to the layouts are in RoomTable, found from the room with Layout). If it overlaps with an object then the movement is tried in the X direction only and the Y direction only so that the actor can slide along the object. If neither works then the actor is left where it was.
The Y position of an actor is the position of its feet, and the Y position of an object is the top of it.
Input
B Height of the actor
C Width of the actor
DE New position of the actor, with Y in D and X in E
IX Actor record
Output
DE The position that the actor can move to
SlideActorPastObjects B81C PUSH IX Stash the actor record and the size of the actor on the stack.
B81E PUSH BC
B81F LD L,(IX+$03) Fetch the X position of the actor.
B822 LD H,(IX+$04) Fetch the Y position of the actor.
B825 LD ($96AE),HL Remember the old X position in Actor_Old_X_Position and the old Y position in Actor_Old_Y_Position.
B828 LD L,(IX+$01) Fetch the room of the actor.
B82B LD H,$00 Clear H.
B82D LD BC,$6066 Add the layout table at Layout to find the layout number of the room.
B830 ADD HL,BC
B831 LD L,(HL) Fetch the layout number of the room.
B832 LD H,$00 Clear H.
B834 ADD HL,HL Double it, as each pointer is two bytes.
B835 LD BC,$6166 Add the table of object lists at RoomTable to find the pointer to the list of objects.
B838 ADD HL,BC
B839 LD A,(HL) Fetch the low byte of the address of the list of objects.
B83A INC HL Move to the high byte.
B83B LD H,(HL) Fetch the high byte of the address of the list of objects.
B83C LD L,A Combine the low byte with the high byte.
B83D PUSH HL Point IX at the list of objects.
B83E POP IX
B840 POP BC Restore the size of the actor from the stack.
Test the new position.
B841 PUSH IX Stash the pointer to the list of objects on the stack.
B843 CALL TestObjectOverlap Test whether the new position overlaps with an object.
B846 POP IX Restore the pointer to the list of objects from the stack.
B848 JR NC,SlideActorPastObjects_Return Jump to SlideActorPastObjects_Return if the new position does not overlap with an object.
Try moving in the X direction only.
B84A PUSH DE Stash the new position on the stack.
B84B LD A,($96AF) Fetch the old Y position.
B84E LD D,A Use the old Y position instead.
B84F PUSH IX Stash the pointer to the list of objects on the stack.
B851 CALL TestObjectOverlap Test whether moving in the X direction only overlaps with an object.
B854 POP IX Restore the pointer to the list of objects from the stack.
B856 POP DE Restore the new position from the stack.
B857 JR NC,SlideActorPastObjects_Vertical Jump to SlideActorPastObjects_Vertical if the actor can move in the X direction.
B859 LD A,($96AE) Keep the old X position, as the actor cannot move in the X direction.
B85C LD E,A
Try moving in the Y direction only.
SlideActorPastObjects_Vertical B85D PUSH DE Stash the new position on the stack.
B85E LD A,($96AE) Use the old X position instead.
B861 LD E,A
B862 PUSH IX Stash the pointer to the list of objects on the stack.
B864 CALL TestObjectOverlap Test whether moving in the Y direction only overlaps with an object.
B867 POP IX Restore the pointer to the list of objects from the stack.
B869 POP DE Restore the new position from the stack.
B86A JR NC,SlideActorPastObjects_Return Jump to SlideActorPastObjects_Return if the actor can move in the Y direction.
B86C LD A,($96AF) Keep the old Y position, as the actor cannot move in the Y direction.
B86F LD D,A
SlideActorPastObjects_Return B870 POP IX Restore the actor record from the stack.
B872 RET Return.
Prev: B814 Up: Map Next: B873