Prev: B810 Up: Map Next: B85B
B82A: Update Direction
Used by the routines at HandleOutlaw and HandleBystander.
Makes a figure choose a new direction every so often. The bottom six bits of byte 06 count down the frames until the next change, and bits 6 and 7 are the direction. The direction is turned a quarter to the left or the right, and the counter is set to a new random number. A figure which has bumped into a wall (bit 0 of the flags) changes direction straight away, and a figure with bit 5 of the flags set never changes direction on its own.
Input
IX The address of the object
Change direction at once if the figure has hit a wall.
UpdateDirection B82A BIT 0,(IX+$07) Jump to UpdateDirection_Random if the figure has bumped into a wall.
B82E JR NZ,UpdateDirection_Random
B830 DEC (IX+$06) Count down the counter.
B833 LD A,(IX+$06) Fetch the counter.
B836 AND %00011111 Keep the bottom five bits.
B838 RET NZ Return unless the counter is at a multiple of thirty two.
B839 BIT 5,(IX+$07) Jump to UpdateDirection_Finish to return if the figure keeps its direction.
B83D JR NZ,UpdateDirection_Finish
Turn left or right and set a new counter.
UpdateDirection_Random B83F LD A,($A218) Fetch a random number.
B842 CP $80 Compare it with 80.
B844 LD A,(IX+$06) Fetch the direction and counter.
B847 JR NC,UpdateDirection_TurnLeft Jump to UpdateDirection_TurnLeft to turn left if the random number is 80 or more.
B849 ADD A,$40 Turn right.
UpdateDirection_Timer B84B LD C,A Keep the new direction in C.
B84C LD A,($A219) Fetch another random number.
B84F AND %00111111 Keep the bottom six bits.
B851 OR C Combine it with the direction.
B852 LD (IX+$06),A Store the new direction.
B855 RET Return.
The random number was 80 or more, so turn left.
UpdateDirection_TurnLeft B856 SUB $40 Turn left.
B858 JR UpdateDirection_Timer Go back to store the direction and counter.
UpdateDirection_Finish B85A RET Return.
View the equivalent code in;
Prev: B810 Up: Map Next: B85B