Prev: 54185 Up: Map Next: 54394
54251: Test Entity Collisions
Used by the routine at MoveEntity.
Tests the entity against each of the other entities with TestEntityPair. A puff and a shot are not tested. A player skips puffs and sparkles, and a saucer skips shots. A disc, a free slot and a hidden entity are skipped. The direction bytes are 32 during the tests. Afterwards the low bytes of x and y, relative to the patched origins, replace them for TestEntityCells. The step in MoveEntityBack is removed for the tests and then put back.
Input
IX The entity
The direction bytes start at 32 so a hit during the tests has a neutral component. The type of this entity is patched into the skip below.
TestEntityCollisions 54251 LD A,4 Mark the entity as only touching.
54253 LD (56652),A
54256 LD A,(IX+0) Remember this entity's type for the skips below.
54259 LD (54303),A
54262 CP 5 A puff is not tested against the others.
54264 JR Z,TestEntityCollisions_Finish
54266 CP 14 A shot is not tested against the others.
54268 JR Z,TestEntityCollisions_Finish
54270 LD (IX+24),32 Set both direction bytes to 32.
54274 LD (IX+25),32
54278 XOR A Clear the object flags and remove the move-back step.
54279 LD (56804),A
54282 LD (23768),A
54285 LD B,12 There are 12 entities.
54287 LD IY,46400 Start at the first entity.
TestEntityCollisions_Loop 54291 PUSH BC Remember how many entities remain.
54292 LD A,(IY+0) Skip an entity that is free.
54295 AND A
54296 JR Z,TestEntityCollisions_Next
54298 CP 12 Skip a disc.
54300 JR Z,TestEntityCollisions_Next
54302 LD A,0 The type patched above selects the next skips.
54304 LD L,A
54305 DEC A
54306 JR NZ,TestEntityCollisions_Saucer A player does not test a puff or a sparkle.
54308 LD A,(IY+0)
54311 CP 5
54313 JR Z,TestEntityCollisions_Next
54315 CP 13
54317 JR Z,TestEntityCollisions_Next
TestEntityCollisions_Saucer 54319 LD A,L A saucer does not test a shot.
54320 CP 9
54322 JR NZ,TestEntityCollisions_Frame
54324 LD A,(IY+0) Skip the shot.
54327 CP 14
54329 JR Z,TestEntityCollisions_Next
TestEntityCollisions_Frame 54331 LD A,(IY+1) Read the other entity's frame.
54334 AND %11000000 Use bits 6 and 7 of the frame.
54336 JR NZ,TestEntityCollisions_Next Skip an entity with either bit set.
54338 PUSH IY It is not tested against itself.
54340 POP HL
54341 PUSH IX
54343 POP DE
54344 AND A Test the pair when the two entities differ.
54345 SBC HL,DE
54347 CALL NZ,TestEntityPair
TestEntityCollisions_Next 54350 LD BC,38 Move on to the next entity.
54353 ADD IY,BC
54355 POP BC Bring the count back.
54356 DJNZ TestEntityCollisions_Loop Repeat for the remaining entities.
TestEntityCollisions_Finish 54358 LD DE,0 Keep the low byte of x relative to the patched origin.
54361 LD H,(IX+2)
54364 LD L,(IX+3)
54367 AND A
54368 SBC HL,DE
54370 LD (IX+24),L
54373 LD DE,0 Keep the low byte of y relative to the patched origin.
54376 LD H,(IX+5)
54379 LD L,(IX+6)
54382 AND A
54383 SBC HL,DE
54385 LD (IX+25),L
54388 LD A,45 Put the step back into the move-back routine.
54390 LD (56804),A
54393 RET Return.
Prev: 54185 Up: Map Next: 54394