Prev: 25399 Up: Map Next: 25886
25562: Move a guard
Used by the routine at 25399.
25562 LD A,(28094) Pick up the guard's return delay counter.
25565 AND A Has this guard been thrown out of the park?
25566 RET NZ Return if so.
25567 LD HL,(31851) Pick up Horace's current location.
25570 RR H Now H=0, 1 or 2, indicating which third of the screen the top row of Horace's sprite is in.
25572 RR H
25574 RR H
25576 LD B,5 Move bits 5-7 of L down to bits 0-2, and bits 0-2 of H into bits 3-5 of L.
25578 RR H
25580 RR L
25582 DJNZ 25578
25584 LD A,L Now A=Horace's screen y-coordinate (0-22).
25585 AND 31
25587 LD HL,(31851) Pick up Horace's current location.
25590 LD H,A H=Horace's screen y-coordinate (0-22).
25591 LD A,L Now L=Horace's screen x-coordinate (0-30).
25592 AND 31
25594 LD L,A
25595 LD (31866),HL Save Horace's screen x- and y-coordinates temporarily.
25598 LD HL,(28088) Compute the guard's screen x- and y-coordinates.
25601 RR H
25603 RR H
25605 RR H
25607 LD B,5
25609 RR H
25611 RR L
25613 DJNZ 25609
25615 LD A,L
25616 AND 31
25618 LD HL,(28088)
25621 LD H,A
25622 LD A,L
25623 AND 31
25625 LD L,A
25626 LD (28080),HL Save the guard's screen x- and y-coordinates temporarily.
25629 LD B,4 Initialise B (the direction indicator) for the loop that follows.
Four passes are made through the following loop, one for each direction the guard might go: left, down, right, or up.
25631 DEC B B=3 (left), 2 (down), 1 (right) or 0 (up).
25632 LD HL,(28088) Pick up the guard's current location.
25635 LD C,0 Initialise C to 0; this is the direction probability parameter.
25637 PUSH BC Save the direction indicator briefly.
25638 LD A,B Copy the direction indicator to A.
25639 CALL 27842 Check the tiles next to the guard in that direction.
25642 POP BC Restore the direction indicator to B.
25643 CP 2 Is there a wall or the maze exit or entrance in that direction?
25645 JP NC,25795 Jump if so with C=0: that direction is blocked.
25648 LD C,25 C=25; this value determines the base probability that the guard will turn 90 degrees in the direction indicated by B when his path is blocked.
25650 LD A,(28090) Pick up the guard's animation frame.
25653 CP B Is it equal to the current value of the direction indicator?
25654 JR NZ,25662 Jump if not.
25656 LD A,40 C=65; this value ensures that the guard will keep moving in the same direction if he can.
25658 ADD A,C
25659 LD C,A
25660 JR 25691
25662 ADD A,2 Add 2 to the guard's current animation frame; this has the effect of toggling his direction between up/down and left/right.
25664 AND 3
25666 CP B Is it equal to the current value of the direction indicator now?
25667 JR NZ,25675 Jump if not.
25669 LD A,246 C=15; this value determines the probability that the guard will turn round 180 degrees when his path is blocked.
25671 ADD A,C
25672 LD C,A
25673 JR 25691
25675 LD HL,(23672) Increment the two least significant bytes of the system variable FRAMES, and copy the value to HL.
25678 INC HL
25679 LD (23672),HL
25682 LD A,H Use this value to generate a pseudo-random number between 0 and 31.
25683 AND 15
25685 LD H,A
25686 LD A,(HL)
25687 AND 31
25689 ADD A,C Add this to C, giving a number between 25 and 56; the higher this value, the more likely the guard will turn 90 degrees in the direction indicated by B when his path is blocked.
25690 LD C,A
25691 LD A,B Copy the direction indicator to A.
25692 CP 3 Set the zero flag if we're considering 'left' at the moment.
25694 LD A,(31844) Pick up the value of the redundant variable at 31844.
25697 JR NZ,25703 Jump if we're considering 'right', 'up' or 'down' at the moment.
25699 DEC A Decrement the redundant variable at 31844.
25700 LD (31844),A
25703 AND A This instruction is redundant.
25704 LD A,B Copy the direction indicator to A.
25705 CP 0 Are we considering 'up' at the moment?
25707 JR NZ,25715 Jump if not.
25709 LD A,(31842) Reset the redundant variable at 31844 to the value of the game speed parameter.
25712 LD (31844),A
25715 LD A,B Copy the direction indicator to A.
25716 CP 0 Are we considering 'up' at the moment?
25718 JR NZ,25732 Jump if not.
25720 LD HL,(28080) Pick up the guard's screen x- and y-coordinates.
25723 LD A,H A=guard's screen y-coordinate.
25724 LD HL,(31866) Pick up Horace's screen x- and y-coordinates.
25727 SUB H Is Horace's y-coordinate greater than the guard's?
25728 JR C,25795 Jump if so.
25730 JR 25774 Otherwise jump to increase the probability that the guard will move up (towards Horace).
25732 CP 1 Are we considering 'right' at the moment?
25734 JR NZ,25748 Jump if not.
25736 LD HL,(31866) Pick up Horace's screen x- and y-coordinates.
25739 LD A,L A=Horace's screen x-coordinate.
25740 LD HL,(28080) Pick up the guard's screen x- and y-coordinates.
25743 SUB L Is the guard's x-coordinate greater than Horace's?
25744 JR C,25795 Jump if so.
25746 JR 25774 Otherwise jump to increase the probability that the guard will move right (towards Horace).
25748 CP 2 Are we considering 'down' at the moment?
25750 JR NZ,25764 Jump if not.
25752 LD HL,(31866) Pick up Horace's screen x- and y-coordinates.
25755 LD A,H A=Horace's screen y-coordinate.
25756 LD HL,(28080) Pick up the guard's screen x- and y-coordinates.
25759 SUB H Is the guard's y-coordinate greater than Horace's?
25760 JR C,25795 Jump if so.
25762 JR 25774 Otherwise jump to increase the probability that the guard will move down (towards Horace).
25764 LD HL,(28080) Pick up the guard's screen x- and y-coordinates.
25767 LD A,L A=guard's screen x-coordinate.
25768 LD HL,(31866) Pick up Horace's screen x- and y-coordinates.
25771 SUB L Is Horace's x-coordinate greater than the guard's?
25772 JR C,25795 Jump if so.
25774 AND A This instruction is redundant.
25775 ADD A,10 Add 10 to A; the higher the value A holds now, the more likely the guard will move in the direction indicated by B (towards Horace).
25777 PUSH AF Save this probability modifier briefly.
25778 PUSH HL Save HL (unnecessarily).
25779 LD HL,(28078) Pick up the guard panic timer.
25782 LD A,H Set the zero flag unless the guards are panicking.
25783 OR L
25784 POP HL Restore HL.
25785 JR Z,25792 Jump unless the guards are panicking.
25787 POP AF Restore the probability modifier to A.
25788 NEG Negate A, making it less likely that the guard will move in the direction indicated by B (towards Horace).
25790 JR 25793
25792 POP AF Restore the probability modifier to A.
25793 ADD A,C Now C holds the probability parameter for the direction indicated by B.
25794 LD C,A
25795 PUSH BC Save the direction indicator briefly.
25796 LD HL,28082 Point HL at one of the four slots at 28082.
25799 LD C,B
25800 LD B,0
25802 ADD HL,BC
25803 POP BC Restore the direction indicator to B.
25804 LD A,C Save the direction probability parameter in the appropriate slot.
25805 LD (HL),A
25806 INC B Have we considered every direction yet?
25807 DEC B
25808 JP NZ,25631 Jump back if not.
Having computed a direction probability parameter for each of the four slots at 28082, we now use those values to determine the guard's next animation frame (and therefore direction of travel).
25811 XOR A Compute in C the index of the slot that holds the largest number (0, 1, 2 or 3).
25812 LD HL,28086
25815 LD B,4
25817 DEC B
25818 DEC HL
25819 CP (HL)
25820 JR NC,25824
25822 LD A,(HL)
25823 LD C,B
25824 INC B
25825 DEC B
25826 JR NZ,25817
25828 LD A,C Update the guard's animation frame to this index value.
25829 LD (28090),A
25832 LD A,(28090) Pick up the guard's animation frame.
25835 LD HL,(28088) Pick up the guard's current location.
25838 CALL 27842 Check the tiles in front of the guard.
25841 CP 0 Is there anything in front of the guard?
25843 JR Z,25866 Jump if not.
25845 CP 1 Is the guard facing a tunnel entrance?
25847 JR NZ,25879 Jump if not. (This jump is never made.)
The guard is about to enter a tunnel.
25849 LD BC,(28623) Pick up the the tunnel offset.
25853 LD A,(28090) Pick up the guard's animation frame.
25856 AND A Is it 0 (going up)?
25857 JR Z,25863 Jump if so.
25859 SBC HL,BC Subtract the tunnel offset from the guard's current location.
25861 JR 25864
25863 ADD HL,BC Add the tunnel offset to the guard's current location.
25864 JR 25875
25866 LD HL,(28088) Pick up the guard's current location.
25869 LD A,(28090) Pick up the guard's animation frame.
25872 CALL 27927 Compute the guard's new location.
25875 LD (28092),HL Update the guard's location.
25878 RET
The guard has been left facing a wall or the maze entrance or exit (so he cannot move). This never happens, so the following code is never executed.
25879 LD HL,(28088) Pick up the guard's current location.
25882 LD (28092),HL Set the guard's new location.
25885 RET
Prev: 25399 Up: Map Next: 25886