Prev: 54251 Up: Map Next: 54701
54394: Test Entity Pair
Used by the routine at TestEntityCollisions.
Tests whether two entities overlap on x, then y, then z, using TestOverlap. The three extents are fields 11 12 and 13. The y test and the z test move IX so that those extents sit at the displacement the test reads. An overlap is stored at OverlapDistances for x, 56785 for y and 56787 for z. A puff with no width flags then scores, from the table at ScoreTable, and becomes a sparkle. A whirler meeting the player, a spider and a shot all burst. A shot is then removed. A pickup is collected with CollectItem, and the player is moved clear with HandleOverlap_Compare.
Input
IX The entity that is being moved
IY The other entity
TestEntityPair 54394 LD H,(IY+2) Fetch the other entity's x coordinate.
54397 LD L,(IY+3)
54400 LD D,(IX+2) Fetch this entity's x coordinate.
54403 LD E,(IX+3)
54406 LD C,(IY+11) Fetch the other entity's x extent.
54409 LD B,(IX+11) Fetch this entity's x extent.
54412 CALL TestOverlap Test the two x ranges.
54415 RET NC Return if the x ranges do not overlap.
54416 INC L Remember the x overlap.
54417 LD (56783),HL
54420 LD H,(IY+5) Fetch the other entity's y coordinate.
54423 LD L,(IY+6)
54426 LD D,(IX+5) Fetch this entity's y coordinate.
54429 LD E,(IX+6)
54432 LD C,(IY+12) Fetch the other entity's y extent.
54435 LD B,(IX+12) Fetch this entity's y extent.
54438 INC IX Aim the test at the y extent.
54440 CALL TestOverlap Test the two y ranges.
54443 DEC IX Restore the entity address.
54445 RET NC Return if the y ranges do not overlap.
54446 INC L Remember the y overlap.
54447 LD (56785),HL
54450 LD H,(IY+8) Fetch the other entity's z coordinate.
54453 LD L,(IY+9)
54456 LD D,(IX+8) Fetch this entity's z coordinate.
54459 LD E,(IX+9)
54462 PUSH IX Aim the test at the z extent.
54464 LD BC,65530
54467 ADD IX,BC
54469 LD C,(IY+13) Fetch the other entity's z extent.
54472 LD B,(IX+19) Fetch this entity's z extent.
54475 CALL TestOverlap Test the two z ranges.
54478 POP IX Restore the entity address.
54480 RET NC Return if the z ranges do not overlap.
54481 INC L Remember the z overlap.
54482 LD (56787),HL
A puff whose width flags are clear scores and becomes a sparkle.
54485 LD A,(IY+22) Leave this reward unless the width flags are clear.
54488 AND 240
54490 JR NZ,TestEntityPair_0
54492 LD A,(IY+0) Score only when the other entity is a puff.
54495 CP 5
54497 JR NZ,TestEntityPair_0
54499 LD A,(IX+0) Use this entity's type as an index into the score table.
54502 ADD A,A
54503 LD HL,54715 Take the score table.
54506 CALL AddToAddress Look the score up.
54509 LD B,(HL) Read the score.
54510 INC HL
54511 LD C,(HL)
54512 CALL AddScore Add the score.
54515 CALL StartBurst Start a burst.
54518 LD (IY+0),13 Turn the puff into a sparkle.
54522 LD (IY+1),0 Clear the sparkle's frame.
54526 LD (IY+23),8 Set the sparkle's height to 8.
54530 LD (IY+35),4 Set the sparkle's countdown to 4.
Nothing else happens while the countdown timer is running. The other entity is in IY.
TestEntityPair_0 54534 LD A,(41695) Return while the countdown timer is running.
54537 AND A
54538 RET NZ
54539 LD A,(IY+22) Read the other entity's width byte.
54542 AND %11110000 Use the countdown nibble.
54544 JR NZ,TestEntityPair_Spider Skip the whirler test when that nibble is set.
54546 LD A,(IY+0) Read the other entity's type.
54549 DEC A The other entity is the player.
54550 JR NZ,TestEntityPair_Whirler
54552 LD A,(IX+0) A whirler bursts the player.
54555 CP 17
54557 JR NZ,TestEntityPair_Spider
54559 JR TestEntityPair_Burst Burst them.
TestEntityPair_Whirler 54561 CP 16 The other entity is a whirler.
54563 JR NZ,TestEntityPair_Spider
54565 LD A,(IX+0) This entity is the player.
54568 DEC A
54569 JR NZ,TestEntityPair_Spider Leave the pair when it is not.
TestEntityPair_Burst 54571 CALL StartBurst Burst the other entity.
54574 CALL BurstOtherEntity Finish bursting it.
TestEntityPair_Spider 54577 LD A,(IY+0) A spider bursts.
54580 CP 16
54582 CALL Z,StartBurst
54585 LD A,(IY+0) A shot bursts and is removed.
54588 CP 14
54590 JR NZ,TestEntityPair_Pickup
54592 CALL StartBurst Burst the shot.
54595 LD (IY+0),0 Remove the shot.
54599 LD (IY+1),128 Hide what remains of it.
TestEntityPair_Pickup 54603 LD A,(IY+0) A pickup is collected.
54606 CP 15
54608 CALL Z,CollectItem
54611 LD A,(IX+0) The player is moved clear of the overlap.
54614 DEC A
54615 JP Z,HandleOverlap_Compare
54618 CP 14 A shot is collected from the other side.
54620 JR NZ,TestEntityPair_Clear
54622 PUSH IY Swap the two entities.
54624 PUSH IX
54626 POP IY
54628 POP IX
54630 CALL CollectItem Collect the item.
54633 PUSH IY Swap the two entities back.
54635 PUSH IX
54637 POP IY
54639 POP IX
TestEntityPair_Clear 54641 XOR A Clear the handled flag.
54642 LD (54692),A
54645 LD HL,(56787) Reduce the z overlap by one.
54648 DEC L
54649 LD (56787),HL
54652 LD HL,(56783) Reduce the x overlap by two.
54655 DEC L
54656 DEC L
54657 LD (56783),HL
54660 LD HL,(56785) Reduce the y overlap by two.
54663 DEC L
54664 DEC L
54665 LD (56785),HL
54668 LD C,(IX+31) Remember the flags and field 31.
54671 LD B,(IX+30)
54674 PUSH BC
54675 CALL HandleOverlap_Compare Move the entity clear of the overlap.
54678 POP BC Bring the saved values back.
54679 LD (IX+31),C Restore field 31.
54682 LD A,B Use bit 6 of the saved flags.
54683 AND 64
54685 OR (IX+30) Keep that bit in the flags.
54688 LD (IX+30),A
54691 LD A,0 Return unless the patched kind is 11.
54693 CP 11
54695 RET NZ
54696 LD A,(IY+0) Return unless the other entity is the player.
54699 DEC A
54700 RET NZ
Continue on to BurstOtherEntity.
Prev: 54251 Up: Map Next: 54701