← C897 Bias a replacement heading for the wheel Map C91C → Steer an object toward a target object
C8C2: Pick a new wander heading on a timer
Drives the wander of an inhabitant or the ball gem: after a random 33–64 frames it picks a new heading.
Input
A heading restriction: 0 for any heading, 1 for diagonal only, 2 for straight only, 3 for right or left only, 4 or more for up or down only
IY the object's logic record (obj2_record)
The restriction in A limits the new heading. It allows any of the eight headings, only the four diagonals or only the four straight ones. It can also allow only right or left, or only up or down.
pick_wander_heading C8C2 LD B,A Save the heading restriction in B.
C8C3 LD A,(IY+$07) Wander timer not yet expired? Hold the heading.
C8C6 OR A
C8C7 JR Z,wander_new_heading
C8C9 DEC (IY+$07) Count the timer down and return.
C8CC RET
wander_new_heading C8CD CALL next_random Timer expired: reload it with a random wander time.
C8D0 AND $1F
C8D2 ADD A,$20
C8D4 LD (IY+$07),A
C8D7 LD A,B Any random heading
C8D8 OR A
C8D9 JR NZ,wander_odd
C8DB CALL next_random
C8DE AND $07
C8E0 LD (IY+$00),A
C8E3 RET
wander_odd C8E4 CP $01 A random diagonal heading
C8E6 JR NZ,wander_even
C8E8 CALL next_random
C8EB AND $07
C8ED OR $01
C8EF LD (IY+$00),A
C8F2 RET
wander_even C8F3 CP $02 A random straight heading
C8F5 JR NZ,wander_horizontal
C8F7 CALL next_random
C8FA AND $06
C8FC LD (IY+$00),A
C8FF RET
wander_horizontal C900 CP $03 A horizontal heading, rightward or leftward
C902 JR NZ,wander_vertical
C904 CALL next_random
C907 AND $01
C909 ADD A,A
C90A ADD A,A
C90B ADD A,$02
C90D LD (IY+$00),A
C910 RET
wander_vertical C911 CALL next_random A vertical heading, up or down
C914 AND $01
C916 ADD A,A
C917 ADD A,A
C918 LD (IY+$00),A
C91B RET
← C897 Bias a replacement heading for the wheel Map C91C → Steer an object toward a target object
Fork me on GitHub