Prev: 47009 Up: Map Next: 47228
47091: Berk Interact With Entity
Test horizontal alignment with the last-collided entity (Pointer_LastCollidedEntity); on match clear bit 2 of IX+3.
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 47091 LD IY,(29354) Load IY with the last-collided entity pointer (Pointer_LastCollidedEntity).
47095 LD C,(IY+0) Load C with the referenced entity's entity type.
47098 LD A,(IY+8) Load A with the referenced entity's x-extent.
47101 SUB (IY+7) Subtract the referenced entity's x-coordinate from A.
47104 SRL A Shift the flag/value in A right one bit.
47106 ADD A,(IY+7) Add the referenced entity's x-coordinate to A.
47109 SUB 2 Subtract 2 from A.
47111 CP (IX+7) Does A match this entity's x-coordinate? If not, return.
47114 RET NZ
47115 RES 2,(IX+3) Reset bit 2 of the current entity's flags byte 3.
47119 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 47120 RES 1,(IX+3) Clear Berk's facing-left flag (bit 1 of IX+3) so he faces right-to-left motion.
47124 LD A,(IX+4) Fetch Berk's room index.
47127 CP 0 Is Berk in room 0? If not, continue the left-walk at Berk_WalkLeft_TestEntityOnRight.
47129 JR NZ,Berk_WalkLeft_TestEntityOnRight
47131 LD A,(IX+6) Fetch Berk's y-extent.
47134 CP 27 Is he still on the trap door row (y-extent 27)? If not, continue the current script at AdvanceScriptInstruction.
47136 JP NZ,AdvanceScriptInstruction
Left walk outside room 0: test an entity on the right before turning or interacting.
Berk_WalkLeft_TestEntityOnRight 47139 CALL Test_EntityOnRight Call Test_EntityOnRight to test Entity On Right? If not, jump to Berk_Interact_With_Entity_Branch.
47142 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 47144 BIT 1,(IX+9) Is bit 1 of the current entity's direction / state set? If so, jump to AdvanceScriptInstruction.
47148 JP NZ,AdvanceScriptInstruction
47151 LD HL,47747 Point HL at Berk control/put-down script data (BerkPutDownScript_WalkLeftFace).
47154 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
Left interact by height: close the trap door at y-extent 64, or take trap scripts at 57.
Berk_Interact_With_Entity_Branch 47157 CP 57 Is the current entity's y-extent equal to 57? If so, jump to Berk_Pick_Up_Entity_TrapDoorScripts.
47159 JR Z,Berk_Pick_Up_Entity_TrapDoorScripts
47161 CP 64 Is the current entity's y-extent equal to 64? If not, jump to Berk_WalkLeft_BelowBand.
47163 JR NZ,Berk_WalkLeft_BelowBand
47165 BIT 1,(IX+9) Is bit 1 of the current entity's direction / state set? If not, jump to Berk_ReadControls_Idle.
47169 JP Z,Berk_ReadControls_Idle
47172 CALL Close_TrapDoor Call Close_TrapDoor to close the trap door.
47175 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 47178 CP 50 Is the current entity's y-extent less than 50? If not, jump to Berk_ReadControls_Idle.
47180 JP NC,Berk_ReadControls_Idle
47183 BIT 4,(IX+3) Is bit 4 of flags byte 3 (IX+3) set? If so, jump to Berk_WalkLeft_FacingScript.
47187 JR NZ,Berk_WalkLeft_FacingScript
47189 LD BC,(29354) Load BC with the last-collided entity pointer (Pointer_LastCollidedEntity).
47193 INC BC Advance the counter/pointer in BC by one.
47194 LD A,(BC) Fetch a byte through the pointer in BC.
47195 AND %00010000 Keep only bit 4 of the flag byte in A (mask 16).
47197 JR NZ,Berk_WalkLeft_FacingScript If the result was non-zero, jump to Berk_WalkLeft_FacingScript.
47199 BIT 3,(IX+3) Is bit 3 of flags byte 3 (IX+3) set? If so, jump to Berk_WalkLeft_TryPickUp.
47203 JR NZ,Berk_WalkLeft_TryPickUp
47205 BIT 1,(IX+9) Is bit 1 of the current entity's direction / state set? If so, jump to AdvanceScriptInstruction.
47209 JP NZ,AdvanceScriptInstruction
Try Berk_Pick_Up_Entity to pick up; on success lock held-state and run script 47873.
Berk_WalkLeft_TryPickUp 47212 CALL Berk_Pick_Up_Entity Call Berk_Pick_Up_Entity to let Berk pick up an entity? If not, jump to Berk_ReadControls_Idle.
47215 JP NC,Berk_ReadControls_Idle
47218 SET 3,(IX+3) Set bit 3 of the current entity's flags byte 3.
47222 LD HL,47873 Point HL at Berk control/put-down script data (47873).
47225 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
Prev: 47009 Up: Map Next: 47228