Prev: AA89 Up: Map Next: AB1F
AAA1: Handle Clockwork Mouse
The update routine for the clockwork mouse (objects 74 to 77), which is deadly to touch. It runs along one axis for a random number of passes in IX+10, or until it hits something. Then it chooses a new random speed and turns through a right angle, alternating between the x and y axes. The sprite number says which way it faces, and the flip flag says which axis it uses.
Input
IX The address of the object
Move the mouse, or choose a new direction.
HandleClockworkMouse AAA1 CALL SetPixelAdjustments_Mouse Call SetPixelAdjustments_Mouse.
AAA4 CALL ApplyGravityAndMove Call ApplyGravityAndMove.
AAA7 LD A,(IX+$09) Jump to HandleClockworkMouse_ChooseDirection if the mouse is not moving.
AAAA OR (IX+$0A)
AAAD JR Z,HandleClockworkMouse_ChooseDirection
AAAF LD A,(IX+$0C) Fetch the collision flags.
AAB2 AND %00000011 Keep bits 0 and 1.
AAB4 JR NZ,HandleClockworkMouse_ChooseDirection Jump to HandleClockworkMouse_ChooseDirection if the mouse has hit something.
AAB6 DEC (IX+$10) Count down the remaining passes.
AAB9 JR Z,HandleClockworkMouse_ChooseDirection Jump to HandleClockworkMouse_ChooseDirection if they have run out.
Animate the mouse and redraw it.
HandleClockworkMouse_Animate AABB CALL ToggleSpriteNumber Call ToggleSpriteNumber.
AABE JP SetDeadlyFlagsAndDraw Jump to SetDeadlyFlagsAndDraw.
Choose a new direction.
HandleClockworkMouse_ChooseDirection AAC1 CALL PlayHighBeep Call PlayHighBeep.
AAC4 LD A,($5B03) Fetch 5B03.
AAC7 LD C,A Keep it in C.
AAC8 LD A,($5B05) Fetch RandomSeed2.
AACB XOR C Combine the two.
AACC AND %00001111 Keep bits 0 to 3.
AACE LD (IX+$10),A Set the remaining passes.
AAD1 LD A,(IX+$07) Fetch the flags of the mouse.
AAD4 XOR %01000000 Flip bit 6.
AAD6 LD (IX+$07),A Store the flags.
AAD9 LD A,($5B05) Fetch RandomSeed2.
AADC AND %00000001 Keep bit 0.
AADE JR Z,HandleClockworkMouse_CheckFlippedForward Jump to HandleClockworkMouse_CheckFlippedForward if it is zero.
AAE0 BIT 6,(IX+$07) Jump to HandleClockworkMouse_ChooseSpeed if the mouse is not flipped.
AAE4 JR Z,HandleClockworkMouse_ChooseSpeed
Turn the mouse round.
HandleClockworkMouse_TurnRound AAE6 LD A,(IX+$00) Fetch the sprite number.
AAE9 XOR %00000010 Flip bit 1.
AAEB LD (IX+$00),A Store the sprite number.
Choose a speed of 02 to 05.
HandleClockworkMouse_ChooseSpeed AAEE LD A,($5B02) Fetch FrameCounter.
AAF1 AND %00000011 Keep bits 0 and 1.
AAF3 ADD A,$02 Add 02.
AAF5 BIT 1,(IX+$00) Jump to HandleClockworkMouse_CheckFlipped if the mouse is facing forwards.
AAF9 JR NZ,HandleClockworkMouse_CheckFlipped
AAFB NEG Make the speed negative.
HandleClockworkMouse_CheckFlipped AAFD BIT 6,(IX+$07) Jump to HandleClockworkMouse_NegativeSpeed if the mouse is flipped.
AB01 JR NZ,HandleClockworkMouse_NegativeSpeed
AB03 LD (IX+$09),A Set the speed along the x axis.
AB06 LD (IX+$0A),$00 Write 00 as the speed along the y axis.
AB0A JR HandleClockworkMouse_Animate Jump to HandleClockworkMouse_Animate.
HandleClockworkMouse_CheckFlippedForward AB0C BIT 6,(IX+$07) Jump to HandleClockworkMouse_TurnRound if the mouse is not flipped.
AB10 JR Z,HandleClockworkMouse_TurnRound
AB12 JR HandleClockworkMouse_ChooseSpeed Jump to HandleClockworkMouse_ChooseSpeed.
HandleClockworkMouse_NegativeSpeed AB14 NEG Make the speed negative.
AB16 LD (IX+$0A),A Set the speed along the y axis.
AB19 LD (IX+$09),$00 Write 00 as the speed along the x axis.
AB1D JR HandleClockworkMouse_Animate Jump to HandleClockworkMouse_Animate.
Prev: AA89 Up: Map Next: AB1F