Prev: A0F8 Up: Map Next: A253
A1AA: 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 A1AA LD A,($5E42) Fetch GameTimer.
A1AD RRCA Rotate it right once.
A1AE LD C,A Stash it in C.
A1AF AND %00000011 Keep only bits 0-1.
Sprite IDs begin at 2A ("Teleporter: Frame 1").
A1B1 ADD A,$2A Add 2A for the pickup frames.
A1B3 LD (IX+$00),A Write it to the actor type.
A1B6 LD B,$00 Clear B.
A1B8 LD HL,$A313 HL=Pickup_Colours.
Pick the actor colour from the next two bits of the timer.
A1BB LD A,C Copy the rotated timer into A.
A1BC RRCA Rotate it right twice.
A1BD RRCA
A1BE AND %00000011 Keep only bits 0-1.
A1C0 LD C,A Copy the colour index into C.
A1C1 ADD HL,BC Point HL at that colour.
A1C2 LD A,(HL) Fetch the colour.
A1C3 LD (IX+$07),A Write it to the actor colour.
A1C6 BIT 3,(IX+$08) Jump to Handler_PickupAction if bit 3 of the actor flags is set.
A1CA JP NZ,Handler_PickupAction
Drop the object to the ground while bit 7 of the actor flags is set.
A1CD BIT 7,(IX+$08) Jump to Handler_Pickup_Draw if bit 7 of the actor flags is reset.
A1D1 JR Z,Handler_Pickup_Draw
A1D3 CALL ClampObjectToGround Call ClampObjectToGround.
A1D6 JR C,Handler_Pickup_TestCarrying Jump to Handler_Pickup_TestCarrying if the object has not landed.
A1D8 LD A,(IX+$08) Fetch the actor flags.
A1DB AND %00000010 Keep only bit 1.
A1DD LD (IX+$08),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 A1E0 LD A,($5EA3) Fetch RoverCargoFlag.
A1E3 AND A Jump to Handler_Pickup_Draw if the rover is already carrying.
A1E4 JR NZ,Handler_Pickup_Draw
A1E6 CALL CompareActorDistance Call CompareActorDistance.
A1E9 JR NC,Handler_Pickup_Draw Jump to Handler_Pickup_Draw if the object is out of range.
A1EB LD A,$01 Write 01 to RoverCargoFlag.
A1ED LD ($5EA3),A
A1F0 SET 3,(IX+$08) Set bit 3 of the actor flags.
A1F4 RES 2,(IX+$08) Reset bit 2 of the actor flags.
Handler_Pickup_Draw A1F8 CALL DrawCurrentActor_Draw Call DrawCurrentActor_Draw.
Type 11 and above means Jetman is not on foot.
A1FB LD A,($6078) Fetch Jetman_Slot.
A1FE CP $11 Return if Jetman's type is at least 11.
A200 RET NC
A201 BIT 2,(IX+$08) Jump to Handler_PickupAction_SnapToJetman if bit 2 of the actor flags is set.
A205 JP NZ,Handler_PickupAction_SnapToJetman
A208 CALL TestActionKey Call TestActionKey.
A20B JP NZ,Handler_PickupAction_Collect Jump to Handler_PickupAction_Collect if the action key is pressed.
A20E RES 1,(IX+$08) Reset bit 1 of the actor flags.
This entry point is used by the routine at Handler_PickupAction.
Teleport Jetman when SPACE is pressed beside this pickup.
Handler_Pickup_Teleport A212 LD A,($6078) Fetch Jetman_Slot.
A215 CP $11 Return if Jetman's type is at least 11.
A217 RET NC
Return unless Jetman is in range and SPACE is pressed.
A218 CALL TestJetmanAction_ComparePosition Call TestJetmanAction_ComparePosition.
A21B RET NC Return if the object is out of range.
A21C CALL TestSpaceKey Call TestSpaceKey.
A21F 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.
A220 PUSH IX Copy the slot pointer into HL (using the stack).
A222 POP HL
A223 LD BC,$60A8 Set BC to the slot-1 address World_Slot_1.
A226 AND A Subtract the slot-1 address.
A227 SBC HL,BC
A229 JP Z,ResumePickup Jump to ResumePickup if this is slot 1.
A22C LD A,($60AC) Fetch World_Slot_1_Y.
A22F LD HL,($60AA) Fetch World_Slot_1_Position.
This entry point is used by the routine at ResumePickup.
Move Jetman onto the destination object's position and start the teleport.
Handler_Pickup_Attach A232 LD DE,($607C) Fetch Jetman_Y into DE.
A236 LD ($607C),A Write the destination Y over Jetman_Y.
A239 LD A,L Fetch the low byte of the destination world X.
A23A AND %11111000 Keep only bits 3-7.
A23C LD L,A Write it back.
A23D LD ($607A),HL Write the pair to Jetman_Position.
Record a Y near Jetman's old position for the debris burst.
A240 LD A,E Fetch Jetman's old Y.
A241 SUB $0C Subtract 0C.
A243 LD ($5E6A),A Write it to Debris_Y.
A246 LD A,($6078) 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.
A249 DEC A Decrease it to a 0-based sprite index.
A24A AND %11110111 Reset bit 3.
A24C INC A Increase it by one.
A24D LD ($6078),A Write it back.
A250 JP StartTeleport Jump to StartTeleport.
Prev: A0F8 Up: Map Next: A253