Prev: 71A3 Up: Map Next: 7279
71D8: Create Actor
Used by the routine at NextActor.
Creates a new actor from the pantry, if the conditions are right. It is not done if six or more actors are in play, if the delay at the start of a life is running, if no more ingredients are needed, or if Charlie is not in his normal form (ID 01 or 02). It is also done on average only one pass in every 20 which is decided with the frame counter and a random number. The new actor is made from the template at Template_NewActor, in the first of the six slots from ActorSpawnSlots which is empty. It starts at the right, at the height of the shelf in the pantry for the level (2F 47 5F 77 or 8F).
Usually it is the ingredient for the level (see IntroductionIngredients), but it is one of the nasties (the tack, the washer or the bolt) if the number of slots which are left (including this one) is not more than the set the level is in (up to a maximum of 04) plus one. So there are more nasties in the later sets of levels. The monster is also created by CreateMonster, if it is not already.
CreateActor 71D8 LD A,($5F1B) Fetch the number of actors in play.
71DB CP $06 Jump to CreateActor_Finished if there are six actors in play.
71DD JR NC,CreateActor_Finished
71DF LD A,($5F1D) Fetch the frame counter and keep it in B.
71E2 LD B,A
71E3 LD A,R Fetch a random number.
71E5 ADD A,B Add the frame counter.
71E6 AND %00011111 Keep only bits 0-4.
71E8 JR NZ,CreateActor_Finished Jump to CreateActor_Finished if the result is not zero.
71EA LD A,($5F25) Fetch the game delay timer.
71ED AND A Is the delay at the start of a life still running?
71EE JR NZ,CreateActor_Finished Jump to CreateActor_Finished if it is.
71F0 LD A,($5F2F) Fetch the number of ingredients which the active player needs.
71F3 AND A Are any more ingredients needed?
71F4 JR Z,CreateActor_Finished Jump to CreateActor_Finished if not.
71F6 LD A,($5F35) Fetch Charlie's ID.
71F9 AND %00111111 Keep only bits 0-5.
71FB DEC A Is Charlie's ID 01?
71FC JR Z,CreateActor_FindSlot Jump to CreateActor_FindSlot if Charlie's ID is 01.
71FE DEC A Is Charlie's ID 02?
71FF JR NZ,CreateActor_Finished Jump to CreateActor_Finished if Charlie's ID is not 02.
Find the first empty slot out of the six.
CreateActor_FindSlot 7201 LD HL,$5F55 Point HL at the first slot for spawned actors.
7204 LD B,$06 Set the slot counter to 06 (the number of slots).
7206 LD DE,$0008 Set the size of an actor to 08.
CreateActor_FindSlotLoop 7209 LD A,(HL) Fetch the actor ID.
720A AND A Is the slot empty?
720B JP Z,CreateActor_Create Jump to CreateActor_Create if it is.
720E ADD HL,DE Move on to the next slot.
720F DJNZ CreateActor_FindSlotLoop Decrease the slot counter by one and loop back to CreateActor_FindSlotLoop until all of the slots have been tried.
CreateActor_Finished 7211 JP MainLoop_NewPass Jump to MainLoop_NewPass.
Make the new actor from the template.
CreateActor_Create 7214 EX DE,HL Point DE at the empty slot.
7215 LD HL,$7279 Point HL at Template_NewActor.
7218 PUSH BC Save the slot counter on the stack.
7219 LD BC,$0008 Set the number of bytes to copy to 08.
721C PUSH DE Save the address of the slot on the stack.
721D LDIR Copy the template into the slot.
721F POP IX Point IX at the new actor.
7221 LD A,$08 A=08.
7223 LD (IX+$00),A Update the actor ID.
Work out the height of the shelf in the pantry for the level; it is 2F + ((18 * the level within the set) AND 78).
7226 LD A,($5F2D) Fetch the level of the active player.
7229 AND %00000111 Keep only bits 0-2.
722B LD C,A Keep the level within the set in C.
722C SLA A Multiply the level within the set by two.
722E ADD A,C Add the level within the set, to multiply it by three.
722F RLA Rotate left three times, to multiply it by eight.
7230 RLA
7231 RLA
7232 AND %01111000 Keep only bits 3-6.
7234 ADD A,$2F Add 2F to get the height of the shelf.
7236 LD (IX+$02),A Set the vertical co-ordinate to the height of the shelf.
Use the ID and the colour of the ingredient for the level.
7239 LD HL,$6D7D Point HL at IntroductionIngredients.
723C SLA C Multiply the level within the set by two.
723E LD B,$00 Set the high byte of the offset to 00.
7240 ADD HL,BC Find the ingredient for the level.
7241 LD A,(HL) Fetch the sprite ID of the ingredient.
7242 LD (IX+$00),A Update the actor ID.
7245 INC HL Move on to the colour.
7246 LD A,(HL) Fetch the colour of the ingredient.
7247 LD (IX+$03),A Update the actor colour.
Decide whether to make it one of the nasties.
724A LD A,($5F2D) Fetch the level of the active player.
724D SRL A Divide the level by eight, to get the set of levels.
724F SRL A
7251 SRL A
7253 POP BC Restore the slot counter from the stack.
7254 CP $04 Jump to CreateActor_TestNasty if the set is less than 04.
7256 JR C,CreateActor_TestNasty
7258 LD A,$04 Limit the set to 04.
CreateActor_TestNasty 725A INC A Add 01.
725B SUB B Subtract the slot counter.
725C JP M,CreateActor_Draw Jump to CreateActor_Draw if this is an ingredient.
725F LD A,R Fetch a random number.
7261 AND %00000011 Keep only bits 0-1.
7263 JR NZ,CreateActor_Nasty Jump to CreateActor_Nasty if the result is not zero.
7265 INC A Increase A by one, so it is in the range 01 to 03.
CreateActor_Nasty 7266 SLA A Multiply the result by two.
7268 ADD A,$1C Add 1C to get the ID of the tack (1E), the washer (20) or the bolt (22).
726A LD (IX+$00),A Update the actor ID.
726D LD (IX+$03),$45 Set the actor colour to 45 (cyan).
CreateActor_Draw 7271 CALL DrawEntity Draw the actor using DrawEntity.
7274 CALL CreateMonster Create the monster using CreateMonster.
7277 JR CreateActor_Finished Jump to CreateActor_Finished.
Prev: 71A3 Up: Map Next: 7279