Prev: 40430 Up: Map Next: 40570
40501: Test Slope Collision
Used by the routine at CheckTerrainCollision.
Tests whether a box touches an object with a sloping face. Bits 6 and 7 of the byte at offset 4 of the object select one of four ways the slope can face, and the bottom three bits are the steepness. The result is stored in 23580, and when the box does touch the object the depth that it has gone into the slope is stored in 23578. The position of the box comes from 52794 and its size from 52796.
Input
IX Address of the object
TestSlopeCollision 40501 XOR A Clear the result.
40502 LD (23580),A Store it.
40505 LD HL,(52794) Fetch the position of the box.
40508 LD DE,(52796) Fetch the size of the box.
40512 LD A,(IX+4) Fetch the slope flags.
40515 AND %00000111 Keep the steepness.
40517 LD C,A Store it in C.
40518 LD A,(IX+4) Fetch the slope flags again.
40521 AND %11000000 Keep the direction bits.
40523 JR Z,TestSlopeCollision_Down Jump to TestSlopeCollision_Down if both are clear.
40525 CP 64 Jump to TestSlopeCollision_Mirrored if it is the second direction.
40527 JP Z,TestSlopeCollision_Mirrored
40530 CP 128 Jump to TestSlopeCollision_Up if it is the third direction.
40532 JP Z,TestSlopeCollision_Up
40535 CP 192 Jump to TestSlopeCollision_UpMirrored if it is the fourth direction.
40537 JP Z,TestSlopeCollision_UpMirrored
40540 RET Return.
TestSlopeCollision_Down 40541 CALL FindSlopeOverlap Find the overlap with the slope.
This entry point is used by the routine at FindMirroredSlopeOverlap.
TestSlopeCollision_Depth 40544 LD A,(23580) Fetch the result.
40547 AND A Test it.
40548 RET Z Return if the box does not overlap.
40549 DEC A Reduce the result to zero.
40550 LD (23580),A Store it.
40553 LD A,D Fetch the width of the box.
40554 ADD A,L Add the horizontal position.
40555 LD L,A Store it in L.
40556 LD A,(IX+0) Fetch the left edge of the object.
40559 ADD A,B Add the distance up the slope.
40560 SUB L Subtract the right edge of the box.
40561 RET NC Return if the box is clear of the slope.
40562 NEG Make the depth positive.
40564 LD (23578),A Store the depth.
40567 JP SetOverlapFlag Jump to SetOverlapFlag to say that the box touches the slope.
Prev: 40430 Up: Map Next: 40570