Prev: B055 Up: Map Next: B0AD
B06B: The update routine for a creature that wanders at random (graphics 94 and 95)
The upper half of object template 17 (the lower half is LOWER_HALF's). It walks two units a turn in one of four directions, and when it is stopped, or has no step yet, it turns a quarter to the left or to the right, chosen by bit 0 of the random number, and sets off the new way on the next turn. It is deadly both ways (SPIKES).
The direction is kept in bit 0 of the graphic and bit 6 of the flags, the mirror bit (STEP_FROM_FACING has the four combinations), so turning also turns the picture. For the move the two halves are made one box (JOIN_HALVES); afterwards they are parted again (PART_HALVES).
Measured in the simulator in room $2F: two units a turn in V, then, stopped, a quarter turn and two units a turn in U, the lower half following it each turn.
Input
IX the upper half's record
WANDERER B06B CALL DRAW_AT_L12_D6 the drawing nudge
B06E CALL JOIN_HALVES the two halves as one box
B071 LD A,(IX+$09) no step yet: choose a direction
B074 OR (IX+$0A)
B077 JR Z,WANDERER_0
B079 CALL DEC_DZ_AND_UPDATE_UVZ move
B07C LD A,(IX+$0B) a thud whenever it has a step in Z (falling, or just landed)
B07F AND A
B080 CALL NZ,BEEP_BY_Z
B083 LD A,(IX+$0C) not stopped in U or V: done
B086 AND $03
B088 JR Z,WANDERER_2
WANDERER_0 B08A CALL THUD_SOUND a thud as it turns
B08D LD A,(RANDOM) bit 0 of the random number: which way to turn
B090 AND $01
B092 JR Z,WANDERER_3
B094 CALL TURN_QUARTER_BACK 1: a quarter turn the other way (TURN_QUARTER_BACK)
WANDERER_1 B097 CALL STEP_FROM_FACING set off in the direction it now faces, two units a turn
B09A SLA (IX+$09)
B09E SLA (IX+$0A)
WANDERER_2 B0A2 CALL PART_HALVES part the halves; deadly both ways, and redraw it
B0A5 JP DEADLY_AND_DRAW
WANDERER_3 B0A8 CALL TURN_QUARTER 0: a quarter turn one way (TURN_QUARTER)
B0AB JR WANDERER_1
Prev: B055 Up: Map Next: B0AD