Prev: A213 Up: Map Next: A282
A218: Move Thief
The handler for entity types 50 to 53, the enemies that go after the programs. The enemy heads for the robot, and picks up any program (map cell type 06) that is in the way. If the enemy is shot then it drops the program.
Input
IX Entity
MoveThief A218 CALL NextSpriteNumber Move on to the next sprite using NextSpriteNumber.
A21B CALL RemoveDistantEntity Remove the enemy if it is far away from the camera using RemoveDistantEntity.
A21E CALL GetPosition Fetch the position of the enemy.
A221 LD B,$40 The enemy can take up to 40 steps in this frame.
MoveThief_Step A223 CALL TryMove Take a step using TryMove.
A226 JR NZ,MoveThief_Blocked Jump if the enemy has been blocked by a cell.
A228 CALL CheckEnemyOverlap Check whether another enemy is in the way using CheckEnemyOverlap.
A22B JR C,MoveThief_Reverse Jump if there is.
A22D LD A,E Jump if the enemy is not at the start of a cell.
A22E OR L
A22F JR NZ,MoveThief_Store
A231 CALL FindDirectionToRobot Choose a new direction using FindDirectionToRobot...
A234 LD (IX+$07),A ...and store it.
A237 LD A,B Loop back to take another step if there are steps left.
A238 AND A
A239 JR NZ,MoveThief_Step
MoveThief_Store A23B CALL SetPosition Store the new position of the enemy.
A23E JP AddEntity Draw the enemy using AddEntity.
The enemy has been blocked by a cell.
MoveThief_Blocked A241 PUSH HL Save the Y position.
A242 LD HL,($962E) Fetch the address of the cell that blocked the enemy...
A245 LD A,(HL) ...and its type.
A246 AND $0F Jump unless it is a program (type 06).
A248 CP $06
A24A JR NZ,MoveThief_Skip
A24C LD B,A Keep the type.
A24D LD A,(IX+$08) Fetch the item that the enemy is carrying.
A250 AND A Jump if it is carrying one already.
A251 JR NZ,MoveThief_Skip
A253 CALL EmptyCell Remove the program from the cell using EmptyCell...
A256 POP HL ...after restoring the Y position...
A257 JR MoveThief_Store ...and carry on. (The enemy has picked up the program, and takes it away.)
MoveThief_Skip A259 POP HL Restore the Y position.
A25A LD A,($9615) Fetch the frame counter.
A25D AND $01 Test the lowest bit of the frame counter, and jump on every other frame to choose a direction towards the robot.
A25F JR Z,MoveThief_Towards
A261 LD A,($9617) Otherwise fetch the random number...
A264 AND $03 ...limited to 00-03...
A266 CP (IX+$07) ...and jump unless it is the direction that the enemy is already heading in.
A269 JR NZ,MoveThief_Direction
A26B INC A Otherwise use the next direction.
A26C AND $03
MoveThief_Direction A26E LD (IX+$07),A Store the new direction.
A271 JR MoveThief_Store Carry on.
MoveThief_Towards A273 CALL FindDirectionToRobot Choose a direction towards the robot using FindDirectionToRobot.
A276 JR MoveThief_Direction Carry on.
The enemy is in the way of another enemy.
MoveThief_Reverse A278 CALL ReverseDirection Turn the enemy round using ReverseDirection.
A27B CALL AddEntity Draw the enemy using AddEntity.
A27E RET NC Return if it was not drawn.
A27F JP MakeBumpSound Otherwise make a sound using MakeBumpSound.
Prev: A213 Up: Map Next: A282