Prev: B7A1 Up: Map Next: B87C
B7F3: Berk Interact With Entity
Test horizontal alignment with the last-collided entity (Pointer_LastCollidedEntity); on match clear bit 02 of IX+03.
Input
IX Address of complex state data for an entity
Handles Berk colliding with doors, the trap door and interactive scenery.
Berk_Interact_With_Entity B7F3 LD IY,($72AA) Load IY with the last-collided entity pointer (Pointer_LastCollidedEntity).
B7F7 LD C,(IY+$00) Load C with the referenced entity's entity type.
B7FA LD A,(IY+$08) Load A with the referenced entity's x-extent.
B7FD SUB (IY+$07) Subtract the referenced entity's x-coordinate from A.
B800 SRL A Shift the flag/value in A right one bit.
B802 ADD A,(IY+$07) Add the referenced entity's x-coordinate to A.
B805 SUB $02 Subtract 02 from A.
B807 CP (IX+$07) Does A match this entity's x-coordinate? If not, return.
B80A RET NZ
B80B RES 2,(IX+$03) Reset bit 02 of the current entity's flags byte 3.
B80F RET Return.
This entry point is used by the routine at Update_Berk_ReadControls.
Handle left: clear facing-left, then walk or turn Berk left.
Berk_WalkLeft B810 RES 1,(IX+$03) Clear Berk's facing-left flag (bit 01 of IX+03) so he faces right-to-left motion.
B814 LD A,(IX+$04) Fetch Berk's room index.
B817 CP $00 Is Berk in room 00? If not, continue the left-walk at Berk_WalkLeft_TestEntityOnRight.
B819 JR NZ,Berk_WalkLeft_TestEntityOnRight
B81B LD A,(IX+$06) Fetch Berk's y-extent.
B81E CP $1B Is he still on the trap door row (y-extent 1B)? If not, continue the current script at AdvanceScriptInstruction.
B820 JP NZ,AdvanceScriptInstruction
Left walk outside room 00: test an entity on the right before turning or interacting.
Berk_WalkLeft_TestEntityOnRight B823 CALL Test_EntityOnRight Call Test_EntityOnRight to test Entity On Right? If not, jump to Berk_Interact_With_Entity_Branch.
B826 JR NC,Berk_Interact_With_Entity_Branch
Already facing the walk-left way: continue the script or run face-left put-down BerkPutDownScript_WalkLeftFace.
Berk_WalkLeft_FacingScript B828 BIT 1,(IX+$09) Is bit 01 of the current entity's direction / state set? If so, jump to AdvanceScriptInstruction.
B82C JP NZ,AdvanceScriptInstruction
B82F LD HL,$BA83 Point HL at Berk control/put-down script data (BerkPutDownScript_WalkLeftFace).
B832 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
Left interact by height: close the trap door at y-extent 40, or take trap scripts at 39.
Berk_Interact_With_Entity_Branch B835 CP $39 Is the current entity's y-extent equal to 39? If so, jump to Berk_Pick_Up_Entity_TrapDoorScripts.
B837 JR Z,Berk_Pick_Up_Entity_TrapDoorScripts
B839 CP $40 Is the current entity's y-extent equal to 40? If not, jump to Berk_WalkLeft_BelowBand.
B83B JR NZ,Berk_WalkLeft_BelowBand
B83D BIT 1,(IX+$09) Is bit 01 of the current entity's direction / state set? If not, jump to Berk_ReadControls_Idle.
B841 JP Z,Berk_ReadControls_Idle
B844 CALL Close_TrapDoor Call Close_TrapDoor to close the trap door.
B847 JP AdvanceScriptInstruction Jump to AdvanceScriptInstruction to run the next script instruction.
Below mid-room on left: either keep walking/turning or attempt a pick-up.
Berk_WalkLeft_BelowBand B84A CP $32 Is the current entity's y-extent less than 32? If not, jump to Berk_ReadControls_Idle.
B84C JP NC,Berk_ReadControls_Idle
B84F BIT 4,(IX+$03) Is bit 04 of flags byte 3 (IX+03) set? If so, jump to Berk_WalkLeft_FacingScript.
B853 JR NZ,Berk_WalkLeft_FacingScript
B855 LD BC,($72AA) Load BC with the last-collided entity pointer (Pointer_LastCollidedEntity).
B859 INC BC Advance the counter/pointer in BC by one.
B85A LD A,(BC) Fetch a byte through the pointer in BC.
B85B AND %00010000 Keep only bit 04 of the flag byte in A (mask 10).
B85D JR NZ,Berk_WalkLeft_FacingScript If the result was non-zero, jump to Berk_WalkLeft_FacingScript.
B85F BIT 3,(IX+$03) Is bit 03 of flags byte 3 (IX+03) set? If so, jump to Berk_WalkLeft_TryPickUp.
B863 JR NZ,Berk_WalkLeft_TryPickUp
B865 BIT 1,(IX+$09) Is bit 01 of the current entity's direction / state set? If so, jump to AdvanceScriptInstruction.
B869 JP NZ,AdvanceScriptInstruction
Try Berk_Pick_Up_Entity to pick up; on success lock held-state and run script BB01.
Berk_WalkLeft_TryPickUp B86C CALL Berk_Pick_Up_Entity Call Berk_Pick_Up_Entity to let Berk pick up an entity? If not, jump to Berk_ReadControls_Idle.
B86F JP NC,Berk_ReadControls_Idle
B872 SET 3,(IX+$03) Set bit 03 of the current entity's flags byte 3.
B876 LD HL,$BB01 Point HL at Berk control/put-down script data (BB01).
B879 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
Prev: B7A1 Up: Map Next: B87C