Prev: 26145 Up: Map Next: 26243
26155: Handler: Worm Collection and Delivery
Used by the routine at Run_Game_Frame.
Manages the worm collectibles in each room. Scans the room attribute data to find active worm tiles, animates them with a wiggling effect, and checks if Percy is at the correct position to pick one up. When Percy is carrying a worm, the worm-in-beak sprite is positioned relative to Percy. On level 6 checks if Percy is at the nest to deliver the worm to the baby chicks for bonus points.
Calculate Percy's tile map position from his pixel coordinates.
Handler_Worms 26155 LD IX,56000 Point IX at Percy_X_Position.
26159 LD B,8 Set B to 8.
26161 LD A,(IX+1) Calculate the tile row from Percy's Y position: add 8 rotate left twice and mask with 224 to get the row component in E.
26164 ADD A,B
26165 RLCA
26166 RLCA
26167 AND %11100000
26169 LD E,A
26170 LD A,(IX+0) Calculate the tile column from Percy's X position: add 2 rotate right three times and mask with 31 then OR with the row component to form the full tile map offset in E.
26173 INC A
26174 INC A
26175 RRCA
26176 RRCA
26177 RRCA
26178 AND %00011111
26180 OR E
26181 LD E,A
26182 LD A,(24485) If *PercyFacingDirection (facing direction) is zero (facing right), increment E by one to adjust the lookup position.
26185 OR A
26186 JR NZ,Scan_Worms
26188 INC E Increment the map offset by one.
Scan the room attribute entries to find active worm tiles.
Scan_Worms 26189 LD HL,(24501) Load the room attribute pointer from *Room_Object_Data_Pointer into HL.
26192 LD A,(24497) Load the worm count from *CurrentLevel, increment it by one and store it in C.
26195 INC A
26196 LD C,A
Scan_Worms_Loop 26197 LD A,(HL) Jump to Skip_Collected_Worm if the current entry is 30 (worm already collected).
26198 CP 30
26200 JR Z,Skip_Collected_Worm
26202 INC HL Advance past the type byte.
26203 LD A,(HL) Jump to Skip_Disabled_Worm if the next byte is 31 (the slot is disabled).
26204 CP 31
26206 JR Z,Skip_Disabled_Worm
26208 INC HL Advance.
26209 LD A,(HL) Compare the entry index against C; jump to Skip_Invalid_Entry if it is greater or equal (not a valid worm).
26210 INC HL
26211 CP C
26212 JR NC,Skip_Invalid_Entry
26214 LD A,(HL) Jump to Handler_Worm_Found if the tile position matches E (worm found at Percy's location).
26215 CP E
26216 JR Z,Handler_Worm_Found
This entry point is used by the routine at Handler_Worm_Found.
No match at this entry; draw the worm wiggle animation at this tile position and move to the next entry.
Animate_Worm 26218 PUSH HL Stash the room attribute pointer, worm counter and position on the stack.
26219 PUSH BC
26220 PUSH DE
26221 LD L,(HL) Load the tile screen address low byte from *HL; set high byte to 240 to form a screen buffer address.
26222 LD H,240
26224 CALL Handler_DrawWorm Call Handler_DrawWorm to draw the worm wiggle animation frame.
26227 POP DE Restore the position, worm counter and room attribute pointer from the stack.
26228 POP BC
26229 POP HL
This entry point is used by the routine at Handler_Worm_Found.
Next_Worm_Entry 26230 INC HL Advance to the next entry and loop back to Scan_Worms_Loop until all 8 entries are checked.
26231 DJNZ Scan_Worms_Loop
26233 JR Position_Worm_In_Beak Jump to Position_Worm_In_Beak.
Skip entries that are marked as collected or disabled.
Skip_Collected_Worm 26235 INC HL Skip one extra byte for collected entries.
Skip_Disabled_Worm 26236 INC HL Skip the remaining bytes of this entry.
26237 INC HL
Skip_Invalid_Entry 26238 INC HL Advance past this entry and loop back to Scan_Worms_Loop until all entries are checked.
26239 DJNZ Scan_Worms_Loop
26241 JR Position_Worm_In_Beak Jump to Position_Worm_In_Beak.
Prev: 26145 Up: Map Next: 26243