Prev: D037 Up: Map Next: D389
D202: Follow Path
Used by the routine at MoveEntity.
Moves an entity that is following a path from the level data, which is the case when fields 24 and 25 are not both zero. Bits 0-2 of field 25 choose a three-byte step from a table. Bits 6-7 of field 24 can replace that step: 40 lowers the entity and can play the long buzz, 80 moves it back along y, and C0 moves it on along x. The three bytes of a looked-up step are added to x, y and z. A step above 08 finishes the path. The player can be scored and shown the filled cup, and a path position is then copied into the entity before the falling sweep plays.
Input
IX The entity
FollowPath D202 RES 7,(IX+$11) Clear the moving flag.
D206 RES 7,(IX+$1E) Clear the fast flag.
D20A CALL FindPathEntry Find the path entry.
D20D PUSH HL Remember the entry.
D20E LD A,(IX+$25) Read the low byte of the path.
D211 AND %00000111 Keep the step number in bits 0-2.
D213 JR NZ,FollowPath_Lookup Look the step up when a number is set.
D215 DEC HL Use the two bytes just before the entry.
D216 DEC HL
D217 JR FollowPath_Step Join the stored step.
FollowPath_Lookup D219 DEC A Turn the step number into a table offset.
D21A ADD A,A
D21B ADD A,A
D21C CALL AddToAddress Look the offset up.
D21F LD C,(HL) Read the x step, the y step and the z step.
D220 INC HL
D221 LD B,(HL)
D222 INC HL
D223 LD E,(HL)
FollowPath_Step D224 LD ($D376),HL Remember where the path continues.
D227 LD A,(IX+$24) Read the high byte of the path.
D22A AND %11000000 Keep the nudge in bits 6-7.
D22C JR Z,FollowPath_Z Use the looked-up step when there is no nudge.
D22E CP $40 Lower the entity when the nudge is 40.
D230 JR NZ,FollowPath_Nudge
D232 LD A,(IX+$25) Read the low byte of the path again.
D235 CP $40 Play the long buzz when that byte is 40 as well.
D237 CALL Z,PlayLongBuzz
D23A LD BC,$0000 Clear the x step and the y step.
D23D LD E,$FE Lower the entity by two.
D23F JR FollowPath_Z Add the step.
FollowPath_Nudge D241 LD B,$FE Move the entity back along y, and clear the other steps.
D243 LD C,$00
D245 LD E,C
D246 CP $80 Keep that nudge when the bits are 80.
D248 JR Z,FollowPath_Z
D24A LD C,$02 Move the entity on along x instead.
D24C LD B,E
FollowPath_Z D24D LD H,(IX+$08) Fetch the z coordinate.
D250 LD L,(IX+$09)
D253 LD D,$00 Sign-extend the z step.
D255 BIT 7,E
D257 JR Z,FollowPath_AddZ
D259 DEC D
FollowPath_AddZ D25A ADD HL,DE Add the z step to the z coordinate.
D25B LD (IX+$08),H
D25E LD (IX+$09),L
D261 LD E,C Sign-extend the x step.
D262 BIT 7,E
D264 LD D,$00
D266 JR Z,FollowPath_X
D268 DEC D
FollowPath_X D269 LD H,(IX+$02) Fetch the x coordinate.
D26C LD L,(IX+$03)
D26F ADD HL,DE Add the x step to the x coordinate.
D270 LD (IX+$02),H
D273 LD (IX+$03),L
D276 LD E,B Sign-extend the y step.
D277 BIT 7,E
D279 LD D,$00
D27B JR Z,FollowPath_Y
D27D DEC D
FollowPath_Y D27E LD H,(IX+$05) Fetch the y coordinate.
D281 LD L,(IX+$06)
D284 ADD HL,DE Add the y step to the y coordinate.
D285 LD (IX+$05),H
D288 LD (IX+$06),L
A step above 08 finishes the path. A step of exactly 08 or a step number that no longer matches the entry, reads the next path byte.
D28B POP HL Restore the path entry.
D28C LD A,(IX+$25) A step of 08 reads the next path byte.
D28F SUB $08
D291 JP Z,FollowPath_Next
D294 JR NC,FollowPath_Finish A larger step finishes the path.
D296 LD A,(IX+$25) Read field 25 again.
D299 AND %00000111 Use the step number.
D29B DEC HL Compare it with the byte before the entry.
D29C CP (HL)
D29D JP NZ,FollowPath_Next Read the next path byte when they differ.
D2A0 LD A,(IX+$24) Read field 24.
D2A3 AND %11000000 Use bits 6-7 of the path.
D2A5 JR Z,FollowPath_Reward Copy the path position when those bits are clear.
D2A7 LD A,(IX+$00) Only the player finishes the path here.
D2AA DEC A
D2AB JR NZ,FollowPath_Clear
D2AD LD HL,$0000 Set the player's vertical speed to 2200.
D2B0 LD ($B552),HL
D2B3 LD ($5D00),A Clear the jump counter.
D2B6 LD A,(IX+$10) Read the width byte.
D2B9 AND %11110000 Use the countdown nibble.
D2BB LD (IX+$10),A Clear the sprite width.
D2BE LD (IX+$1A),$00 Clear the fraction of the speed.
FollowPath_Clear D2C2 XOR A Clear field 24.
D2C3 LD (IX+$24),A
FollowPath_Finish D2C6 LD (IX+$25),A Clear field 25 and return.
D2C9 RET
The byte stored by FindPathEntry chooses the player's reward. Zero scores 0500. Any other byte, the first time, scores 60 and draws the cup.
FollowPath_Reward D2CA LD A,(IX+$00) Only the player is rewarded.
D2CD DEC A
D2CE JR NZ,FollowPath_1
D2D0 EXX Switch to the reward byte.
D2D1 LD A,$00 Score 0500 when the path byte is zero.
D2D3 AND A
D2D4 JR NZ,FollowPath_Cup
D2D6 LD BC,$0500 Add a score of 0500.
D2D9 CALL AddScore
D2DC JR FollowPath_0 Skip the cup.
FollowPath_Cup D2DE LD A,($DEFC) The cup is shown only once.
D2E1 AND A
D2E2 JR NZ,FollowPath_0
D2E4 LD A,($B55C) Read the player's animation counter.
D2E7 AND %11110000 Use the high nibble of the animation.
D2E9 OR %00000101 Set the low nibble to 05.
D2EB LD ($B55C),A Keep that animation.
D2EE LD A,$05 Set the control byte to 05.
D2F0 LD ($AB7D),A
D2F3 LD BC,$0060 Add a score of 60.
D2F6 CALL AddScore
D2F9 LD HL,$6808 Draw the filled cup.
D2FC LD DE,$6498
D2FF CALL DrawPicture
D302 LD A,$01 Remember that the cup has been shown.
D304 LD ($DEFC),A
FollowPath_0 D307 EXX Switch back.
FollowPath_1 D308 DEC HL Step back to the path's position.
D309 LD A,(IX+$24) Read field 24.
D30C AND %00111111 Use bits 0-5 of the path.
D30E OR (HL) Combine them with the path byte and keep them.
D30F LD B,A
D310 LD (IX+$24),A
D313 LD A,(IX+$25) Read field 25.
D316 AND %00000111 Use the step number.
D318 OR %00100000 Mark the step with bit 5.
D31A LD (IX+$25),A Keep the marked step.
D31D DEC HL Copy the path's coordinates into the entity.
D31E LD A,(HL)
D31F LD (IX+$09),A
D322 DEC HL
D323 LD A,(HL)
D324 LD (IX+$08),A
D327 DEC HL
D328 LD A,(HL)
D329 LD (IX+$06),A
D32C DEC HL
D32D LD A,(HL)
D32E LD (IX+$05),A
D331 DEC HL
D332 LD A,(HL)
D333 LD (IX+$03),A
D336 DEC HL
D337 LD A,(HL)
D338 LD (IX+$02),A
D33B LD A,B Bring the new path flags back.
D33C AND %11000000 Use bits 6-7 of those flags.
D33E CP $90 Place the entity on y unless the flags are C0.
D340 JR NC,FollowPath_PlaceX
D342 LD A,(IX+$06) Read the low byte of y.
D345 AND %11110000 Use the high nibble of y.
D347 OR %00001000 Force the low nibble to 08.
D349 LD (IX+$06),A Keep that y position.
D34C LD A,$10 Shift x by half of 10 less the x extent.
D34E SUB (IX+$0B)
D351 SRL A
D353 ADD A,(IX+$03)
D356 LD (IX+$03),A
D359 JR FollowPath_2 Join the falling sweep.
FollowPath_PlaceX D35B LD A,(IX+$03) Read the low byte of x.
D35E AND %11110000 Use the high nibble of x.
D360 OR %00001000 Force the low nibble to 08.
D362 LD (IX+$03),A Keep that x position.
D365 LD A,$10 Shift y by half of 10 less the y extent.
D367 SUB (IX+$0C)
D36A SRL A
D36C ADD A,(IX+$06)
D36F LD (IX+$06),A
FollowPath_2 D372 JP PlayFallingSweep Play the falling sweep.
FollowPath_Next D375 LD HL,$0000 Read the next byte of the path table.
D378 LD DE,$0005
D37B ADD HL,DE
D37C LD A,(HL) Use it as field 25.
D37D LD (IX+$25),A
D380 LD A,(IX+$24) Read field 24.
D383 AND %00111111 Use bits 0-5 of the path.
D385 LD (IX+$24),A Clear bits 6-7 of the path.
D388 RET Return.
Prev: D037 Up: Map Next: D389