Prev: 52532 Up: Map Next: 52836
52560: Handle Homing Enemy
Per-frame entity handler for a homing enemy. Each frame the entity moves one step toward the player. If it catches another entity it removes that entity from play, awards the player points, and shows a floating score popup. If it reaches the player it triggers the player death sequence.
Handle_Homing_Enemy 52560 LD A,(50483) Read the wave start delay from Wave_Start_Delay.
52563 AND A Jump to Process_Entity_Record_Counter_Up_Next7 if the wave has not started yet.
52564 JP NZ,Process_Entity_Record_Counter_Up_Next7
52567 CALL Generate_Random_Byte Generate a random movement delay value.
52570 AND %00001111 Keep the low four bits (delay range 0–15).
52572 INC A Increment to give a delay range of 1–16.
52573 LD (50422),HL Stash the entity record pointer and load the delay into B.
52576 LD B,A
52577 LD A,(50460) Read the animation frame counter from 50460.
52580 SUB B Skip movement this frame if the frame counter has not yet reached the delay value.
52581 JP NC,Handle_Homing_Enemy_Advance
52584 INC HL Step past the handler address and erase the entity sprite.
52585 CALL Erase_Entity_Sprite
52588 LD HL,(50422) Restore the entity record pointer and advance to the entity position bytes.
52591 INC HL
52592 INC HL
Move the entity one step toward the player along both axes.
52593 LD A,(50388) Compute the vertical distance from this entity to the player.
52596 SUB (HL)
52597 LD A,(50214) Load the vertical movement speed and negate it if the entity is above the player.
52600 JR NC,Handle_Homing_Enemy_Apply_Y
52602 NEG
Handle_Homing_Enemy_Apply_Y 52604 ADD A,(HL) Apply the vertical delta and step to the X position byte.
52605 LD (HL),A
52606 INC HL
52607 LD A,(50389) Compute the horizontal distance from this entity to the player.
52610 SUB (HL)
52611 LD A,(50214) Load the horizontal movement speed and negate it if the entity is to the right of the player.
52614 JR NC,Handle_Homing_Enemy_Apply_X
52616 NEG
Handle_Homing_Enemy_Apply_X 52618 ADD A,(HL) Apply the horizontal delta to the entity X position.
52619 LD (HL),A
52620 DEC HL Step back to the entity Y position.
52621 DEC HL
52622 EXX Set the draw colour to 70 in the shadow registers.
52623 LD B,70
52625 EXX
52626 CALL Draw_Entity_Sprite Redraw the entity sprite at its new position.
52629 LD HL,(50422) Restore the entity record pointer.
Handle_Homing_Enemy_Advance 52632 INC HL Advance the entity record pointer by two bytes.
52633 INC HL
52634 EXX Jump to Handle_Homing_Enemy_Caught_Entity if this entity has caught another entity in the list.
52635 CALL Find_Colliding_Entity
52638 JR NC,Handle_Homing_Enemy_Caught_Entity
52640 LD HL,50388 Point to the player position data and switch to the shadow registers.
52643 EXX
52644 CALL HitTestBounds8AtHL Trigger the player death sequence if this entity has reached the player.
52647 JP NC,Strip_Attributes_And_Fade
52650 INC HL Advance the entity pointer and return.
52651 INC HL
52652 RET
This entity has reached another entity; remove the caught entity from play, award the player points, and display a floating score popup.
Handle_Homing_Enemy_Caught_Entity 52653 LD DE,6 Step back six bytes to the start of the caught entity's record.
52656 SBC HL,DE
52658 LD (50394),HL Save the caught entity's record pointer to Entity_Record_Pointer.
52661 CALL Erase_Narrow_Entity_Sprite Erase the caught entity's sprite.
52664 CALL Remove_Entity_From_List Remove the caught entity from the entity list.
52667 LD HL,50204 Decrement the active enemy count at Active_Enemy_Count.
52670 DEC (HL)
52671 LD HL,50213 Decrement the wave entity kill counter.
52674 DEC (HL)
52675 EXX Install the score popup handler and update the entity state in the shadow record.
52676 DEC HL
52677 DEC HL
52678 LD (HL),2
52680 DEC HL
52681 LD DE,52767
52684 LD (HL),D
52685 DEC HL
52686 LD (HL),E
52687 INC HL Step forward to the entity position byte.
52688 INC HL
52689 INC HL
52690 PUSH HL Erase the score popup sprite.
52691 CALL Erase_Entity_Sprite
52694 POP HL
52695 INC HL Step to the entity Y position byte.
52696 EXX Set the draw colour to 2 in the shadow registers.
52697 LD B,2
52699 EXX
52700 LD A,(HL) Clamp the score popup Y position within the play area.
52701 SUB 6
52703 CP 16
52705 JR C,Handle_Homing_Enemy_1
52707 CP 185
52709 JR C,Handle_Homing_Enemy_0
52711 SUB 6
Handle_Homing_Enemy_0 52713 LD (HL),A
Handle_Homing_Enemy_1 52714 DEC HL
52715 PUSH HL Draw the score popup sprite at the entity's position.
52716 CALL Draw_Clipped_Wide_Sprite
52719 POP HL
52720 LD DE,6 Step forward to the player's BCD score bytes.
52723 ADD HL,DE
Award the player points for catching the entity; add the point value to the BCD score with carry propagation through all four score bytes.
52724 EXX Add the enemy's point value to the least significant BCD score byte.
52725 LD HL,50182
52728 LD A,(HL)
52729 ADD A,0
52731 DAA
52732 LD (HL),A
52733 LD A,1 Propagate BCD carry from the lowest score byte into the next score byte.
52735 DEC HL
52736 JR NC,Handle_Homing_Enemy_2
52738 INC A
Handle_Homing_Enemy_2 52739 ADD A,(HL)
52740 DAA
52741 LD (HL),A
52742 JR NC,Handle_Homing_Enemy_3
52744 DEC HL Propagate BCD carry through the second score byte.
52745 LD A,1
52747 ADD A,(HL)
52748 DAA
52749 LD (HL),A
52750 JR NC,Handle_Homing_Enemy_3
52752 DEC HL Propagate BCD carry into the most significant score byte.
52753 LD A,1
52755 DAA
52756 LD (HL),A
Handle_Homing_Enemy_3 52757 CALL Clear_Colour_Bar_Column Refresh the score display column.
52760 LD E,0 Initialise the score popup entity state via Initialise_Entity_State.
52762 CALL Initialise_Entity_State
52765 EXX Restore the main register set and return.
52766 RET
Per-frame handler for the floating score popup; scrolls the popup upward each frame until 15 frames have elapsed.
Handle_Homing_Enemy_Float_Score 52767 LD A,(HL) Load the entity state byte into shadow B'.
52768 EXX
52769 LD B,A
52770 EXX
52771 PUSH HL Draw the score popup sprite at the current entity position.
52772 INC HL
52773 CALL Draw_Clipped_Wide_Sprite
52776 POP HL
52777 INC (HL) Advance the animation frame and jump to Handle_Homing_Enemy_Float_Score_Exit when the score popup has completed.
52778 LD A,(HL)
52779 CP 15
52781 JR Z,Handle_Homing_Enemy_Float_Score_Exit
52783 EXX Update shadow B' with the frame count and advance to the entity Y position.
52784 LD B,A
52785 EXX
52786 INC HL
52787 INC HL
52788 LD A,(HL) Select the vertical scroll speed based on the Y position.
52789 CP 22
52791 JR NC,Handle_Homing_Enemy_4
52793 CP 173
52795 LD A,0
52797 JR NC,Handle_Homing_Enemy_Float_Score_Done
52799 JR Handle_Homing_Enemy_Float_Score_Move
Handle_Homing_Enemy_4 52801 CP 176 Adjust the scroll speed for the upper boundary.
52803 LD A,250
52805 JR C,Handle_Homing_Enemy_Float_Score_Move
52807 LD A,244
Handle_Homing_Enemy_Float_Score_Move 52809 ADD A,(HL) Apply the Y delta, redraw the score popup, and continue at Process_Entity_Record_Next6.
52810 LD (HL),A
52811 DEC HL
52812 PUSH HL
52813 CALL Draw_Clipped_Wide_Sprite
52816 POP HL
52817 JP Process_Entity_Record_Next6
Handle_Homing_Enemy_Float_Score_Done 52820 DEC HL Step back to the handler address field.
52821 DEC HL
Handle_Homing_Enemy_Float_Score_Exit 52822 LD DE,57388 Install Process_Entity_Record_Next7 as the score popup completion handler.
52825 DEC HL
52826 LD (HL),D
52827 DEC HL
52828 LD (HL),E
52829 INC HL
52830 INC HL
52831 JP Process_Entity_Record_Next7 Jump to Process_Entity_Record_Next7 to finalise the score popup.
52834 POP DE Return.
52835 RET
Prev: 52532 Up: Map Next: 52836