Prev: 61143 Up: Map Next: 61700
61441: Handler: Pirates
Used by the routine at InitialiseGame.
See No Pirates.
Handler_Pirates 61441 LD A,(62260) Return if *LiftsPiratesFrameSkip is a skipped frame.
61444 CP 0
61446 RET Z
61447 LD HL,36392 Write 36392 to *CHARS.
61450 LD (23606),HL
61453 LD IX,(23518) Point IX at *ReferencePirate.
Handler_Pirates_Loop 61457 LD A,(IX+0) Return if this pirate entry is the terminator (255).
61460 CP 255
61462 RET Z
61463 LD A,16 Set INK from the pirate attribute.
61465 RST 16
61466 LD A,(IX+9)
61469 RST 16
Advance the pirate walk frame.
61470 LD A,(IX+6) Fetch the current pirate sprite ID.
61473 ADD A,6 Add one walk frame.
61475 LD (IX+6),A Write it back to the pirate sprite ID.
Wrap the walk cycle at each facing's last frame.
61478 CP 74 Jump to Handler_Pirates_CheckSpriteFrames if the right-facing frames have not wrapped.
61480 JR NZ,Handler_Pirates_CheckSpriteFrames
61482 LD (IX+6),32 Reset to the first right-facing pirate frame.
Handler_Pirates_CheckSpriteFrames 61486 CP 128 Jump to Handler_Pirates_SkipSpriteFrames if the left-facing frames have not wrapped.
61488 JR NZ,Handler_Pirates_SkipSpriteFrames
61490 LD (IX+6),80 Reset to the first left-facing pirate frame.
Handler_Pirates_SkipSpriteFrames 61494 CALL ApplyMovementDeltas Apply the pirate's movement deltas.
61497 LD A,C Jump to Handler_Pirate_TurnRight if the pirate walked off the right.
61498 CP 34
61500 JP Z,Handler_Pirate_TurnRight
61503 CP 3 Jump to Handler_Pirate_TurnLeft if the pirate walked off the left.
61505 JP Z,Handler_Pirate_TurnLeft
61508 PUSH DE Stash the new position and offsets on the stack.
61509 PUSH BC
61510 LD A,(IX+4) Jump to Handler_Pirates_SeekDoorLeft if the pirate is not moving right.
61513 CP 255
61515 JR NZ,Handler_Pirates_SeekDoorLeft
61517 DEC C Adjust the test column when moving right.
61518 DEC C
Handler_Pirates_SeekDoorLeft 61519 CALL FindKeyAtPosition Look for a key or locked door in this column.
61522 POP BC Restore the new position and offsets from the stack.
61523 POP DE
61524 CP 255 Jump to Pirate_TurnController if a key or locked door blocks this column.
61526 JP NZ,Pirate_TurnController
61529 PUSH BC Stash the new position and offsets on the stack.
61530 PUSH DE
61531 DEC B Move three rows up to the pirate's feet.
61532 DEC B
61533 DEC B
61534 LD A,(IX+4) Jump to Handler_Pirates_ConvertFootLeft if the pirate is not moving right.
61537 CP 255
61539 JR NZ,Handler_Pirates_ConvertFootLeft
61541 DEC C Adjust the test column when moving right.
61542 DEC C
Handler_Pirates_ConvertFootLeft 61543 CALL ConvertCoordinateToBufferOffset Convert that foot position into a room-buffer offset.
61546 LD HL,41412 HL=BufferRoom.
61549 LD DE,(62256) Add the offset from *BufferRoomPointer.
61553 ADD HL,DE HL+=DE.
61554 POP DE Restore the new position and offsets from the stack.
61555 POP BC
61556 LD A,(HL) Jump to Pirate_TurnController if that buffer tile is empty space.
61557 CP 33
61559 JP C,Pirate_TurnController
61562 LD (IX+0),C Write the new horizontal co-ordinate back to the pirate.
61565 LD (IX+1),B Write the new vertical co-ordinate back to the pirate.
61568 LD (IX+2),E Write the new horizontal offset back to the pirate.
61571 LD (IX+3),D Write the new vertical offset back to the pirate.
61574 CALL EraseSpriteTrail Erase the pirate's previous sprite.
Handler_Pirates_Print 61577 CALL PrintShiftedSprite Print the pirate.
61580 LD A,(IX+0) Copy the horizontal co-ordinate to the previous-horizontal slot.
61583 LD (IX+13),A
61586 LD A,(IX+1) Copy the vertical co-ordinate to the previous-vertical slot.
61589 LD (IX+14),A
61592 LD A,(IX+2) Copy the horizontal offset to the previous-offset slot.
61595 LD (IX+11),A
61598 LD A,(IX+3) Copy the vertical offset to the previous-vertical-offset slot.
61601 LD (IX+15),A
Test whether the pirate overlaps the player.
61604 LD C,(IX+0) C=the pirate horizontal co-ordinate.
61607 DEC C Decrease C by one.
61608 SLA C Convert it to a pixel column.
61610 SLA C
61612 LD A,(IX+2) Add the pirate's horizontal offset.
61615 ADD A,C A+=C.
61616 LD C,A C=the pirate's pixel column.
61617 LD A,(62003) B=*PlayerHorizontalPosition.
61620 LD B,A
61621 LD A,(62001) A=*TablePlayerAttributes.
61624 DEC A Decrease A by one.
61625 SLA A Convert the player column to a pixel position.
61627 SLA A
61629 ADD A,B Add the player's horizontal offset.
61630 ADD A,7 Add the player's pixel width.
61632 SUB C Subtract the pirate's pixel column.
61633 CP 16 Jump to Handler_Pirate_Next if the player is outside the pirate's horizontal span.
61635 JR NC,Handler_Pirate_Next
61637 LD B,(IX+1) B=the pirate vertical co-ordinate.
61640 LD A,(62002) A=*PlayerVerticalCoordinate.
61643 ADD A,2 Add the player's height.
61645 SUB B Subtract the pirate vertical co-ordinate.
61646 CP 6 Jump to Handler_Pirate_Next if the player is outside the pirate's vertical span.
61648 JP NC,Handler_Pirate_Next
61651 LD A,2 Queue the "caught by pirate" sound at SoundFlag_General.
61653 LD (65534),A
61656 JP LoseLife Jump to LoseLife to lose a life.
Move onto the next pirate.
Handler_Pirate_Next 61659 LD DE,16 Move IX on to the next sixteen-byte pirate entry.
61662 ADD IX,DE
61664 JP Handler_Pirates_Loop Jump to Handler_Pirates_Loop.
Face and move left, then reprint.
Handler_Pirate_TurnLeft 61667 LD (IX+4),1 Set horizontal movement to the left.
61671 LD (IX+6),80 Write the first left-facing pirate frame.
61675 JP Handler_Pirates_Print Jump to Handler_Pirates_Print.
Face and move right, then reprint.
Handler_Pirate_TurnRight 61678 LD (IX+4),255 Set horizontal movement to the right.
61682 LD (IX+6),32 Write the first right-facing pirate frame.
61686 JP Handler_Pirates_Print Jump to Handler_Pirates_Print.
Turn the pirate around after a blocked step.
Pirate_TurnController 61689 LD A,(IX+4) Jump to Handler_Pirate_TurnLeft if the pirate is moving right.
61692 CP 255
61694 JP Z,Handler_Pirate_TurnLeft
61697 JP Handler_Pirate_TurnRight Jump to Handler_Pirate_TurnRight.
Prev: 61143 Up: Map Next: 61700