Prev: 39421 Up: Map Next: 39606
39434: Update Pickup Entity
Updates an entity of the type 15 which is made by CreatePickup. While the frame of the entity is 0 or 1 it moves up or down on its third coordinate to line up with the player, and in one frame in every 128 on average, it changes into frame 2. Frame 3 is set up from a random choice of the table at PickupFrames, and later frames count down in field 32 until the entity is turned into one of type 7.
Input
IX The entity
UpdatePickupEntity 39434 LD A,(IX+1) Fetch the frame of the entity.
39437 AND %00011111 Keep the number of the frame.
39439 CP 2 Jump to UpdatePickupEntity_LaterFrames if it is 2 or more.
39441 JR NC,UpdatePickupEntity_LaterFrames
39443 LD A,(46408) Fetch the first byte of the third coordinate of the player from 46408.
39446 LD H,A Copy it into H.
39447 LD A,(46409) Fetch the second byte of the third coordinate of the player from 46409.
39450 LD L,A Copy it into L.
39451 LD BC,48 BC is 48.
39454 ADD HL,BC Add it to the third coordinate of the player.
39455 LD D,(IX+8) Fetch the first byte of the third coordinate of the entity.
39458 LD E,(IX+9) Fetch the second byte of the third coordinate of the entity.
39461 SBC HL,DE Subtract it from the third coordinate of the player.
39463 LD HL,64 Set the speed to 64 to move up.
39466 JR NC,UpdatePickupEntity_SetSpeed Jump to UpdatePickupEntity_SetSpeed if the entity is below the player.
39468 LD HL,65472 Set the speed to 65472 to move down.
UpdatePickupEntity_SetSpeed 39471 LD (IX+20),H Store the first byte of the speed in field 20 of the entity.
39474 LD (IX+21),L Store the second byte of the speed in field 21 of the entity.
39477 CALL GetRandomNumber Call GetRandomNumber to get a random number.
39480 LD A,(24474) Fetch the low byte of the seed.
39483 AND %01111111 Use bits 0-6.
39485 JP NZ,UpdateEntity_Move Jump to UpdateEntity_Move to carry on updating the entity unless they are all zero.
39488 LD (IX+1),2 Set the frame of the entity to 2.
39492 LD (IX+28),81 Set field 28 of the entity to 81.
39496 LD (IX+29),51 Set field 29 of the entity to 51.
39500 CALL SetEntitySize Call SetEntitySize to set the sprite of the entity.
39503 CALL PlaySlowFall Call PlaySlowFall.
39506 JP UpdateEntity_Move Jump to UpdateEntity_Move to carry on updating the entity.
UpdatePickupEntity_LaterFrames 39509 CP 2 Jump to UpdateEntity_Move to carry on updating the entity if it is 2.
39511 JP Z,UpdateEntity_Move
39514 CP 3 Jump to UpdatePickupEntity_Countdown unless it is 3.
39516 JR NZ,UpdatePickupEntity_Countdown
39518 LD A,(24474) Fetch the low byte of the seed.
39521 AND %00000110 Use bits 1-2.
39523 LD HL,39606 Point HL at PickupFrames.
39526 CALL AddToAddress Add the offset to find the entry.
39529 LD A,(HL) Fetch the frame from the entry.
39530 LD (IX+1),A Set the frame of the entity.
39533 INC HL Move onto the next byte of the entry.
39534 LD A,(HL) Fetch the value from the entry.
39535 LD (IX+29),A Set field 29 of the entity.
39538 LD (IX+32),64 Set field 32 of the entity to 64.
39542 LD (IX+28),3 Set field 28 of the entity to 3.
39546 LD (IX+20),255 Set field 20 of the entity to 255.
39550 LD (IX+21),160 Set field 21 of the entity to 160.
39554 CALL SetEntitySize Call SetEntitySize to set the sprite of the entity.
39557 RES 7,(IX+17) Reset bit 7 of the heading.
39561 JP UpdateEntity_Move Jump to UpdateEntity_Move to carry on updating the entity.
UpdatePickupEntity_Countdown 39564 LD A,(IX+29) Read field 29 of the entity.
39567 CP 84 Jump to UpdatePickupEntity_Move unless it is 84.
39569 JR NZ,UpdatePickupEntity_Move
39571 CALL FacePlayer Call FacePlayer to choose the direction towards the player.
39574 LD A,(IX+32) Read field 32 of the entity.
39577 OR %10000000 Set bit 7.
39579 LD (IX+17),A Set the heading.
39582 LD A,(IX+31) Read field 31 of the entity.
39585 AND A Test it.
39586 JP NZ,UpdateEntity_Move Jump to UpdateEntity_Move to carry on updating the entity if it is not zero.
39589 JR UpdatePickupEntity_Finish Jump to UpdatePickupEntity_Finish to finish with the entity.
UpdatePickupEntity_Move 39591 CALL DecreaseEntityCounter Call DecreaseEntityCounter.
39594 DEC (IX+32) Decrease field 32 of the entity by one.
39597 JP NZ,UpdateEntity_Move Jump to UpdateEntity_Move to carry on updating the entity unless it is zero.
UpdatePickupEntity_Finish 39600 CALL StartBurst Call StartBurst to turn the entity into one of type 7.
39603 JP UpdateEntity_Move Jump to UpdateEntity_Move to carry on updating the entity.
Prev: 39421 Up: Map Next: 39606