Prev: AFDB Up: Map Next: B01D
AFDC: Script Routine: (1B) Animate trap door / update Berk interaction
Animate the trap door for Drutt's current action and refresh Berk's interaction with it.
ScriptRoutine_AnimateTrapDoorBerk AFDC LD A,($72BB) Load A with Drutt's animation counter (DruttAnimationCounter).
AFDF OR A Is Drutt's animation counter (DruttAnimationCounter) zero? If not, jump to AdvanceScriptInstruction to run the next script instruction.
AFE0 JP NZ,AdvanceScriptInstruction
AFE3 LD A,$0C Load A with sound index 0C.
AFE5 CALL Queue_Sound Call Queue_Sound to queue a sound effect.
AFE8 LD IY,$908D Point IY at complex entity state StateData_Complex_30.
AFEC DEC (IY+$05) Move the referenced entity one character up.
AFEF DEC (IY+$06)
AFF2 LD A,(IY+$06) Load A with the referenced entity's y-extent.
AFF5 CP $16 Is the y-extent still below the trap door open threshold 16? If not, jump to AnimateTrapDoor_ToggleFrame.
AFF7 JR NZ,AnimateTrapDoor_ToggleFrame
AFF9 CALL Reset_Trap_Door_Animation_State Call Reset_Trap_Door_Animation_State to reset trap door animation state.
AFFC XOR A Clear the trap door flags.
AFFD LD ($72BA),A Set the trap door flags (TrapDoorFlags).
B000 JR AnimateTrapDoor_SetLayoutB Jump to AnimateTrapDoor_SetLayoutB to handle the trap door.
Toggle the lever animation phase and choose open facing left (GraphicLayout_LeverOpenLeft) or closed facing left (GraphicLayout_LeverClosedLeft).
AnimateTrapDoor_ToggleFrame B002 LD A,($72BA) Load A with the trap door flags (TrapDoorFlags).
B005 XOR %00000001 Toggle the trap door animation phase bit in A.
B007 LD ($72BA),A Set the trap door flags (TrapDoorFlags).
B00A SRL A Shift the trap door animation phase bit into the success marker.
B00C JR NC,AnimateTrapDoor_SetLayoutB Jump to AnimateTrapDoor_SetLayoutB to handle the trap door if the result did not underflow.
B00E LD BC,$A818 Point BC at the lever open, facing left (GraphicLayout_LeverOpenLeft).
B011 JR AnimateTrapDoor_WriteLayout Jump to AnimateTrapDoor_WriteLayout to handle the trap door.
Use the lever closed, facing left at GraphicLayout_LeverClosedLeft.
AnimateTrapDoor_SetLayoutB B013 LD BC,$A827 Point BC at the lever closed, facing left (GraphicLayout_LeverClosedLeft).
Install the chosen lever layout into Pointer_AnimatingSceneryLayout and continue the script.
AnimateTrapDoor_WriteLayout B016 LD ($91AF),BC Store BC in the animating scenery layout pointer (Pointer_AnimatingSceneryLayout).
B01A JP AdvanceScriptInstruction Jump to AdvanceScriptInstruction to run the next script instruction.
Prev: AFDB Up: Map Next: B01D