Prev: BF66 Up: Map Next: C00E
BF79: Handle Pickup And Drop
Used by the routine at HandlePlayerLegs.
Deals with the key for picking up and dropping objects. The key only does something once for each time that it is pressed, and only if the player is standing on the ground, away from the walls.
If the player is touching an object that can be carried, it is picked up. The player carries three objects at most, so if the carried objects are all in use the oldest one is dropped in its place. If the player is not touching anything, the object that is in the last place of the inventory (the oldest one) is dropped, if there is a free object record and nothing is in the way above the player. When that place is empty, the carried objects are only moved along one place towards it.
An object is dropped by creating it in a free object record, at the position of the player, who is moved up out of the way.
Input
IX Record of the object of the legs of the player
Do nothing if the key is still being held down from the last time.
HandlePickupAndDrop BF79 LD A,($A740) Fetch the flag from PickupDropPressedFlag.
BF7C AND A Jump to CheckActionKeyReleased if the key was already being held down.
BF7D JP NZ,CheckActionKeyReleased
The key was not being held, so find out if it is pressed, and if the player is able to pick things up or drop them.
BF80 CALL TestPickupDropKey Return if the key is not being pressed.
BF83 RET Z
BF84 CALL TestPlayerInRoom Return if the player is touching a wall.
BF87 RET NC
BF88 BIT 3,(IX+$0C) Return if the player is jumping.
BF8C RET NZ
BF8D BIT 2,(IX+$0C) Return if the player is not on the ground.
BF91 RET Z
BF92 XOR A Clear the flag that says that there is no room to drop an object.
BF93 LD ($A741),A
BF96 LD A,(IX+$03) Stash the height of the player in B.
BF99 LD B,A
BF9A ADD A,$0C Raise the player by 0C.
BF9C LD (IX+$03),A
BF9F CALL TestObjectIntersections Call TestObjectIntersections to find out if there is room for the player there.
BFA2 LD (IX+$03),B Put the player back where it was.
BFA5 JR NC,HandlePickupAndDrop_Start Jump to HandlePickupAndDrop_Start if there is room.
BFA7 LD A,$01 Set the flag that says that there is no room to drop an object.
BFA9 LD ($A741),A
HandlePickupAndDrop_Start BFAC LD A,$01 Set the flag that says that the key is being held down.
BFAE LD ($A740),A
BFB1 LD ($A720),A Set the flag to redraw the inventory in ObjectsCarriedChangedFlag.
BFB4 LD B,$30 Set a counter in B of the number of ordinary object records, which is 30.
Make the player larger by 04 along each axis, so that it can touch objects that are close.
BFB6 LD L,(IX+$04) Make the half size along x larger by 04.
BFB9 LD A,L
BFBA ADD A,$04
BFBC LD (IX+$04),A
BFBF LD H,(IX+$05) Make the half size along y larger by 04.
BFC2 LD A,H
BFC3 ADD A,$04
BFC5 LD (IX+$05),A
BFC8 PUSH HL Stash the old half sizes along x and y on the stack.
BFC9 LD L,(IX+$06) Make the size along z larger by 04.
BFCC LD A,L
BFCD ADD A,$04
BFCF LD (IX+$06),A
BFD2 PUSH HL Stash the old size along z on the stack.
BFD3 LD IY,$A82F Start with the first ordinary object record, ObjectsTable_RoomObjects.
Look for an object that can be picked up.
HandlePickupAndDrop_Search BFD7 CALL TestObjectCanBePickedUp Call TestObjectCanBePickedUp to test if the object can be picked up and touches the player.
BFDA JP C,PickUpObject Jump to PickUpObject to pick it up if it does.
BFDD LD DE,$0020 Move on to the next object record.
BFE0 ADD IY,DE
BFE2 DJNZ HandlePickupAndDrop_Search Decrease the counter and loop until all the records have been tried.
Nothing can be picked up, so look for a free object record to drop an object in.
BFE4 CALL TestPickupDropKey Jump to HandlePickupAndDrop_Done if the key is no longer pressed.
BFE7 JR Z,HandlePickupAndDrop_Done
BFE9 LD DE,$0020 Set the size of an object record in DE.
BFEC LD B,$30 Set a counter in B of the number of ordinary object records.
BFEE LD IY,$A82F Start with the first ordinary object record.
HandlePickupAndDrop_FindFree BFF2 LD A,(IY+$00) Jump to DropObject to drop an object if this record is free.
BFF5 AND A
BFF6 JR Z,DropObject
BFF8 ADD IY,DE Advance to the next record and loop until all of them have been tried.
BFFA DJNZ HandlePickupAndDrop_FindFree
This entry point is used by the routine at DropObject.
Put the size of the player back to what it was, and make a noise.
HandlePickupAndDrop_Done BFFC POP HL Restore the old size along z from the stack.
BFFD LD (IX+$06),L
C000 POP HL Restore the old half sizes along x and y from the stack.
C001 LD (IX+$04),L Put the old half sizes back.
C004 LD (IX+$05),H
C007 LD HL,$0105 Start a sound effect with a type of 01 and a count of 05.
C00A LD ($A749),HL
C00D RET Return.
View the equivalent code in;
Prev: BF66 Up: Map Next: C00E