Prev: 57634 Up: Map Next: 57898
57782: Handle Horizontal Enemy Entity
Per-frame entity handler for the horizontal-moving wave enemy, written into entity records by Spawn_Horizontal_Wave_Enemies. Checks the wave start delay at 50483; if still counting, skips forward via Process_Entity_Record_Counter_Up_Next6. Otherwise erases the sprite, tests player contact via HitTestBounds8AtHL (triggering death via Strip_Attributes_And_Fade if touching), searches the wave enemy list for a collision partner via Find_Colliding_Wave_Enemy, and repositions the entity by applying a directional delta from the table at Direction_Delta_Table. Spawns the entity at its new position via Draw_Wide_Entity_Sprite and advances the entity record pointer via Process_Entity_Record_Next6.
Handle_Horizontal_Enemy_Entity 57782 LD A,(50483) Skip to Process_Entity_Record_Counter_Up_Next6 if the wave start delay at 50483 is still active.
57785 AND A
57786 JP NZ,Process_Entity_Record_Counter_Up_Next6
57789 PUSH HL Stash the entity record pointer and erase the sprite via Erase_Wide_Entity_Sprite.
57790 CALL Erase_Wide_Entity_Sprite
57793 POP HL
57794 INC HL Advance past the entity handler field.
57795 EXX Set the player Y position address into alternate HL.
57796 LD HL,50388
57799 EXX
57800 CALL HitTestBounds8AtHL Test whether this entity overlaps the player via HitTestBounds8AtHL.
57803 JP NC,Strip_Attributes_And_Fade Trigger the death sequence via Strip_Attributes_And_Fade if the entity touches the player.
57806 DEC HL Step back three bytes to the entity Y position field.
57807 DEC HL
57808 DEC HL
57809 CALL Find_Colliding_Wave_Enemy Search the wave entity list for another entity at this position via Find_Colliding_Wave_Enemy.
57812 CALL NC,Begin_Enemy_Death_Animation Begin the death animation via Begin_Enemy_Death_Animation if a collision was found.
Decide whether to pick a new entity type or keep the existing one: if a random value is 240 or higher, randomise a new type in the range 52-55; otherwise reuse the current entity type.
57815 EXX Switch to alternate registers and generate a random value; compare against 240.
57816 CALL Generate_Random_Byte
57819 CP 240
57821 JP C,Handle_Horizontal_Enemy_Entity_0 Keep the existing entity type if the random value is below 240.
Handle_Horizontal_Enemy_Entity_Retry 57824 DEC HL Step back to the entity type byte and generate a new random byte via Generate_Random_Byte.
57825 CALL Generate_Random_Byte
57828 AND %00000011 Mask to the low 2 bits for the entity type offset.
57830 ADD A,52 Add 52 to form the entity type, write it, and advance.
57832 LD (HL),A
57833 INC HL
57834 JP Handle_Horizontal_Enemy_Entity_Apply_Delta Jump to Handle_Horizontal_Enemy_Entity_Apply_Delta.
Handle_Horizontal_Enemy_Entity_0 57837 DEC HL Load the existing entity type and advance past it.
57838 LD A,(HL)
57839 INC HL
Apply the directional delta from the table to the entity Y and X position. Retry if the new position falls outside the play area.
Handle_Horizontal_Enemy_Entity_Apply_Delta 57840 EX DE,HL Exchange DE and HL to preserve the entity record pointer.
57841 AND %00000011 Mask the entity type to the low 2 bits for the direction index.
57843 LD C,A Double the direction index and load the delta table base at Direction_Delta_Table.
57844 SLA C
57846 LD B,0
57848 LD HL,57626
57851 ADD HL,BC
57852 EX DE,HL Exchange DE and HL to restore the entity record pointer.
57853 LD A,(DE) Apply the Y delta to the current Y coordinate; retry via Handle_Horizontal_Enemy_Entity_Retry if the result is outside 16-170.
57854 ADD A,(HL)
57855 CP 170
57857 JP NC,Handle_Horizontal_Enemy_Entity_Retry
57860 CP 16 Apply the X delta to the current X coordinate; retry via Handle_Horizontal_Enemy_Entity_Retry if the result is outside 8-235.
57862 JP C,Handle_Horizontal_Enemy_Entity_Retry
57865 LD C,A
57866 INC HL
57867 INC DE Step the delta pointer forward; apply the second delta to X; validate X bounds.
57868 LD A,(DE)
57869 ADD A,(HL)
57870 CP 235
57872 DEC HL
57873 JP NC,Handle_Horizontal_Enemy_Entity_Retry Write the validated Y and X coordinates back to the entity record.
57876 CP 8
57878 JP C,Handle_Horizontal_Enemy_Entity_Retry
57881 INC HL
57882 LD (HL),A
57883 DEC HL
57884 LD (HL),C
57885 DEC HL Stash the record pointer, set colour INK: GREEN, PAPER: BLACK (BRIGHT) , spawn the entity via Draw_Wide_Entity_Sprite, and restore the pointer.
57886 PUSH HL
57887 EXX
57888 LD B,68
57890 EXX
57891 CALL Draw_Wide_Entity_Sprite
57894 POP HL Restore the entity record pointer.
57895 JP Process_Entity_Record_Next6 Advance to the next entity record via Process_Entity_Record_Next6.
Prev: 57634 Up: Map Next: 57898