Prev: EA6D Up: Map Next: EAE2
EA73: Reposition Camera-Follow Entity After Interaction
Clear the attribute file via Clear_AttributeFile, then randomly reposition the camera-follow entity (StateData_Berk) and store a Berk script pointer at Pointer_BerkScriptPosition.
Reposition_CameraFollowEntity EA73 LD A,$04 Load A with 04.
EA75 LD ($730A),A Set the camera-follow delay (CameraFollowDelay).
EA78 LD A,$7F Load A with 7F.
EA7A CALL Clear_AttributeFile Call Clear_AttributeFile to clear the attribute file (and play sound).
EA7D EXX Switch to the shadow registers.
EA7E PUSH IX Stash IX on the stack.
EA80 LD IX,$909B Point IX at the camera-follow entity (StateData_Berk).
EA84 LD A,(IX+$07) Load A with the current entity's x-coordinate.
EA87 LD B,$05 Load B with 05.
Divide the follow entity's X by 20 to pick a room-band seed.
Reposition_CameraFollow_ShiftX EA89 SRL A Shift A right logical.
EA8B DJNZ Reposition_CameraFollow_ShiftX Decrease the loop counter in B and jump to Reposition_CameraFollow_ShiftX if more iterations remain.
EA8D LD C,A Keep the fill attribute in C.
Pick a random X band that differs from the previous one.
Reposition_CameraFollow_WriteX EA8E LD A,$05 Load A with 05.
EA90 CALL PseudoRandom Call PseudoRandom to pick a pseudo-random value.
EA93 INC A Step the fill-row counter on by one.
EA94 CP C Does A match C? If so, jump to Reposition_CameraFollow_WriteX.
EA95 JR Z,Reposition_CameraFollow_WriteX
EA97 PUSH AF Stash AF on the stack.
EA98 LD B,$05 Load B with 05.
Scale the band into a world X and add a random offset for the follow entity.
Reposition_CameraFollow_RandomY EA9A ADD A,A Double A to form a word index into the table.
EA9B DJNZ Reposition_CameraFollow_RandomY Decrease the loop counter in B and jump to Reposition_CameraFollow_RandomY if more iterations remain.
EA9D LD B,A Keep a copy of A in B.
EA9E LD A,$14 Load A with 14.
EAA0 CALL PseudoRandom Call PseudoRandom to pick a pseudo-random value.
EAA3 ADD A,$02 A+=02.
EAA5 ADD A,B A+=B.
EAA6 LD (IX+$07),A Set the current entity's x-coordinate.
EAA9 ADD A,$05 A+=05.
EAAB LD (IX+$08),A Set the current entity's x-extent.
EAAE POP AF Restore AF from the stack.
EAAF CP $03 Is A equal to 03? If so, jump to Reposition_CameraFollow_WriteScript.
EAB1 JR Z,Reposition_CameraFollow_WriteScript
EAB3 LD A,$03 Load A with 03.
EAB5 CALL PseudoRandom Call PseudoRandom to pick a pseudo-random value.
EAB8 INC A Step the fill-row counter on by two.
Write the follow entity's room, Y, extents, and facing after the random place.
Reposition_CameraFollow_WriteScript EAB9 INC A
EABA LD (IX+$04),A Set the current entity's room index.
EABD ADD A,$1D A+=1D.
EABF LD (IX+$05),A Set the current entity's y-coordinate.
EAC2 ADD A,$06 A+=06.
EAC4 LD (IX+$06),A Set the current entity's y-extent.
EAC7 LD (IX+$09),$00 Write 00 to the current entity's direction / state.
EACB SET 0,(IX+$03) Set bit 00 of the current entity's flags byte 3.
EACF LD BC,$BBBD Load BC with BBBD.
EAD2 BIT 4,(IX+$03) Is bit 04 of flags byte 3 (IX+03) set? If so, jump to Reposition_CameraFollow_PickScript.
EAD6 JR NZ,Reposition_CameraFollow_PickScript
EAD8 INC BC Advance the script address in BC by two bytes.
EAD9 INC BC
Store the chosen Berk script pointer at Pointer_BerkScriptPosition and return.
Reposition_CameraFollow_PickScript EADA LD ($72B1),BC Store BC in Pointer: Berk Script Position (Pointer_BerkScriptPosition).
EADE POP IX Restore IX from the stack.
EAE0 EXX Switch to the shadow registers.
EAE1 RET Return.
Prev: EA6D Up: Map Next: EAE2