Prev: 57642 Up: Map Next: 58123
57901: Handler: Animals
Used by the routine at InitialiseGame.
Moves, animates and collides the live animal at TableAnimalAttributes. If the slot is empty, AnimalsEventTiming may spawn one.
Handler_Animals 57901 LD IX,62236 Point IX at TableAnimalAttributes.
57905 LD A,(IX+0) Jump to AnimalsEventTiming if no animal is active.
57908 CP 0
57910 JP Z,AnimalsEventTiming
Point the UDG graphics at the animal frames.
57913 LD HL,37708 Write 37708 to *CHARS.
57916 LD (23606),HL
57919 CALL ApplyMovementDeltas Apply the animal's movement deltas.
57922 LD (IX+0),C Write the new horizontal co-ordinate back to the slot.
57925 LD (IX+1),B Write the new vertical co-ordinate back to the slot.
57928 LD (IX+2),E Write the new horizontal offset back to the slot.
57931 LD (IX+3),D Write the new vertical offset back to the slot.
Erase the previous animal when it crosses a character boundary.
57934 LD A,E Jump to Handler_Animals_TestLeaveOrHit if the horizontal offset is not 3.
57935 CP 3
57937 JR NZ,Handler_Animals_TestLeaveOrHit
57939 LD A,(IX+4) Jump to Handler_Animals_MoveRight if the animal is moving right.
57942 CP 255
57944 JR Z,Handler_Animals_MoveRight
57946 LD A,C A=the new horizontal co-ordinate.
57947 SUB (IX+7) Subtract the animal width.
57950 CP 2 Jump to Handler_Animals_TestLeaveOrHit if that column is off the left of the play area.
57952 JR C,Handler_Animals_TestLeaveOrHit
57954 CP 34 Jump to Handler_Animals_TestLeaveOrHit if that column is off the right of the play area.
57956 JR NC,Handler_Animals_TestLeaveOrHit
57958 LD C,A C=the trail column to erase.
57959 LD E,1 E=1 (one character wide).
57961 LD D,(IX+8) D=the animal height.
57964 CALL PrintSpriteUpdateBuffer Erase the previous animal from the room buffer.
57967 JR Handler_Animals_TestLeaveOrHit Jump to Handler_Animals_TestLeaveOrHit.
Handler_Animals_MoveRight 57969 INC C Step the trail column one to the right.
57970 LD A,C Jump to Handler_Animals_TestLeaveOrHit if that column is off the right of the play area.
57971 CP 34
57973 JR NC,Handler_Animals_TestLeaveOrHit
57975 CP 2 Jump to Handler_Animals_TestLeaveOrHit if that column is off the left of the play area.
57977 JR C,Handler_Animals_TestLeaveOrHit
57979 LD E,1 E=1 (one character wide).
57981 LD D,(IX+8) D=the animal height.
57984 CALL PrintSpriteUpdateBuffer Erase the previous animal from the room buffer.
Leave the screen, or animate and test a hit on the player.
Handler_Animals_TestLeaveOrHit 57987 LD A,(IX+0) Jump to Handler_Animals_ClearSlot if the animal has walked off the right.
57990 CP 38
57992 JP Z,Handler_Animals_ClearSlot
57995 CP 1 Jump to Handler_Animals_ClearSlot if the animal has walked off the left.
57997 JP Z,Handler_Animals_ClearSlot
58000 LD A,(IX+6) Jump to Handler_Animals_StoreFrame if this is still a rat frame (below 37).
58003 CP 37
58005 JR C,Handler_Animals_StoreFrame
58007 ADD A,8 Advance the bird animation by one frame.
58009 CP 71 Jump to Handler_Animals_StoreFrame if the bird frames have not wrapped.
58011 JR C,Handler_Animals_StoreFrame
58013 SUB 32 Wrap back to the first bird frame.
Handler_Animals_StoreFrame 58015 LD (IX+6),A Write the new frame ID back to the slot.
58018 CALL PrintShiftedSprite Print the animal.
58021 LD A,(IX+0) Copy the horizontal co-ordinate to the previous-horizontal slot.
58024 LD (IX+13),A
58027 LD A,(IX+1) Copy the vertical co-ordinate to the previous-vertical slot.
58030 LD (IX+14),A
58033 LD A,(IX+2) Copy the horizontal offset to the previous-offset slot.
58036 LD (IX+11),A
58039 LD A,(IX+3) Copy the vertical offset to the previous-vertical-offset slot.
58042 LD (IX+15),A
Test whether the animal overlaps the player.
58045 LD A,(IX+8) A=the animal height.
58048 ADD A,3 Add 3 for the player's height.
58050 LD C,A C=the combined height.
58051 LD B,(IX+1) B=the animal vertical co-ordinate.
58054 LD A,(62002) A=the player's vertical co-ordinate.
58057 DEC A Decrease A by one.
58058 ADD A,(IX+8) Add the animal height.
58061 SUB B Subtract the animal vertical co-ordinate.
58062 CP C Return if the player is outside the animal's vertical span.
58063 RET NC
58064 LD A,(IX+7) A=the animal width.
58067 ADD A,2 Add 2.
58069 SLA A Convert that width into a pixel span.
58071 SLA A
58073 LD B,A B=the pixel width to test.
58074 LD C,(IX+0) C=the animal horizontal co-ordinate.
58077 LD A,(62003) D=the player's horizontal offset.
58080 LD D,A
58081 LD A,C A=the animal horizontal co-ordinate.
58082 SLA A Convert it to a pixel column.
58084 SLA A
58086 ADD A,(IX+2) Add the animal's horizontal offset.
58089 LD C,A
58090 LD A,(62001) A=the player's horizontal co-ordinate.
58093 ADD A,(IX+7) Add the animal width.
58096 SLA A Shift A left (with carry).
58098 SLA A Shift A left (with carry).
58100 ADD A,D Add the player's horizontal offset.
58101 DEC A Decrease A by one.
58102 SUB C Subtract the animal's pixel column.
58103 CP B Return if the player is outside the animal's horizontal span.
58104 RET NC
58105 LD A,1 Queue the "touched by animal" sound at SoundFlag_General.
58107 LD (65534),A
58110 JP LoseLife Jump to LoseLife to lose a life.
The animal has left the room; clear the slot.
Handler_Animals_ClearSlot 58113 LD (IX+0),0 Clear *TableAnimalAttributes; no animal is active.
58117 LD A,0 Stop the animal sound at SoundFlag_Animal.
58119 LD (65535),A
58122 RET Return.
Prev: 57642 Up: Map Next: 58123