Prev: 58553 Up: Map Next: 59060
58656: Process Cluster Entity
Per-frame entity handler for the cluster entities spawned when a tracked wave enemy promotes. Advances three bytes to a countdown timer, decrements it, and redraws the entity via Paint_Narrow_Entity_Attributes while the timer is still running. When the timer reaches zero, calls Erase_Entity_Sprite to erase the entity sprite. If the animation pass counter (two bytes back) is also exhausted, detaches the entity and scores; otherwise increments the pass counter, redraws via Draw_Entity_Sprite, sets the animation delay to 4 and jumps to Tick_Entity_Colour_Timer_Advance. On further passes the handler transitions to Process_Cluster_Entity_Homing, which searches for player contact via Find_Colliding_Entity and triggers a kill via Process_Player_Tracking_Enemy if found, or else applies directional movement toward the player and draws via Draw_Narrow_Entity_Sprite.
Process_Cluster_Entity 58656 INC HL Advance three bytes to the countdown timer, decrement it, and check for expiry.
58657 INC HL
58658 INC HL
58659 DEC (HL)
58660 DEC HL
58661 DEC HL
58662 DEC HL
58663 JP Z,Process_Cluster_Entity_Expired Timer still running: redraw the entity via Paint_Narrow_Entity_Attributes and advance.
58666 EXX
58667 LD B,69
58669 EXX
58670 PUSH HL
58671 CALL Paint_Narrow_Entity_Attributes
58674 POP HL
58675 JP Retire_Expired_Entity_Advance
Process_Cluster_Entity_Expired 58678 PUSH HL Timer expired: erase the entity sprite via Erase_Entity_Sprite.
58679 CALL Erase_Entity_Sprite
58682 POP HL
58683 INC (HL)
58684 LD A,(HL) Check the pass counter; jump to Process_Cluster_Entity_Transition if the maximum pass count (31) is reached.
58685 CP 31
58687 JP Z,Process_Cluster_Entity_Transition
58690 PUSH HL Increment the pass counter, redraw the entity via Draw_Entity_Sprite, and write animation delay 4.
58691 EXX
58692 LD B,69
58694 EXX
58695 CALL Draw_Entity_Sprite
58698 POP HL
58699 INC HL
58700 INC HL Jump to Tick_Entity_Colour_Timer_Advance to advance the entity pointer.
58701 INC HL
58702 LD (HL),4
58704 JP Tick_Entity_Colour_Timer_Advance
Process_Cluster_Entity_Transition 58707 DEC HL Write handler Process_Cluster_Entity_Homing and redraw the entity via Draw_Entity_Sprite; set the animation byte to 11.
58708 DEC HL
58709 LD DE,58733
58712 LD (HL),E
58713 INC HL
58714 LD (HL),D
58715 INC HL
58716 PUSH HL
58717 EXX
58718 LD B,69
58720 EXX
58721 CALL Draw_Entity_Sprite
58724 POP HL
58725 INC HL
58726 INC HL
58727 INC HL
58728 LD (HL),11
58730 DEC HL
58731 DEC HL
58732 DEC HL
Process_Cluster_Entity_Homing 58733 INC HL Increment the animation counter and check for overflow; jump to Process_Cluster_Entity_Advance if the counter wraps.
58734 LD A,(HL)
58735 INC A
58736 JP Z,Process_Cluster_Entity_Advance
58739 PUSH HL Stash HL, step back one byte, and erase the entity sprite via Erase_Entity_Sprite.
58740 DEC HL
58741 CALL Erase_Entity_Sprite
58744 POP HL
58745 EXX Search for a player-contact slot via Find_Colliding_Entity, then jump to Process_Player_Tracking_Enemy if player contact is detected.
58746 CALL Find_Colliding_Entity
58749 JP C,Process_Player_Tracking_Enemy
Entity not touching the player: erase the sprite again, score 2 BCD, and update the colour bar.
58752 LD DE,6 Step back six bytes, erase the sprite via Erase_Narrow_Entity_Sprite, and restore HL.
58755 AND A
58756 SBC HL,DE
58758 PUSH HL
58759 CALL Erase_Narrow_Entity_Sprite
58762 POP HL
58763 CALL Remove_Entity_From_List_Step Remove the entity from the list via Remove_Entity_From_List_Step.
58766 LD DE,50181 Add 2 BCD to the low score digit at 50181 and propagate carry through two further score digits.
58769 LD A,(DE)
58770 ADD A,2
58772 DAA
58773 LD (DE),A
58774 JP NC,Process_Cluster_Entity_Score_Bar
58777 DEC DE
58778 LD A,(DE)
58779 ADD A,1
58781 DAA
58782 LD (DE),A
58783 JP NC,Process_Cluster_Entity_Score_Bar
58786 DEC DE
58787 LD A,(DE)
58788 ADD A,1
58790 DAA
58791 LD (DE),A
Process_Cluster_Entity_Score_Bar 58792 EXX Update the colour bar via Clear_Colour_Bar_Column, decrement the active count at 50221 and Active_Enemy_Count, restore HL, and mark the entity slot as finished.
58793 PUSH HL
58794 CALL Clear_Colour_Bar_Column
58797 LD HL,50221
58800 DEC (HL)
58801 LD HL,50204
58804 DEC (HL)
58805 POP HL
58806 LD (HL),255
Process_Cluster_Entity_Advance 58808 INC HL Advance four bytes and check the secondary timer byte.
This entry point is used by the routine at Process_Player_Tracking_Enemy.
Process_Cluster_Entity_Next 58809 INC HL
58810 INC HL
58811 INC HL
58812 LD A,(HL)
58813 AND A }
58814 JP Z,Process_Cluster_Entity_Seek Decrement the secondary timer; if it reaches zero, erase the entity sprite via Erase_Narrow_Entity_Sprite; then jump to Process_Cluster_Entity_Seek.
58817 DEC (HL)
58818 JP NZ,Process_Cluster_Entity_Move
58821 PUSH HL
58822 INC HL
58823 CALL Erase_Narrow_Entity_Sprite
58826 POP HL
58827 JP Process_Cluster_Entity_Seek
Process_Cluster_Entity_Move 58830 INC HL Move to the entity position bytes, switch to alternate registers, and set the player Y address in alternate HL; trigger death via Strip_Attributes_And_Fade if touching.
58831 INC HL
58832 EXX
58833 LD HL,50388
58836 EXX
58837 CALL HitTestBounds8AtHL
58840 JP NC,Strip_Attributes_And_Fade
58843 DEC HL Step back four bytes and stash the entity pointer.
58844 DEC HL
58845 DEC HL
58846 PUSH HL
58847 DEC HL
58848 CALL Erase_Narrow_Entity_Sprite Step back, erase the sprite via Erase_Narrow_Entity_Sprite, and search for a player slot via Find_Colliding_Entity; jump to Apply_Entity_Velocity if player contact.
58851 POP HL
58852 EXX
58853 CALL Find_Colliding_Entity
58856 JP C,Apply_Entity_Velocity
58859 LD DE,6
58862 SBC HL,DE Step back six bytes, erase the entity via Erase_Narrow_Entity_Sprite, score 37 BCD against the six-byte score at 50182 and propagate carry.
58864 PUSH HL
58865 CALL Erase_Narrow_Entity_Sprite
58868 POP HL
58869 CALL Remove_Entity_From_List_Step
58872 LD HL,50182
58875 LD A,(HL)
58876 ADD A,37
58878 DAA
58879 LD (HL),A
58880 JP NC,Process_Cluster_Entity_Bar
58883 LD B,3
Process_Cluster_Entity_Score_Carry 58885 DEC HL Propagate BCD carry through B higher-order score digits.
58886 LD A,(HL)
58887 ADD A,1
58889 DAA
58890 LD (HL),A
58891 JP NC,Process_Cluster_Entity_Bar
58894 DJNZ Process_Cluster_Entity_Score_Carry
Process_Cluster_Entity_Bar 58896 CALL Clear_Colour_Bar_Column Refresh the colour bar via Clear_Colour_Bar_Column, switch to alternate registers, and step back DE bytes to the entity record start.
58899 EXX
58900 JP Process_Cluster_Entity_Seek_Y
58903 DEC HL
58904 DEC HL
58905 DEC HL
Process_Cluster_Entity_Seek_Y 58906 DEC HL Step back two more bytes to the entity handler field.
58907 DEC HL
Process_Cluster_Entity_Seek 58908 LD D,H Load the Y and X position bytes and compute the signed Y offset from the player's Y coordinate at 50388.
58909 LD E,L
58910 DEC DE
58911 DEC DE
58912 DEC DE
58913 DEC DE
58914 LD A,(DE)
58915 INC A
58916 JP Z,Retire_Cluster_Entity
58919 LD (HL),55
58921 INC HL Compute the signed Y and X distances from the player, halve each distance five times to form a velocity nudge, and negate if negative.
58922 INC HL
58923 PUSH HL
58924 LD A,(DE)
58925 LD C,A
58926 LD B,0
58928 LD A,(50388)
58931 LD L,A
58932 LD H,0
58934 AND A
58935 SBC HL,BC
58937 BIT 0,H
58939 LD A,L
58940 JP Z,Process_Cluster_Entity_0
58943 NEG
Process_Cluster_Entity_0 58945 SRL A
58947 SRL A
58949 SRL A
58951 SRL A
58953 BIT 0,H
58955 JP Z,Process_Cluster_Entity_Seek_X
58958 NEG
Process_Cluster_Entity_Seek_X 58960 EX AF,AF' Compute the X nudge from the player's X coordinate at 50389 in the same way.
58961 INC DE
58962 LD A,(DE)
58963 LD C,A
58964 LD B,0
58966 LD A,(50389)
58969 LD L,A
58970 LD H,0
58972 AND A
58973 SBC HL,BC
58975 BIT 0,H
58977 LD A,L
58978 JP Z,Process_Cluster_Entity_1
58981 NEG
Process_Cluster_Entity_1 58983 SRL A
58985 SRL A
58987 SRL A
58989 SRL A
58991 BIT 0,H
58993 JP Z,Process_Cluster_Entity_2
58996 NEG
Process_Cluster_Entity_2 58998 LD C,A
58999 EX AF,AF'
59000 LD B,A
59001 POP HL
Process_Cluster_Entity_Chase 59002 OR C If both nudge components are zero, replace them with a small random drift.
59003 JP NZ,Process_Cluster_Entity_Apply
59006 CALL Generate_Random_Byte
59009 AND 3
59011 SUB 1
59013 LD C,A
59014 CALL Generate_Random_Byte
59017 AND 3
59019 SUB 2
59021 LD B,A
59022 JP Process_Cluster_Entity_Chase
Process_Cluster_Entity_Apply 59025 DEC DE Add the Y nudge offset 3 to the Y position; advance DE and HL.
59026 LD A,(DE)
59027 ADD A,3
59029 LD (HL),A
59030 INC DE Add the X nudge offset 2 to the X position and advance.
59031 INC HL
59032 LD A,(DE)
59033 ADD A,2
59035 LD (HL),A
59036 INC HL
59037 INC HL
59038 INC HL Write the computed Y and X nudge bytes to the record and stash HL.
59039 LD (HL),B
59040 INC HL
59041 LD (HL),C
59042 PUSH HL
59043 LD DE,6
59046 AND A Step back six bytes, set colour INK: WHITE, PAPER: BLACK (BRIGHT) in B', draw via Draw_Narrow_Entity_Sprite, and advance two bytes before returning.
59047 SBC HL,DE
59049 EXX
59050 LD B,71
59052 EXX
59053 CALL Draw_Narrow_Entity_Sprite
59056 POP HL
59057 INC HL
59058 INC HL
59059 RET
Prev: 58553 Up: Map Next: 59060