Prev: 56383 Up: Map Next: 56673
56426: Handle Overlap
Used by the routine at TestGroupObjects.
Moves an entity off the overlap whose axis is the smallest of the three held at OverlapDistances. The x axis is handled by HandleOverlapFirst and the y axis by HandleOverlapSecond. On z, a player under a flagged block changes frame, the difference is planted for TestEntityCells, and the vertical speed pushes the entity clear. A saucer sets the high byte of its vertical speed to 2 first.
Input
IX The entity
IY The other entity or object
The smallest overlap chooses the axis. A saucer is pushed up before the choice is made.
HandleOverlap 56426 LD A,(IX+0) A saucer sets its vertical speed.
56429 CP 9
56431 JR NZ,HandleOverlap_Compare
56433 LD (IX+18),2 Set the high byte of the vertical speed to 2.
This entry point is used by the routine at TestEntityPair.
HandleOverlap_Compare 56437 LD A,(56783) Read the x overlap.
56440 LD B,A
56441 LD A,(56785) Compare it with the y overlap.
56444 CP B
56445 JP NC,HandleOverlapFirst Handle x when it is the smaller overlap.
56448 LD B,A Keep the y overlap.
56449 LD A,(56787) Compare it with the z overlap.
56452 CP B
56453 JP NC,HandleOverlapSecond Handle y when it is the smaller overlap.
This entry point is used by the routine at HandleOverlapFirst.
The z overlap is the smallest. A player whose block has the top flag set takes frame 2 and the sides of the block choose the push.
HandleOverlap_Vertical 56456 LD A,(IX+0) Remember the type.
56459 LD (54692),A
56462 DEC A Only the player changes frame.
56463 JR NZ,HandleOverlap_Frame
56465 LD A,(23768) Read the object's flags.
56468 RLA Change the frame when the top flag is set.
56469 JR NC,HandleOverlap_Frame
56471 LD A,(IX+1) Use the top three bits of the frame.
56474 AND 224
56476 OR %00000010 Set the frame number to 2.
56478 LD (IX+1),A Keep that frame.
56481 CALL SetEntitySize Measure the sprite.
HandleOverlap_Frame 56484 BIT 5,(IX+1) Move straight on when bit 5 of the frame is set.
56488 JP NZ,HandleOverlap_Move
56491 LD D,(IX+2) Fetch the x coordinate.
56494 LD E,(IX+3)
56497 LD HL,(55012) Fetch the near x edge.
56500 XOR A Subtract the entity's x from the edge.
56501 INC A
56502 SBC HL,DE
56504 JR Z,HandleOverlap_SizeX The entity is on the edge.
56506 JR NC,HandleOverlap_Push Push back when the entity is past the edge.
HandleOverlap_SizeX 56508 LD A,(IY+2) Scale the object's byte up to a size along x.
56511 ADD A,A
56512 ADD A,A
56513 ADD A,A
56514 ADD A,A
56515 AND %01110000 Use bits 4-6 of that byte.
56517 ADD A,16 Add 16 to make the size.
56519 LD C,A
56520 LD B,0
56522 ADD HL,BC Add the size to the difference.
56523 LD A,L The push stays small when x is still inside the extent.
56524 CP (IX+11)
56527 LD A,2 The small push is 2.
56529 JR C,HandleOverlap_Push Double the push and test y when x is clear.
56531 ADD A,A Double the push.
56532 LD D,(IX+5) Fetch the y coordinate.
56535 LD E,(IX+6)
56538 LD HL,(55029) Subtract the entity's y from the near edge.
56541 SBC HL,DE
56543 JR Z,HandleOverlap_SizeY The entity is on the edge.
56545 JR NC,HandleOverlap_Push Push back when the entity is past the edge.
HandleOverlap_SizeY 56547 LD A,(IY+2) Read the object's byte.
56550 ADD A,A Double that byte.
56551 AND %01110000 Use bits 4-6.
56553 ADD A,16 Add 16 to make the size.
56555 LD C,A
56556 ADD HL,BC Add the size to the difference.
56557 LD A,L The push stays 8 when y is still inside the extent.
56558 CP (IX+12)
56561 LD A,8 The push is 8.
56563 JR NC,HandleOverlap_Move Move the entity when y is clear.
HandleOverlap_Push 56565 LD B,A Keep the push.
56566 LD A,L Read the low byte of the difference.
56567 BIT 7,A Jump to HandleOverlap_Step to keep a negative difference.
56569 JR NZ,HandleOverlap_Step
56571 NEG Force the difference negative.
HandleOverlap_Step 56573 LD (55488),A Give that step to the turn.
56576 LD A,(55357) Read the hit already planted.
56579 AND A A second hit becomes 255.
56580 JR Z,HandleOverlap_Hit
56582 LD B,255 A second hit is 255.
HandleOverlap_Hit 56584 LD A,B Plant the hit for TestEntityCells.
56585 LD (55357),A
A positive z overlap clears the vertical speed. A negative one sets it, and a saucer is left alone. The byte at 56652 is patched by TestGroupObjects: zero clears the low byte of the speed, and 4 skips that clear.
HandleOverlap_Move 56588 LD HL,(56787) Fetch the z overlap.
56591 PUSH IX Remember the entity.
56593 LD DE,6 Move on to the vertical speed.
56596 ADD IX,DE
56598 XOR A Clear the fraction of x.
56599 LD (IX+4),A
56602 BIT 7,H A negative overlap pushes the entity up.
56604 JR NZ,HandleOverlap_0
56606 LD (IX+12),A Clear the vertical speed.
56609 LD (IX+13),A
56612 CALL MoveEntityBack Move the entity back.
56615 JR HandleOverlap_4 Join the restore.
HandleOverlap_0 56617 LD A,(IX-6) A saucer is not pushed up.
56620 CP 9
56622 JR Z,HandleOverlap_2
56624 LD A,(23768) Read the object's flags.
56627 RLA The push is 253 when the top flag is set.
56628 LD A,253
56630 JR C,HandleOverlap_1
56632 INC A Otherwise the push is 255.
56633 INC A
HandleOverlap_1 56634 LD (IX+12),A Use that as the vertical speed.
56637 LD (IX+13),A
HandleOverlap_2 56640 SET 7,(IX+24) Set bit 7 of the vertical speed and clear bit 6.
56644 RES 6,(IX+24)
56648 CALL MoveEntityBack Move the entity back.
HandleOverlap_3 56651 JR HandleOverlap_3 Clear the low byte of the speed when the entity is inside.
56653 LD (IX+25),0 Clear the low byte of the vertical speed.
HandleOverlap_4 56657 POP IX Restore the entity.
56659 LD A,(IX+8) Snap z up when its top byte is zero.
56662 AND A
56663 RET NZ
56664 LD (IX+8),1 Set the top of z to one.
56668 LD (IX+9),0 Clear the middle byte of z.
56672 RET Return.
Prev: 56383 Up: Map Next: 56673