Prev: 43201 Up: Map Next: 43339
43221: Handle Tumbleweed
Type 23: a tumbleweed rolling about next to the sheriff. It follows one of two routes, stepping through the route one byte at a time; the high nibble of each byte is the vertical speed and the low nibble the horizontal speed, both signed. Bits 6 and 7 of byte 5 mirror the route, and they change every time a route ends, so the tumbleweed wanders in a different way each time. It spins by flipping its sprite every frame, and it hurts the sheriff if they touch. It goes away when the sheriff is two cells away.
Disappear if the sheriff is more than two cells away.
HandleTumbleweed 43221 LD C,2 Set the distance to two cells.
43223 CALL CheckDistance Check how close the sheriff is.
43226 JP NC,HandleBody_Remove Remove the tumbleweed if the sheriff has moved away.
Fetch the next step of the route.
43229 LD A,(IX+10) Fetch the number of the route, zero or one.
43232 LD BC,43339 Point BC at TumbleweedRoutes.
43235 CALL GetTableEntry Point HL at the start of the route.
43238 LD A,(IX+11) Fetch the position in the route.
43241 INC (IX+11) Move on to the next step.
43244 CALL AddAToHL Point HL at the step.
43247 LD A,(HL) Fetch the step.
43248 CP 128 Jump to HandleTumbleweed_RouteEnd if this is the end of the route.
43250 JR Z,HandleTumbleweed_RouteEnd
Work out the vertical speed from the high nibble.
43252 SRA A Shift the high nibble into the bottom of the byte, keeping the sign.
43254 SRA A
43256 SRA A
43258 SRA A
43260 BIT 6,(IX+5) Jump to HandleTumbleweed_DoubleVertical unless the route is mirrored vertically.
43264 JR Z,HandleTumbleweed_DoubleVertical
43266 NEG Negate the speed to mirror the route.
HandleTumbleweed_DoubleVertical 43268 SLA A Double the speed.
43270 LD (41493),A Store it as the vertical speed.
Work out the horizontal speed from the low nibble.
43273 LD A,(HL) Fetch the step again.
43274 LD C,A Keep the tumbleweed step in C.
43275 AND %00001111 Keep the low nibble.
43277 BIT 3,C Jump to HandleTumbleweed_TestHorizontal unless the nibble is negative.
43279 JR Z,HandleTumbleweed_TestHorizontal
43281 OR %11110000 Extend the sign of the nibble into the top half.
HandleTumbleweed_TestHorizontal 43283 BIT 7,(IX+5) Jump to HandleTumbleweed_DoubleHorizontal unless the route is mirrored horizontally.
43287 JR Z,HandleTumbleweed_DoubleHorizontal
43289 NEG Negate the speed to mirror the route.
HandleTumbleweed_DoubleHorizontal 43291 SLA A Double the speed.
43293 LD (41492),A Store it as the horizontal speed.
Move the tumbleweed.
43296 CALL CheckWallsEachWay Set the direction the tumbleweed is facing from its speed.
43299 CALL MoveObject Move the tumbleweed.
43302 LD A,(IX+7) Fetch the flags of the object.
43305 XOR %01000000 Flip the sprite horizontally.
43307 LD (IX+7),A Store the flags.
43310 CALL CheckSheriffTouch Check whether the tumbleweed is touching the sheriff.
43313 JP C,KillSheriff Hurt the sheriff if it is.
43316 RET Return.
The route has ended, so choose the next one.
HandleTumbleweed_RouteEnd 43317 LD A,(41496) Fetch a random number.
43320 AND %00000001 Keep bit 0.
43322 LD (IX+10),A Choose the route with it.
43325 LD (IX+11),0 Write 0 to byte 11 to go back to the first step.
43329 LD A,(IX+5) Fetch the mirror flags.
43332 ADD A,64 Add 64 to change how the route is mirrored.
43334 LD (IX+5),A Store the flags.
43337 JR HandleTumbleweed Start again with the new route.
Prev: 43201 Up: Map Next: 43339