Prev: 41208 Up: Map Next: 41555
41386: Handler: Pickup
Animate a collectible, attach it to the rover when RoverCargoFlag is clear, and teleport Jetman from Handler_Pickup_Teleport when SPACE is pressed beside it.
Input
IX Actor slot
Cycle the sprite ID and colour from GameTimer.
Handler_Pickup 41386 LD A,(24130) Fetch GameTimer.
41389 RRCA Rotate it right once.
41390 LD C,A Stash it in C.
41391 AND %00000011 Keep only bits 0-1.
Sprite IDs begin at 42 ("Teleporter: Frame 1").
41393 ADD A,42 Add 42 for the pickup frames.
41395 LD (IX+0),A Write it to the actor type.
41398 LD B,0 Clear B.
41400 LD HL,41747 HL=Pickup_Colours.
Pick the actor colour from the next two bits of the timer.
41403 LD A,C Copy the rotated timer into A.
41404 RRCA Rotate it right twice.
41405 RRCA
41406 AND %00000011 Keep only bits 0-1.
41408 LD C,A Copy the colour index into C.
41409 ADD HL,BC Point HL at that colour.
41410 LD A,(HL) Fetch the colour.
41411 LD (IX+7),A Write it to the actor colour.
41414 BIT 3,(IX+8) Jump to Handler_PickupAction if bit 3 of the actor flags is set.
41418 JP NZ,Handler_PickupAction
Drop the object to the ground while bit 7 of the actor flags is set.
41421 BIT 7,(IX+8) Jump to Handler_Pickup_Draw if bit 7 of the actor flags is reset.
41425 JR Z,Handler_Pickup_Draw
41427 CALL ClampObjectToGround Call ClampObjectToGround.
41430 JR C,Handler_Pickup_TestCarrying Jump to Handler_Pickup_TestCarrying if the object has not landed.
41432 LD A,(IX+8) Fetch the actor flags.
41435 AND %00000010 Keep only bit 1.
41437 LD (IX+8),A Write it back.
Attach the pickup to the rover if the rover is not carrying and the pickup is in range.
Handler_Pickup_TestCarrying 41440 LD A,(24227) Fetch RoverCargoFlag.
41443 AND A Jump to Handler_Pickup_Draw if the rover is already carrying.
41444 JR NZ,Handler_Pickup_Draw
41446 CALL CompareActorDistance Call CompareActorDistance.
41449 JR NC,Handler_Pickup_Draw Jump to Handler_Pickup_Draw if the object is out of range.
41451 LD A,1 Write 1 to RoverCargoFlag.
41453 LD (24227),A
41456 SET 3,(IX+8) Set bit 3 of the actor flags.
41460 RES 2,(IX+8) Reset bit 2 of the actor flags.
Handler_Pickup_Draw 41464 CALL DrawCurrentActor_Draw Call DrawCurrentActor_Draw.
Type 17 and above means Jetman is not on foot.
41467 LD A,(24696) Fetch Jetman_Slot.
41470 CP 17 Return if Jetman's type is at least 17.
41472 RET NC
41473 BIT 2,(IX+8) Jump to Handler_PickupAction_SnapToJetman if bit 2 of the actor flags is set.
41477 JP NZ,Handler_PickupAction_SnapToJetman
41480 CALL TestActionKey Call TestActionKey.
41483 JP NZ,Handler_PickupAction_Collect Jump to Handler_PickupAction_Collect if the action key is pressed.
41486 RES 1,(IX+8) Reset bit 1 of the actor flags.
Teleport Jetman when SPACE is pressed beside this pickup.
Handler_Pickup_Teleport 41490 LD A,(24696) Fetch Jetman_Slot.
41493 CP 17 Return if Jetman's type is at least 17.
41495 RET NC
Return unless Jetman is in range and SPACE is pressed.
41496 CALL TestJetmanAction_ComparePosition Call TestJetmanAction_ComparePosition.
41499 RET NC Return if the object is out of range.
41500 CALL TestSpaceKey Call TestSpaceKey.
41503 RET Z Return if SPACE is not pressed.
Find the object to teleport to: the position at World_Slot_1_Position, unless this is the object at World_Slot_1.
41504 PUSH IX Copy the slot pointer into HL (using the stack).
41506 POP HL
41507 LD BC,24744 Set BC to the slot-1 address World_Slot_1.
41510 AND A Clear the carry flag.
41511 SBC HL,BC Subtract the slot-1 address.
41513 JP Z,ResumePickup Jump to ResumePickup if this is slot 1.
41516 LD A,(24748) Fetch World_Slot_1_Y.
41519 LD HL,(24746) Fetch World_Slot_1_Position.
Move Jetman onto the destination object's position and start the teleport.
Handler_Pickup_Attach 41522 LD DE,(24700) Fetch Jetman_Y into DE.
41526 LD (24700),A Write the destination Y over Jetman_Y.
41529 LD A,L Fetch the low byte of the destination world X.
41530 AND %11111000 Keep only bits 3-7.
41532 LD L,A Write it back.
41533 LD (24698),HL Write the pair to Jetman_Position.
Record a Y near Jetman's old position for the debris burst.
41536 LD A,E Fetch Jetman's old Y.
41537 SUB 12 Subtract 12.
41539 LD (24170),A Write it to Debris_Y.
41542 LD A,(24696) Fetch Jetman_Slot.
The actor type is a 1-based sprite ID. Decrease it to work on the 0-based index, reset bit 3 to switch from the walking frames to the flying frames, then write the 1-based ID back.
41545 DEC A Decrease it to a 0-based sprite index.
41546 AND %11110111 Reset bit 3.
41548 INC A Increase it by one.
41549 LD (24696),A Write it back.
41552 JP StartTeleport Jump to StartTeleport.
Prev: 41208 Up: Map Next: 41555