Prev: 7508 Up: Map Next: 7574
7512: Handler: Cat
Controls the cat hazard that patrols horizontally along a platform. The cat bounces between left and right boundaries, animates through walking frames, and checks for collision with Percy and Percy's egg. The cat parameters vary per room, looked up from state data indexed by the current room number.
Input
IX Pointer to the cat sprite data
Set up the cat state pointer and movement parameters.
Handler_Cat 7512 LD IY,$7AC8 Point IY at Cat_State_Data.
7516 LD HL,$7589 Point HL at Cat_Direction_Flag.
Sprite ID Sprite
39 udg45627-56x4
7519 LD BC,$0739 Set B=07 (sprite active value) and C=39 (base cat frame).
This entry point is used by the routine at Handler_Dog.
Calculate_Hazard_Room_Offset 751C LD A,($5FC5) Calculate the state data offset: (*CurrentRoom - 01) * 04 and add to IY to point at this room's cat state entry.
751F DEC A
7520 ADD A,A
7521 ADD A,A
7522 LD E,A
7523 LD D,$00
7525 ADD IY,DE
This entry point is used by the routine at Handler_Walking_Paratrooper.
Cat_Entry 7527 LD A,($5FBB) Call Reset_Cat_Position if *RespawnFlag is set to reset the cat position.
752A OR A
752B CALL NZ,Reset_Cat_Position
752E BIT 7,(IY+$00) Jump to Animate_Stunned_Hazard if bit 7 of *IY+00 is set (cat is stunned by egg).
7532 JR NZ,Animate_Stunned_Hazard
Determine movement direction and update X position.
7534 LD A,(HL) Load the direction byte from *HL; test bit 7.
7535 BIT 7,A
7537 INC HL Advance HL to the step size byte.
7538 JR NZ,Cat_Moving_Left Jump to Cat_Moving_Left if bit 7 is set (moving left).
Moving right: add the step size to the X position.
753A LD A,(IX+$00) Load the cat X position from *IX+00.
753D ADD A,(HL) Add the step size from *HL.
753E CP (IY+$03) Compare with the right boundary at *IY+03.
7541 DEC HL Move HL back to the direction byte.
7542 JR C,Cat_Update_X_Right Jump to Cat_Update_X_Right if the X position hasn't reached the right boundary.
7544 LD A,$80 Write 80 to *HL to switch direction to moving left.
7546 LD (HL),A
7547 JR Update_Cat_Frame Jump to Update_Cat_Frame.
Cat_Update_X_Right 7549 LD (IX+$00),A Write the updated X position to *IX+00.
754C JR Update_Cat_Frame Jump to Update_Cat_Frame.
Moving left: subtract the step size from the X position.
Cat_Moving_Left 754E LD A,(IX+$00) Load the cat X position from *IX+00.
7551 SUB (HL) Subtract the step size from *HL.
7552 CP (IY+$02) Compare with the left boundary at *IY+02.
7555 DEC HL Move HL back to the direction byte.
7556 JR NC,Cat_Update_X_Left Jump to Cat_Update_X_Left if the X position hasn't reached the left boundary.
7558 XOR A Write 00 to *HL to switch direction to moving right.
7559 LD (HL),A
755A JR Update_Cat_Frame Jump to Update_Cat_Frame.
Cat_Update_X_Left 755C LD (IX+$00),A Write the updated X position to *IX+00.
This entry point is used by the routine at Handler_Walking_Paratrooper.
Update the cat's walking animation frame and check for collisions.
Update_Cat_Frame 755F DEC HL Move HL back to the animation counter.
7560 LD A,(HL) Increment the animation counter, wrapping at 07.
7561 INC A
7562 AND %00000111
7564 LD (HL),A
7565 RRA Divide by two.
7566 ADD A,C Add the base frame from C.
7567 INC HL Advance HL to the direction byte.
7568 BIT 7,(HL) Skip to Set_Hazard_Frame if bit 7 of *HL is unset (moving right).
756A JR Z,Set_Hazard_Frame
756C ADD A,$04 Add 04 for the left-facing frame set.
Set_Hazard_Frame 756E LD (IX+$03),A Write the sprite frame to *IX+03.
7571 JP Check_Hazard_Collision Jump to Check_Hazard_Collision to check for collision with Percy or egg.
Prev: 7508 Up: Map Next: 7574