Prev: E11F Up: Map Next: E22D
E12A: Animals Event Timing
Used by the routine at Handler_Animals.
*PlayerBooty starts at 0000 and counts up for every item of booty collected. This means that, the chance that animals appear increases when the player has collected over 100 items (of booty, not treasure - which counts down from 007D).
AnimalsEventTiming E12A LD BC,($5BF4) If the player has collected over 100 items of booty (in *PlayerBooty) then jump to IncreasedFrequencyAnimalsEventTiming.
E12E LD A,C
E12F CP $64
E131 JR NC,IncreasedFrequencyAnimalsEventTiming
E133 LD HL,($5C78) Return if *FRAMES is lower than 0578.
E136 LD DE,$0578
E139 SBC HL,DE
E13B RET C
This entry point is used by the routine at IncreasedFrequencyAnimalsEventTiming.
Use FRAMES as a counter.
StartAnimalsEvent E13C LD HL,$0000 Reset *FRAMES to 0000 to start a new event cycle.
E13F LD ($5C78),HL
Pick a spawn row from TableAnimalSpawnRows.
E142 CALL GetRandomNumber Call GetRandomNumber.
E145 AND %00000011 Ensure the random number is between 00 and 03.
E147 LD HL,$F317 Point HL at that row in TableAnimalSpawnRows.
E14A LD E,A
E14B LD D,$00
E14D ADD HL,DE
E14E PUSH HL Stash the spawn-row pointer on the stack.
E14F INC HL Advance to the next table byte.
E150 LD A,(HL) A=the door-row to match.
Abort if a locked door already sits on that row.
E151 LD IX,($5BDA) IX=*ReferenceKeysAndLockedDoors.
E155 LD B,A B=the door-row to match.
AnimalsEventTiming_ScanDoors E156 LD A,(IX+$00) Jump to AnimalsEventTiming_ChooseSide if this entry is the terminator (FF).
E159 CP $FF
E15B JR Z,AnimalsEventTiming_ChooseSide
E15D LD A,(IX+$01) Jump to AnimalsEventTiming_NextDoor if this door's vertical is not the match row.
E160 CP B
E161 JR NZ,AnimalsEventTiming_NextDoor
E163 LD A,(IX+$05) Jump to AbortAnimalEvent if a key or locked door already occupies this row.
E166 CP $00
E168 JP NZ,AbortAnimalEvent
AnimalsEventTiming_NextDoor E16B LD DE,$0006 Move IX on to the next six-byte door entry.
E16E ADD IX,DE
E170 JR AnimalsEventTiming_ScanDoors Jump to AnimalsEventTiming_ScanDoors.
AnimalsEventTiming_ChooseSide E172 LD IX,$F31C Point IX at TableAnimalAttributes.
Choose whether the animal enters from the left or the right.
E176 CALL GetRandomNumber Call GetRandomNumber.
E179 BIT 3,A Test bit 3 of A.
E17B JR Z,AnimalsEventTiming_EnterFromRight Jump to AnimalsEventTiming_EnterFromRight if the animal should enter from the right.
Enter from the left, moving left.
E17D LD (IX+$00),$02 Write the left-hand column (02) to the horizontal co-ordinate.
E181 LD (IX+$02),$01 Write 01 to the horizontal offset.
E185 LD (IX+$04),$01 Set horizontal movement to left (01).
E189 LD (IX+$05),$00 Clear vertical movement.
E18D LD (IX+$0B),$01 Write 01 to the previous horizontal offset.
E191 LD (IX+$0D),$02 Write 02 to the previous horizontal co-ordinate.
E195 JR AnimalsEventTiming_ChooseSpecies Jump to AnimalsEventTiming_ChooseSpecies.
Enter from the right, moving right.
AnimalsEventTiming_EnterFromRight E197 LD (IX+$00),$25 Write the right-hand column (25) to the horizontal co-ordinate.
E19B LD (IX+$02),$00 Write 00 to the horizontal offset.
E19F LD (IX+$04),$FF Set horizontal movement to right (FF).
E1A3 LD (IX+$05),$00 Clear vertical movement.
E1A7 LD (IX+$0B),$00 Write 00 to the previous horizontal offset.
E1AB LD (IX+$0D),$24 Write 24 to the previous horizontal co-ordinate.
Choose a rat or a bird.
AnimalsEventTiming_ChooseSpecies E1AF CALL GetRandomNumber Call GetRandomNumber.
E1B2 BIT 5,A Test bit 5 of A.
E1B4 JR Z,AnimalsEventTiming_SpawnBird Jump to AnimalsEventTiming_SpawnBird if this should be a bird.
Spawn a rat on the chosen row, but only if that scanline is empty.
E1B6 POP HL Restore the spawn-row pointer from the stack.
E1B7 PUSH HL Stash the spawn-row pointer on the stack.
E1B8 LD A,(HL) Set up the screen buffer location 21/*HL using CL_SET.
E1B9 LD B,A
E1BA LD C,$21
E1BC CALL $0DD9
E1BF LD HL,($5C84) HL=*DF_CC.
E1C2 LD B,$20 B=20 (one character row).
AnimalsEventTiming_CopyScreenLoop E1C4 LD A,(HL) Fetch a screen byte.
E1C5 INC HL Advance the screen pointer.
E1C6 CP $FF Jump to AbortAnimalEvent if this byte is not empty (FF).
E1C8 JP NZ,AbortAnimalEvent
E1CB DJNZ AnimalsEventTiming_CopyScreenLoop Decrease counter by one and loop back to AnimalsEventTiming_CopyScreenLoop until the whole row has been tested.
E1CD POP HL Restore the spawn-row pointer from the stack.
E1CE LD A,(HL) A=the spawn row.
E1CF INC A Increment A by one.
E1D0 LD (IX+$01),A Write it to the animal vertical co-ordinate.
E1D3 LD (IX+$0E),A Write it to the previous vertical co-ordinate.
E1D6 LD (IX+$03),$03 Write 03 to the vertical offset.
E1DA LD (IX+$0F),$03 Write 03 to the previous vertical offset.
E1DE LD (IX+$06),$20 Write the first rat frame (20) to the sprite ID.
E1E2 LD (IX+$09),$03 Write the rat attribute (03).
E1E6 LD (IX+$07),$04 Write the rat width (04).
E1EA LD (IX+$08),$01 Write the rat height (01).
E1EE LD A,$01 Queue the rat sound at SoundFlag_Animal.
E1F0 LD ($FFFF),A
E1F3 LD A,(IX+$04) Return if the animal is moving left.
E1F6 CP $01
E1F8 RET Z
E1F9 LD (IX+$06),$24 Else use the right-facing rat frame (24).
E1FD RET Return.
Spawn a bird three rows below the chosen spawn row.
AnimalsEventTiming_SpawnBird E1FE POP HL Restore the spawn-row pointer from the stack.
E1FF LD A,(HL) A=the spawn row.
E200 INC A Add 03 for the bird's flying height.
E201 INC A
E202 INC A
E203 LD (IX+$01),A Write it to the animal vertical co-ordinate.
E206 LD (IX+$0E),A Write it to the previous vertical co-ordinate.
E209 LD (IX+$03),$03 Write 03 to the vertical offset.
E20D LD (IX+$06),$28 Write the first bird frame (28) to the sprite ID.
E211 LD (IX+$09),$06 Write the bird attribute (06).
E215 LD (IX+$07),$02 Write the bird width (02).
E219 LD (IX+$08),$02 Write the bird height (02).
E21D LD A,$02 Queue the bird sound at SoundFlag_Animal.
E21F LD ($FFFF),A
E222 LD A,(IX+$04) Return if the animal is moving right.
E225 CP $FF
E227 RET Z
E228 LD (IX+$06),$2C Else use the left-facing bird frame (2C).
E22C RET Return.
Prev: E11F Up: Map Next: E22D