Prev: 61919 Up: Map Next: 62031
61939: Update Camera Follow
Used by the routine at GameStart.
Adjust the camera window at Pointer_CameraRoomOrigin to follow the target entity.
If the camera-follow delay is non-zero, tick it down; otherwise scroll the window toward the target.
Update_CameraFollow 61939 LD A,(29450) Load A with the camera-follow delay (CameraFollowDelay).
61942 OR A Is the camera-follow delay (CameraFollowDelay) zero? If so, jump to Update_CameraFollow_Active.
61943 JR Z,Update_CameraFollow_Active
61945 DEC A Decrease A by one.
61946 LD (29450),A Set the camera-follow delay (CameraFollowDelay).
61949 RET Return.
Camera delay expired: point at the follow entity (StateData_Berk) and track it against Pointer_CameraRoomOrigin.
Update_CameraFollow_Active 61950 LD IX,37019 Point IX at the camera-follow entity (StateData_Berk).
61954 LD DE,(29435) Load DE with the camera room-origin pointer (Pointer_CameraRoomOrigin).
61958 LD B,32 Load B with loop count 32.
Probe whether the follow entity sits inside the camera X window.
Update_CameraFollow_ProbeX 61960 LD A,(IX+7) Load A with the current entity's x-coordinate.
61963 ADD A,2 A+=2.
61965 CP E Is A less than E? If so, jump to Update_CameraFollow_ScrollLeft.
61966 JR C,Update_CameraFollow_ScrollLeft
61968 LD C,A Keep A in C for the next calculation.
61969 LD A,D Copy D into A for later use.
61970 CP C Is A less than C? If so, jump to Update_CameraFollow_ScrollRight.
61971 JR C,Update_CameraFollow_ScrollRight
61973 RET Return.
Scroll the camera origin right by 32 until the follow entity is centred.
Update_CameraFollow_ScrollRight 61974 LD A,E Copy the saved low byte from E into A.
61975 CP 160 Is A equal to 160? If so, jump to Update_CameraFollow_WrapLeft.
61977 JR Z,Update_CameraFollow_WrapLeft
61979 ADD A,B A+=B.
61980 LD E,A Copy A into E as a saved coordinate / value.
61981 LD D,A Copy A into D as a saved coordinate / value.
61982 ADD A,B A+=B.
61983 LD D,A Copy A into D as a saved coordinate / value.
61984 LD (29435),DE Store DE in Pointer: Camera Room Origin (Pointer_CameraRoomOrigin).
61988 JR Update_CameraFollow_ProbeX Jump to Update_CameraFollow_ProbeX to continue the loop.
Wrap the follow entity left by 160 when the camera hits the right edge.
Update_CameraFollow_WrapLeft 61990 LD A,(IX+7) Load A with the current entity's x-coordinate.
61993 SUB 160 A-=160.
61995 LD (IX+7),A Set the current entity's x-coordinate.
61998 JR Update_CameraFollow_AdjustXExtent Jump to Update_CameraFollow_AdjustXExtent to refresh the follow entity's x-extent.
Scroll the camera origin left by 32 until the follow entity is centred.
Update_CameraFollow_ScrollLeft 62000 LD A,E Copy the saved low byte from E into A.
62001 CP 32 Is A equal to 32? If so, jump to Update_CameraFollow_WrapRight.
62003 JR Z,Update_CameraFollow_WrapRight
62005 SUB B Subtract B from A.
62006 LD E,A Copy A into E as a saved coordinate / value.
62007 LD A,D Copy D into A for later use.
62008 SUB B Subtract B from A.
62009 LD D,A Copy A into D as a saved coordinate / value.
62010 LD (29435),DE Store DE in Pointer: Camera Room Origin (Pointer_CameraRoomOrigin).
62014 JR Update_CameraFollow_ProbeX Jump to Update_CameraFollow_ProbeX to continue the loop.
Wrap the follow entity right by 160 when the camera hits the left edge.
Update_CameraFollow_WrapRight 62016 LD A,(IX+7) Load A with the current entity's x-coordinate.
62019 ADD A,160 A+=160.
62021 LD (IX+7),A Set the current entity's x-coordinate.
Refresh the follow entity's X-extent after a wrap and keep probing.
Update_CameraFollow_AdjustXExtent 62024 ADD A,5 A+=5.
62026 LD (IX+8),A Set the current entity's x-extent.
62029 JR Update_CameraFollow_ProbeX Jump to Update_CameraFollow_ProbeX to continue the loop.
Prev: 61919 Up: Map Next: 62031