Prev: E4B9 Up: Map Next: E6B4
E520: 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 04 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 E520 INC HL Advance three bytes to the countdown timer, decrement it, and check for expiry.
E521 INC HL
E522 INC HL
E523 DEC (HL)
E524 DEC HL
E525 DEC HL
E526 DEC HL
E527 JP Z,Process_Cluster_Entity_Expired Timer still running: redraw the entity via Paint_Narrow_Entity_Attributes and advance.
E52A EXX
E52B LD B,$45
E52D EXX
E52E PUSH HL
E52F CALL Paint_Narrow_Entity_Attributes
E532 POP HL
E533 JP Retire_Expired_Entity_Advance
Process_Cluster_Entity_Expired E536 PUSH HL Timer expired: erase the entity sprite via Erase_Entity_Sprite.
E537 CALL Erase_Entity_Sprite
E53A POP HL
E53B INC (HL)
E53C LD A,(HL) Check the pass counter; jump to Process_Cluster_Entity_Transition if the maximum pass count (1F) is reached.
E53D CP $1F
E53F JP Z,Process_Cluster_Entity_Transition
E542 PUSH HL Increment the pass counter, redraw the entity via Draw_Entity_Sprite, and write animation delay 04.
E543 EXX
E544 LD B,$45
E546 EXX
E547 CALL Draw_Entity_Sprite
E54A POP HL
E54B INC HL
E54C INC HL Jump to Tick_Entity_Colour_Timer_Advance to advance the entity pointer.
E54D INC HL
E54E LD (HL),$04
E550 JP Tick_Entity_Colour_Timer_Advance
Process_Cluster_Entity_Transition E553 DEC HL Write handler Process_Cluster_Entity_Homing and redraw the entity via Draw_Entity_Sprite; set the animation byte to 0B.
E554 DEC HL
E555 LD DE,$E56D
E558 LD (HL),E
E559 INC HL
E55A LD (HL),D
E55B INC HL
E55C PUSH HL
E55D EXX
E55E LD B,$45
E560 EXX
E561 CALL Draw_Entity_Sprite
E564 POP HL
E565 INC HL
E566 INC HL
E567 INC HL
E568 LD (HL),$0B
E56A DEC HL
E56B DEC HL
E56C DEC HL
Process_Cluster_Entity_Homing E56D INC HL Increment the animation counter and check for overflow; jump to Process_Cluster_Entity_Advance if the counter wraps.
E56E LD A,(HL)
E56F INC A
E570 JP Z,Process_Cluster_Entity_Advance
E573 PUSH HL Stash HL, step back one byte, and erase the entity sprite via Erase_Entity_Sprite.
E574 DEC HL
E575 CALL Erase_Entity_Sprite
E578 POP HL
E579 EXX Search for a player-contact slot via Find_Colliding_Entity, then jump to Process_Player_Tracking_Enemy if player contact is detected.
E57A CALL Find_Colliding_Entity
E57D JP C,Process_Player_Tracking_Enemy
Entity not touching the player: erase the sprite again, score 02 BCD, and update the colour bar.
E580 LD DE,$0006 Step back six bytes, erase the sprite via Erase_Narrow_Entity_Sprite, and restore HL.
E583 AND A
E584 SBC HL,DE
E586 PUSH HL
E587 CALL Erase_Narrow_Entity_Sprite
E58A POP HL
E58B CALL Remove_Entity_From_List_Step Remove the entity from the list via Remove_Entity_From_List_Step.
E58E LD DE,$C405 Add 02 BCD to the low score digit at C405 and propagate carry through two further score digits.
E591 LD A,(DE)
E592 ADD A,$02
E594 DAA
E595 LD (DE),A
E596 JP NC,Process_Cluster_Entity_Score_Bar
E599 DEC DE
E59A LD A,(DE)
E59B ADD A,$01
E59D DAA
E59E LD (DE),A
E59F JP NC,Process_Cluster_Entity_Score_Bar
E5A2 DEC DE
E5A3 LD A,(DE)
E5A4 ADD A,$01
E5A6 DAA
E5A7 LD (DE),A
Process_Cluster_Entity_Score_Bar E5A8 EXX Update the colour bar via Clear_Colour_Bar_Column, decrement the active count at C42D and Active_Enemy_Count, restore HL, and mark the entity slot as finished.
E5A9 PUSH HL
E5AA CALL Clear_Colour_Bar_Column
E5AD LD HL,$C42D
E5B0 DEC (HL)
E5B1 LD HL,$C41C
E5B4 DEC (HL)
E5B5 POP HL
E5B6 LD (HL),$FF
Process_Cluster_Entity_Advance E5B8 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 E5B9 INC HL
E5BA INC HL
E5BB INC HL
E5BC LD A,(HL)
E5BD AND A }
E5BE 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.
E5C1 DEC (HL)
E5C2 JP NZ,Process_Cluster_Entity_Move
E5C5 PUSH HL
E5C6 INC HL
E5C7 CALL Erase_Narrow_Entity_Sprite
E5CA POP HL
E5CB JP Process_Cluster_Entity_Seek
Process_Cluster_Entity_Move E5CE 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.
E5CF INC HL
E5D0 EXX
E5D1 LD HL,$C4D4
E5D4 EXX
E5D5 CALL HitTestBounds8AtHL
E5D8 JP NC,Strip_Attributes_And_Fade
E5DB DEC HL Step back four bytes and stash the entity pointer.
E5DC DEC HL
E5DD DEC HL
E5DE PUSH HL
E5DF DEC HL
E5E0 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.
E5E3 POP HL
E5E4 EXX
E5E5 CALL Find_Colliding_Entity
E5E8 JP C,Apply_Entity_Velocity
E5EB LD DE,$0006
E5EE SBC HL,DE Step back six bytes, erase the entity via Erase_Narrow_Entity_Sprite, score 25 BCD against the six-byte score at C406 and propagate carry.
E5F0 PUSH HL
E5F1 CALL Erase_Narrow_Entity_Sprite
E5F4 POP HL
E5F5 CALL Remove_Entity_From_List_Step
E5F8 LD HL,$C406
E5FB LD A,(HL)
E5FC ADD A,$25
E5FE DAA
E5FF LD (HL),A
E600 JP NC,Process_Cluster_Entity_Bar
E603 LD B,$03
Process_Cluster_Entity_Score_Carry E605 DEC HL Propagate BCD carry through B higher-order score digits.
E606 LD A,(HL)
E607 ADD A,$01
E609 DAA
E60A LD (HL),A
E60B JP NC,Process_Cluster_Entity_Bar
E60E DJNZ Process_Cluster_Entity_Score_Carry
Process_Cluster_Entity_Bar E610 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.
E613 EXX
E614 JP Process_Cluster_Entity_Seek_Y
E617 DEC HL
E618 DEC HL
E619 DEC HL
Process_Cluster_Entity_Seek_Y E61A DEC HL Step back two more bytes to the entity handler field.
E61B DEC HL
Process_Cluster_Entity_Seek E61C LD D,H Load the Y and X position bytes and compute the signed Y offset from the player's Y coordinate at C4D4.
E61D LD E,L
E61E DEC DE
E61F DEC DE
E620 DEC DE
E621 DEC DE
E622 LD A,(DE)
E623 INC A
E624 JP Z,Retire_Cluster_Entity
E627 LD (HL),$37
E629 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.
E62A INC HL
E62B PUSH HL
E62C LD A,(DE)
E62D LD C,A
E62E LD B,$00
E630 LD A,($C4D4)
E633 LD L,A
E634 LD H,$00
E636 AND A
E637 SBC HL,BC
E639 BIT 0,H
E63B LD A,L
E63C JP Z,Process_Cluster_Entity_0
E63F NEG
Process_Cluster_Entity_0 E641 SRL A
E643 SRL A
E645 SRL A
E647 SRL A
E649 BIT 0,H
E64B JP Z,Process_Cluster_Entity_Seek_X
E64E NEG
Process_Cluster_Entity_Seek_X E650 EX AF,AF' Compute the X nudge from the player's X coordinate at C4D5 in the same way.
E651 INC DE
E652 LD A,(DE)
E653 LD C,A
E654 LD B,$00
E656 LD A,($C4D5)
E659 LD L,A
E65A LD H,$00
E65C AND A
E65D SBC HL,BC
E65F BIT 0,H
E661 LD A,L
E662 JP Z,Process_Cluster_Entity_1
E665 NEG
Process_Cluster_Entity_1 E667 SRL A
E669 SRL A
E66B SRL A
E66D SRL A
E66F BIT 0,H
E671 JP Z,Process_Cluster_Entity_2
E674 NEG
Process_Cluster_Entity_2 E676 LD C,A
E677 EX AF,AF'
E678 LD B,A
E679 POP HL
Process_Cluster_Entity_Chase E67A OR C If both nudge components are zero, replace them with a small random drift.
E67B JP NZ,Process_Cluster_Entity_Apply
E67E CALL Generate_Random_Byte
E681 AND $03
E683 SUB $01
E685 LD C,A
E686 CALL Generate_Random_Byte
E689 AND $03
E68B SUB $02
E68D LD B,A
E68E JP Process_Cluster_Entity_Chase
Process_Cluster_Entity_Apply E691 DEC DE Add the Y nudge offset 03 to the Y position; advance DE and HL.
E692 LD A,(DE)
E693 ADD A,$03
E695 LD (HL),A
E696 INC DE Add the X nudge offset 02 to the X position and advance.
E697 INC HL
E698 LD A,(DE)
E699 ADD A,$02
E69B LD (HL),A
E69C INC HL
E69D INC HL
E69E INC HL Write the computed Y and X nudge bytes to the record and stash HL.
E69F LD (HL),B
E6A0 INC HL
E6A1 LD (HL),C
E6A2 PUSH HL
E6A3 LD DE,$0006
E6A6 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.
E6A7 SBC HL,DE
E6A9 EXX
E6AA LD B,$47
E6AC EXX
E6AD CALL Draw_Narrow_Entity_Sprite
E6B0 POP HL
E6B1 INC HL
E6B2 INC HL
E6B3 RET
Prev: E4B9 Up: Map Next: E6B4