Prev: A3C5 Up: Map Next: A41A
A3E0: Handler: Choose Nastie
Handles a nastie which has finished appearing (sprite ID 06) by choosing which type of nastie it is going to be. The types are held in SpriteReference. At the start of the game only the first eight types are possible, but each amulet piece which has been collected makes two more types possible.
Input
IX Nastie record
Count off the nastie if it is not in the same room as the player.
HandlerChooseNastie A3E0 LD A,($9703) Fetch the room of the player from 9703.
A3E3 CP (IX+$01) Jump to ExpireActor if the nastie is in a different room to the player.
A3E6 JP NZ,ExpireActor
A3E9 CALL StoreEntity Remember the previous position of the nastie.
Count the amulet pieces which have been collected.
A3EC LD A,($970D) Fetch the amulet pieces collected from 970D.
A3EF LD C,$00 Clear the number of amulet pieces collected in C.
A3F1 LD B,$04 Set the amulet piece counter in B to 04.
HandlerChooseNastie_Loop A3F3 RRCA Rotate the flag for the next amulet piece into the carry flag.
A3F4 JR NC,HandlerChooseNastie_Next Jump to HandlerChooseNastie_Next if the amulet piece has not been collected.
A3F6 INC C Count the amulet piece.
HandlerChooseNastie_Next A3F7 DJNZ HandlerChooseNastie_Loop Decrease the amulet piece counter by one and loop back to HandlerChooseNastie_Loop until all four pieces have been checked.
Work out how many types of nastie are possible: 08 plus twice the number of pieces collected.
A3F9 SLA C Double the number of amulet pieces collected.
A3FB LD A,C Copy it to A.
A3FC ADD A,$08 Add 08.
A3FE LD C,A Stash the number of nastie types possible in C.
Choose a type at random, using the counter. If it is not one of the types which are possible then use only the first eight.
A3FF LD A,($9693) Fetch the low byte of the game timer from GameTimer.
A402 AND %00001111 Keep only bits 0-3.
A404 CP C Jump to HandlerChooseNastie_Type if the type is possible.
A405 JR C,HandlerChooseNastie_Type
A407 AND %00000111 Keep only bits 0-2.
HandlerChooseNastie_Type A409 LD C,A Stash the type in C.
A40A LD B,$00 Clear B.
A40C LD HL,$A41A Point HL at the table of nastie types at SpriteReference.
A40F ADD HL,BC Add the type to get the address of the sprite ID.
A410 LD A,(HL) Fetch the sprite ID for the type.
A411 LD (IX+$00),A Set the sprite ID of the nastie.
A414 CALL ChooseVelocity Choose a velocity for the nastie.
A417 JP DisplayActor Jump to DisplayActor to display the nastie.
Prev: A3C5 Up: Map Next: A41A