Prev: 45722 Up: Map Next: 45806
45765: Calculate Pixel Coordinates
Works out the pixel position of an object on the screen from its x, y and z positions. The pixel x position is x + y - 128 and the pixel y position (from the bottom of the screen) is half of y - x + 128, plus z, less 104, each with the adjustments of the object added. The pixel x position is set to zero if it would be below zero.
Input
IX The address of the object
Output
F The carry flag is set if the sprite is on the screen
Work out the pixel x position.
CalculatePixelCoordinates 45765 LD A,(IX+1) Fetch the x position of the object.
45768 ADD A,(IX+2) Add the y position.
45771 SUB 128 Subtract 128 to centre the room on the screen.
45773 ADD A,(IX+18) Add the horizontal sprite offset.
45776 JR C,CalculatePixelCoordinates_SetX Jump to CalculatePixelCoordinates_SetX if the result is not below zero.
45778 XOR A Set A to 0.
CalculatePixelCoordinates_SetX 45779 LD (IX+26),A Write the screen x co-ordinate of the object.
Work out the pixel y position.
45782 LD A,(IX+2) Fetch the y position of the object.
45785 SUB (IX+1) Subtract the x position.
45788 ADD A,128 Add 128.
45790 SRL A Halve it.
45792 ADD A,(IX+3) Add the height of the object.
45795 SUB 104 Subtract 104 to put the floor at the bottom of the screen.
45797 ADD A,(IX+19) Add the vertical sprite offset.
45800 LD (IX+27),A Write the screen y co-ordinate of the object.
45803 CP 192 Compare it with 192, the number of lines on the screen.
45805 RET Return, with the carry flag set when the sprite is on the screen.
View the equivalent code in;
Prev: 45722 Up: Map Next: 45806