Prev: D1F5 Up: Map Next: D251
D1FD: Run Wanderer
The handler of the object types 50 and 51, which are creatures that harm the player and wander about the room. A creature stays just above the floor, and walks along one axis at a time, at a speed of four. When it has no speed, because something has stopped it, it picks a new direction at random: along x if it was stopped along y, and along y if it was not. The lowest bit of its type and the flag for the sprite being mirrored are set to show which of the four ways it is going, to give the right picture.
Input
IX Object record
Move the creature and keep it just above the floor.
RunWanderer D1FD CALL SetSpriteOffset_Minus16_Minus8 Call SetSpriteOffset_Minus16_Minus8 to set the offsets of the sprite.
D200 CALL SetDeadlyFlags Call SetDeadlyFlags to make the creature harm the player.
D203 CALL ApplyGravityAndMove Call ApplyGravityAndMove to apply gravity to the creature and move it.
D206 LD A,(IX+$03) Jump to RunWanderer_Test if the creature is at least 81 up.
D209 CP $81
D20B JR NC,RunWanderer_Test
D20D LD (IX+$03),$81 Put the creature at a height of 81.
D211 LD (IX+$0B),$00 Set the speed along z to zero.
Pick a new direction when the creature is stopped.
RunWanderer_Test D215 LD A,(IX+$09) Jump to SetWipeAndDrawFlags to flag the creature as moved if it is moving.
D218 OR (IX+$0A)
D21B JP NZ,SetWipeAndDrawFlags
D21E LD A,R Fetch a random number from the refresh register.
D220 AND %00001000 Keep bit 3.
D222 SUB $04 Make it FC or 04.
D224 BIT 1,(IX+$0C) Jump to RunWanderer_AlongX if the creature was stopped along y.
D228 JR NZ,RunWanderer_AlongX
D22A LD (IX+$0A),A Set the speed along y.
D22D SET 0,(IX+$00) Set the bit of the type that goes with going forwards along y.
D231 RES 6,(IX+$07) Clear the flag for the sprite being mirrored.
D235 JR RunWanderer_Direction Jump to RunWanderer_Direction.
RunWanderer_AlongX D237 LD (IX+$09),A Set the speed along x.
D23A RES 0,(IX+$00) Clear the bit of the type that goes with going forwards along x.
D23E SET 6,(IX+$07) Set the flag for the sprite being mirrored.
RunWanderer_Direction D242 AND A Jump to SetWipeAndDrawFlags to flag the creature as moved when it is going forwards.
D243 JP P,SetWipeAndDrawFlags
D246 LD A,(IX+$00) Fetch the type of the creature.
D249 XOR %00000001 Turn the bit of the type around, as the creature is going backwards.
D24B LD (IX+$00),A Set the type.
D24E JP SetWipeAndDrawFlags Jump to SetWipeAndDrawFlags to flag the creature as moved.
Prev: D1F5 Up: Map Next: D251