Prev: E122 Up: Map Next: E22A
E1B6: 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 C533; 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 E1B6 LD A,($C533) Skip to Process_Entity_Record_Counter_Up_Next6 if the wave start delay at C533 is still active.
E1B9 AND A
E1BA JP NZ,Process_Entity_Record_Counter_Up_Next6
E1BD PUSH HL Stash the entity record pointer and erase the sprite via Erase_Wide_Entity_Sprite.
E1BE CALL Erase_Wide_Entity_Sprite
E1C1 POP HL
E1C2 INC HL Advance past the entity handler field.
E1C3 EXX Set the player Y position address into alternate HL.
E1C4 LD HL,$C4D4
E1C7 EXX
E1C8 CALL HitTestBounds8AtHL Test whether this entity overlaps the player via HitTestBounds8AtHL.
E1CB JP NC,Strip_Attributes_And_Fade Trigger the death sequence via Strip_Attributes_And_Fade if the entity touches the player.
E1CE DEC HL Step back three bytes to the entity Y position field.
E1CF DEC HL
E1D0 DEC HL
E1D1 CALL Find_Colliding_Wave_Enemy Search the wave entity list for another entity at this position via Find_Colliding_Wave_Enemy.
E1D4 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 F0 or higher, randomise a new type in the range 34-37; otherwise reuse the current entity type.
E1D7 EXX Switch to alternate registers and generate a random value; compare against F0.
E1D8 CALL Generate_Random_Byte
E1DB CP $F0
E1DD JP C,Handle_Horizontal_Enemy_Entity_0 Keep the existing entity type if the random value is below F0.
Handle_Horizontal_Enemy_Entity_Retry E1E0 DEC HL Step back to the entity type byte and generate a new random byte via Generate_Random_Byte.
E1E1 CALL Generate_Random_Byte
E1E4 AND %00000011 Mask to the low 2 bits for the entity type offset.
E1E6 ADD A,$34 Add 34 to form the entity type, write it, and advance.
E1E8 LD (HL),A
E1E9 INC HL
E1EA JP Handle_Horizontal_Enemy_Entity_Apply_Delta Jump to Handle_Horizontal_Enemy_Entity_Apply_Delta.
Handle_Horizontal_Enemy_Entity_0 E1ED DEC HL Load the existing entity type and advance past it.
E1EE LD A,(HL)
E1EF 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 E1F0 EX DE,HL Exchange DE and HL to preserve the entity record pointer.
E1F1 AND %00000011 Mask the entity type to the low 2 bits for the direction index.
E1F3 LD C,A Double the direction index and load the delta table base at Direction_Delta_Table.
E1F4 SLA C
E1F6 LD B,$00
E1F8 LD HL,$E11A
E1FB ADD HL,BC
E1FC EX DE,HL Exchange DE and HL to restore the entity record pointer.
E1FD LD A,(DE) Apply the Y delta to the current Y coordinate; retry via Handle_Horizontal_Enemy_Entity_Retry if the result is outside 10-AA.
E1FE ADD A,(HL)
E1FF CP $AA
E201 JP NC,Handle_Horizontal_Enemy_Entity_Retry
E204 CP $10 Apply the X delta to the current X coordinate; retry via Handle_Horizontal_Enemy_Entity_Retry if the result is outside 08-EB.
E206 JP C,Handle_Horizontal_Enemy_Entity_Retry
E209 LD C,A
E20A INC HL
E20B INC DE Step the delta pointer forward; apply the second delta to X; validate X bounds.
E20C LD A,(DE)
E20D ADD A,(HL)
E20E CP $EB
E210 DEC HL
E211 JP NC,Handle_Horizontal_Enemy_Entity_Retry Write the validated Y and X coordinates back to the entity record.
E214 CP $08
E216 JP C,Handle_Horizontal_Enemy_Entity_Retry
E219 INC HL
E21A LD (HL),A
E21B DEC HL
E21C LD (HL),C
E21D 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.
E21E PUSH HL
E21F EXX
E220 LD B,$44
E222 EXX
E223 CALL Draw_Wide_Entity_Sprite
E226 POP HL Restore the entity record pointer.
E227 JP Process_Entity_Record_Next6 Advance to the next entity record via Process_Entity_Record_Next6.
Prev: E122 Up: Map Next: E22A