Prev: 29960 Up: Map Next: 30068
29970: 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 29970 LD IY,31432 Point IY at Cat_State_Data.
29974 LD HL,30089 Point HL at Cat_Direction_Flag.
Sprite ID Sprite
57 udg45627-56x4
29977 LD BC,1849 Set B=7 (sprite active value) and C=57 (base cat frame).
This entry point is used by the routine at Handler_Dog.
Calculate_Hazard_Room_Offset 29980 LD A,(24517) Calculate the state data offset: (*CurrentRoom - 1) * 4 and add to IY to point at this room's cat state entry.
29983 DEC A
29984 ADD A,A
29985 ADD A,A
29986 LD E,A
29987 LD D,0
29989 ADD IY,DE
This entry point is used by the routine at Handler_Walking_Paratrooper.
Cat_Entry 29991 LD A,(24507) Call Reset_Cat_Position if *RespawnFlag is set to reset the cat position.
29994 OR A
29995 CALL NZ,Reset_Cat_Position
29998 BIT 7,(IY+0) Jump to Animate_Stunned_Hazard if bit 7 of *IY+0 is set (cat is stunned by egg).
30002 JR NZ,Animate_Stunned_Hazard
Determine movement direction and update X position.
30004 LD A,(HL) Load the direction byte from *HL; test bit 7.
30005 BIT 7,A
30007 INC HL Advance HL to the step size byte.
30008 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.
30010 LD A,(IX+0) Load the cat X position from *IX+0.
30013 ADD A,(HL) Add the step size from *HL.
30014 CP (IY+3) Compare with the right boundary at *IY+3.
30017 DEC HL Move HL back to the direction byte.
30018 JR C,Cat_Update_X_Right Jump to Cat_Update_X_Right if the X position hasn't reached the right boundary.
30020 LD A,128 Write 128 to *HL to switch direction to moving left.
30022 LD (HL),A
30023 JR Update_Cat_Frame Jump to Update_Cat_Frame.
Cat_Update_X_Right 30025 LD (IX+0),A Write the updated X position to *IX+0.
30028 JR Update_Cat_Frame Jump to Update_Cat_Frame.
Moving left: subtract the step size from the X position.
Cat_Moving_Left 30030 LD A,(IX+0) Load the cat X position from *IX+0.
30033 SUB (HL) Subtract the step size from *HL.
30034 CP (IY+2) Compare with the left boundary at *IY+2.
30037 DEC HL Move HL back to the direction byte.
30038 JR NC,Cat_Update_X_Left Jump to Cat_Update_X_Left if the X position hasn't reached the left boundary.
30040 XOR A Write 0 to *HL to switch direction to moving right.
30041 LD (HL),A
30042 JR Update_Cat_Frame Jump to Update_Cat_Frame.
Cat_Update_X_Left 30044 LD (IX+0),A Write the updated X position to *IX+0.
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 30047 DEC HL Move HL back to the animation counter.
30048 LD A,(HL) Increment the animation counter, wrapping at 7.
30049 INC A
30050 AND %00000111
30052 LD (HL),A
30053 RRA Divide by two.
30054 ADD A,C Add the base frame from C.
30055 INC HL Advance HL to the direction byte.
30056 BIT 7,(HL) Skip to Set_Hazard_Frame if bit 7 of *HL is unset (moving right).
30058 JR Z,Set_Hazard_Frame
30060 ADD A,4 Add 4 for the left-facing frame set.
Set_Hazard_Frame 30062 LD (IX+3),A Write the sprite frame to *IX+3.
30065 JP Check_Hazard_Collision Jump to Check_Hazard_Collision to check for collision with Percy or egg.
Prev: 29960 Up: Map Next: 30068