Prev: 50577 Up: Map Next: 50691
50632: Handle Ghost
Handles the graphic numbers 80 to 83, which are a ghost. The ghost moves in a straight line until it hits something, or does not move at all, and then it picks a new direction at random: its speed in X and in Y is 3 or 4, in either direction. The graphic of the ghost shows the way it moves, and is changed between its two frames each time. The ghost is deadly.
Input
IX Address of the ghost object
HandleGhost 50632 CALL SetPixelAdjustments_Legs Set the pixel adjustments of the bottom half of a guard.
50635 CALL ApplyGravityAndMove Apply gravity to the ghost and move it.
50638 LD A,(IX+9) Fetch the speed in X.
50641 OR (IX+10) Combine it with the speed in Y.
50644 JR Z,HandleGhost_NewDirection Jump to HandleGhost_NewDirection if the ghost is not moving.
50646 LD A,(IX+12) Fetch the flags that say what the ghost has hit.
50649 AND %00000011 Keep the bits for X and Y.
50651 JR Z,HandleGhost_Draw Jump to HandleGhost_Draw if the ghost has not hit anything.
Choose a new direction.
HandleGhost_NewDirection 50653 LD A,(23461) Fetch the second random seed from RandomSeed2.
50656 AND %00000011 Keep the lowest two bits.
50658 ADD A,4 Add 4, to get a number from 4 to 7.
50660 CALL LookUpGhostSpeed Look up the speed.
50663 LD (IX+9),A Set the speed in X.
50666 LD A,(23458) Fetch the frame counter from FrameCounter.
50669 AND %00000011 Keep the lowest two bits.
50671 ADD A,4 Add 4, to get a number from 4 to 7.
50673 CALL LookUpGhostSpeed Look up the speed.
50676 LD (IX+10),A Set the speed in Y.
50679 CALL SetGhostDirectionGraphic Choose the graphic of the ghost from its direction.
50682 CALL PlaySoundFromPosition Play the sound of a moving object.
HandleGhost_Draw 50685 CALL ToggleGraphic Toggle the graphic of the ghost between its two frames.
50688 JP SetDeadlyFlagsAndDraw Make the ghost deadly and flag it to be drawn again.
Prev: 50577 Up: Map Next: 50691