Prev: 99FD Up: Map Next: 9AB6
9A0A: Update Pickup Entity
Updates an entity of the type 0F which is made by CreatePickup. While the frame of the entity is 00 or 01 it moves up or down on its third coordinate to line up with the player, and in one frame in every 80 on average, it changes into frame 02. Frame 03 is set up from a random choice of the table at PickupFrames, and later frames count down in field 20 until the entity is turned into one of type 07.
Input
IX The entity
UpdatePickupEntity 9A0A LD A,(IX+$01) Fetch the frame of the entity.
9A0D AND %00011111 Keep the number of the frame.
9A0F CP $02 Jump to UpdatePickupEntity_LaterFrames if it is 02 or more.
9A11 JR NC,UpdatePickupEntity_LaterFrames
9A13 LD A,($B548) Fetch the first byte of the third coordinate of the player from B548.
9A16 LD H,A Copy it into H.
9A17 LD A,($B549) Fetch the second byte of the third coordinate of the player from B549.
9A1A LD L,A Copy it into L.
9A1B LD BC,$0030 BC is 30.
9A1E ADD HL,BC Add it to the third coordinate of the player.
9A1F LD D,(IX+$08) Fetch the first byte of the third coordinate of the entity.
9A22 LD E,(IX+$09) Fetch the second byte of the third coordinate of the entity.
9A25 SBC HL,DE Subtract it from the third coordinate of the player.
9A27 LD HL,$0040 Set the speed to 40 to move up.
9A2A JR NC,UpdatePickupEntity_SetSpeed Jump to UpdatePickupEntity_SetSpeed if the entity is below the player.
9A2C LD HL,$FFC0 Set the speed to FFC0 to move down.
UpdatePickupEntity_SetSpeed 9A2F LD (IX+$14),H Store the first byte of the speed in field 14 of the entity.
9A32 LD (IX+$15),L Store the second byte of the speed in field 15 of the entity.
9A35 CALL GetRandomNumber Call GetRandomNumber to get a random number.
9A38 LD A,($5F9A) Fetch the low byte of the seed.
9A3B AND %01111111 Use bits 0-6.
9A3D JP NZ,UpdateEntity_Move Jump to UpdateEntity_Move to carry on updating the entity unless they are all zero.
9A40 LD (IX+$01),$02 Set the frame of the entity to 02.
9A44 LD (IX+$1C),$51 Set field 1C of the entity to 51.
9A48 LD (IX+$1D),$33 Set field 1D of the entity to 33.
9A4C CALL SetEntitySize Call SetEntitySize to set the sprite of the entity.
9A4F CALL PlaySlowFall Call PlaySlowFall.
9A52 JP UpdateEntity_Move Jump to UpdateEntity_Move to carry on updating the entity.
UpdatePickupEntity_LaterFrames 9A55 CP $02 Jump to UpdateEntity_Move to carry on updating the entity if it is 02.
9A57 JP Z,UpdateEntity_Move
9A5A CP $03 Jump to UpdatePickupEntity_Countdown unless it is 03.
9A5C JR NZ,UpdatePickupEntity_Countdown
9A5E LD A,($5F9A) Fetch the low byte of the seed.
9A61 AND %00000110 Use bits 1-2.
9A63 LD HL,$9AB6 Point HL at PickupFrames.
9A66 CALL AddToAddress Add the offset to find the entry.
9A69 LD A,(HL) Fetch the frame from the entry.
9A6A LD (IX+$01),A Set the frame of the entity.
9A6D INC HL Move onto the next byte of the entry.
9A6E LD A,(HL) Fetch the value from the entry.
9A6F LD (IX+$1D),A Set field 1D of the entity.
9A72 LD (IX+$20),$40 Set field 20 of the entity to 40.
9A76 LD (IX+$1C),$03 Set field 1C of the entity to 03.
9A7A LD (IX+$14),$FF Set field 14 of the entity to FF.
9A7E LD (IX+$15),$A0 Set field 15 of the entity to A0.
9A82 CALL SetEntitySize Call SetEntitySize to set the sprite of the entity.
9A85 RES 7,(IX+$11) Reset bit 7 of the heading.
9A89 JP UpdateEntity_Move Jump to UpdateEntity_Move to carry on updating the entity.
UpdatePickupEntity_Countdown 9A8C LD A,(IX+$1D) Read field 1D of the entity.
9A8F CP $54 Jump to UpdatePickupEntity_Move unless it is 54.
9A91 JR NZ,UpdatePickupEntity_Move
9A93 CALL FacePlayer Call FacePlayer to choose the direction towards the player.
9A96 LD A,(IX+$20) Read field 20 of the entity.
9A99 OR %10000000 Set bit 7.
9A9B LD (IX+$11),A Set the heading.
9A9E LD A,(IX+$1F) Read field 1F of the entity.
9AA1 AND A Test it.
9AA2 JP NZ,UpdateEntity_Move Jump to UpdateEntity_Move to carry on updating the entity if it is not zero.
9AA5 JR UpdatePickupEntity_Finish Jump to UpdatePickupEntity_Finish to finish with the entity.
UpdatePickupEntity_Move 9AA7 CALL DecreaseEntityCounter Call DecreaseEntityCounter.
9AAA DEC (IX+$20) Decrease field 20 of the entity by one.
9AAD JP NZ,UpdateEntity_Move Jump to UpdateEntity_Move to carry on updating the entity unless it is zero.
UpdatePickupEntity_Finish 9AB0 CALL StartBurst Call StartBurst to turn the entity into one of type 07.
9AB3 JP UpdateEntity_Move Jump to UpdateEntity_Move to carry on updating the entity.
Prev: 99FD Up: Map Next: 9AB6