Prev: A12D Up: Map Next: A20D
A144: Move Spark
The handler for entity types 3C to 3F, which are the shots that the robot fires using the first weapon. A shot moves across the map until it hits something or has run out of range. The shot destroys the contents of the cell that it hits, apart from the cells that are solid.
Input
IX Entity
MoveSpark A144 CALL NextSpriteNumber Move on to the next sprite using NextSpriteNumber.
A147 CALL GetPosition Fetch the position of the shot.
A14A LD B,$60 The shot can take up to 60 steps in this frame.
MoveSpark_Step A14C CALL TryMove Take a step using TryMove.
A14F JR NZ,MoveSpark_Hit Jump if the shot has hit something.
A151 LD A,E Jump if the shot is not at the start of a cell.
A152 OR L
A153 JR NZ,MoveSpark_Store
A155 LD A,(IX+$07) Fetch the range of the shot...
A158 SUB $10 ...take away one cell...
A15A LD (IX+$07),A ...and store it.
A15D AND $F0 Jump to explode the shot if it has run out of range.
A15F JR Z,MoveSpark_Explode
A161 LD A,B Loop back to take another step if there are steps left.
A162 AND A
A163 JR NZ,MoveSpark_Step
This entry point is used by the routine at MovePellet.
MoveSpark_Store A165 CALL SetPosition Store the new position of the shot.
A168 CALL CheckShotHit Check whether it has hit an enemy using CheckShotHit.
A16B LD A,(IX+$00) Fetch the type of the shot, and draw it using AddEntity unless it has become smoke.
A16E CP $38
A170 JP NZ,AddEntity
A173 LD A,(IY+$08) Fetch the item that the enemy was carrying, and draw the shot if it was not carrying any.
A176 AND A
A177 JP Z,AddEntity
A17A LD C,A Keep the item.
A17B LD HL,($962E) Fetch the address of the cell that the shot was in.
A17E LD A,(HL) Fetch the contents of the cell.
A17F AND $F0 Keep the initial type of the cell and use the item as the current type, so that the enemy drops it.
A181 OR C
A182 LD (HL),A Store the new contents of the cell.
A183 XOR A Clear the item that the enemy was carrying...
A184 LD (IY+$08),A ...and store it.
A187 JP AddEntity Draw the shot using AddEntity.
MoveSpark_Explode A18A LD (IX+$00),$38 Turn the shot into smoke by changing its type to 38.
A18E JR MoveSpark_Store Store the position.
The shot has hit something.
MoveSpark_Hit A190 PUSH DE Save the X position.
A191 LD DE,$0010 Each entity is 10 bytes long.
A194 LD B,$02 There are two entities that are used for puffs of smoke.
A196 LD IY,$98B0 Point IY at CloudEntities.
MoveSpark_FindPuff A19A LD A,(IY+$00) Fetch its type, and jump if it is not being used.
A19D AND A
A19E JR Z,MoveSpark_Unused
A1A0 ADD IY,DE Move on to the next one.
A1A2 DJNZ MoveSpark_FindPuff Loop back until both have been tried.
A1A4 POP DE Restore the X position.
A1A5 JR MoveSpark_Explode Make the shot explode without hitting the cell, as there is no puff to use.
MoveSpark_Unused A1A7 POP DE Restore the X position.
A1A8 PUSH HL Save the Y position.
A1A9 LD HL,($962E) Fetch the address of the cell that was hit.
A1AC LD A,(HL) Fetch its contents.
A1AD AND $0F Keep the current type of the cell.
A1AF CP $05 Jump to explode the shot if the type is 05.
A1B1 JR Z,MoveSpark_Restore
A1B3 CP $04 Jump to explode the shot if the type is 04.
A1B5 JR Z,MoveSpark_Restore
A1B7 CP $01 Jump to explode the shot if the type is 01.
A1B9 JR Z,MoveSpark_Restore
A1BB CP $07 Jump to explode the shot if the type is 07.
A1BD JR Z,MoveSpark_Restore
A1BF CP $08 Jump to explode the shot if the type is 08.
A1C1 JR Z,MoveSpark_Restore
A1C3 CP $09 Jump to explode the shot if the type is 09.
A1C5 JR Z,MoveSpark_Restore
A1C7 CP $0C Jump to explode the shot if the type is 0C.
A1C9 JR Z,MoveSpark_Restore
A1CB CP $0E Jump to explode the shot if the type is 0E.
A1CD JR Z,MoveSpark_Restore
A1CF LD A,(HL) Fetch the contents of the cell again...
A1D0 AND $F0 ...and keep the initial type, so that the cell is emptied.
A1D2 JR MoveSpark_Destroy
MoveSpark_Replace A1D4 LD (HL),A Store the new contents of the cell.
A1D5 LD (IY+$00),$54 Start a puff of smoke...
A1D9 LD HL,($962C) ...at the position of the cell.
A1DC LD (IY+$02),L Set the X cell of the puff...
A1DF LD (IY+$04),H ...and then its Y cell.
MoveSpark_Restore A1E2 POP HL Restore the Y position.
A1E3 JR MoveSpark_Explode Make the shot explode.
MoveSpark_Destroy A1E5 LD C,A Keep the initial type of the cell.
A1E6 LD A,(HL) Fetch the contents of the cell...
A1E7 AND $0F ...and keep its current type.
A1E9 CP $02 Jump to empty the cell if it is not type 02 (an installed program).
A1EB LD A,C
A1EC JR NZ,MoveSpark_Replace
A1EE PUSH AF Save the contents...
A1EF PUSH DE ...and the X position...
A1F0 PUSH HL ...and the Y position.
A1F1 CALL FindSector Find the sector that the cell is in using FindSector.
A1F4 LD E,D Use the sector number as an index.
A1F5 LD D,$00
A1F7 LD HL,$965B Point HL at SectorFlags.
A1FA ADD HL,DE Add the index.
A1FB LD A,(HL) Fetch the flag, and jump if the sector has been activated (as its programs are safe).
A1FC AND A
A1FD JR NZ,MoveSpark_Safe
A1FF CALL ReduceSectorEnergy Otherwise take one unit of energy off the sector using ReduceSectorEnergy.
A202 POP HL Restore the Y position...
A203 POP DE ...and the X position...
A204 POP AF ...and the contents.
A205 JR MoveSpark_Replace Jump back to empty the cell.
MoveSpark_Safe A207 POP HL Restore the Y position...
A208 POP DE ...and the X position...
A209 POP AF ...and the contents.
A20A LD A,(HL) Fetch the contents of the cell, which are left as they are.
A20B JR MoveSpark_Replace Jump back to start the puff of smoke.
Prev: A12D Up: Map Next: A20D