Prev: 7145 Up: Map Next: 71BE
7164: Spawn Bug
Decides whether to add a new bug to the play area. A bug is added when all of the following are true:
  • there are fewer than three bugs, or the level is 06 or more, or there are fewer than six bugs and the low five bits of the random number are zero (a one in thirty-two chance);
  • the "get ready" delay is over;
  • the cubby hole picked by the game timer (one of the first ten) is empty;
  • the flower is not blooming;
  • Robbie is alive;
  • there is an inactive bug object.
The cubby hole is where the new bug starts. If a bug is not added then this carries on at SpawnBonusItem.
SpawnBug 7164 LD A,($5E16) A=the number of bugs from CurrentBug_ID.
7167 CP $03 Jump to SpawnBug_Delay if there are fewer than three bugs.
7169 JR C,SpawnBug_Delay
716B LD A,($5E37) A=the level from ActivePlayer_Level.
716E CP $06 Jump to SpawnBug_Delay if the level is 06 or more.
7170 JR NC,SpawnBug_Delay
7172 EX AF,AF' Get the random number back from AF'.
7173 AND %00011111 Keep only bits 0-4 (a one in thirty-two chance).
7175 JR NZ,SpawnBonusItem Jump to SpawnBonusItem unless the result is zero.
7177 LD A,($5E16) A=the number of bugs from CurrentBug_ID.
717A CP $06 Jump to SpawnBonusItem if there are six bugs.
717C JR NC,SpawnBonusItem
SpawnBug_Delay 717E LD A,($5E22) A=PlayDelay_Counter (the "get ready" delay).
7181 AND A Test the delay.
7182 JR NZ,SpawnBonusItem Jump to SpawnBonusItem if the delay is not over.
7184 LD A,($5E17) A=the game timer from GameTimer.
7187 AND %00001111 Keep only bits 0-3.
7189 CP $0A Jump to SpawnBonusItem if it is 0A or more.
718B JR NC,SpawnBonusItem
718D LD C,A C=the cubby hole number.
718E LD B,$00 B=00.
7190 LD HL,$5E23 HL=CubbyHoles.
7193 ADD HL,BC Add the cubby hole number.
7194 LD A,(HL) A=the contents of the cubby hole.
7195 AND A Test the contents.
7196 JR NZ,SpawnBonusItem Jump to SpawnBonusItem if the cubby hole is not empty.
7198 LD A,($5E8C) A=the state of the flower from State_Flower.
719B CP $13 Jump to SpawnBonusItem if the flower is blooming.
719D JR Z,SpawnBonusItem
719F LD A,C A=the cubby hole number.
71A0 LD ($5E13),A Write it to BugStart_CubbyHole.
71A3 LD A,($5E6C) A=the state of Robbie from State_Robbie_Active.
71A6 AND %00111111 Keep only bits 0-5.
71A8 DEC A Decrease the state of Robbie by one (zero if he is empty-handed).
71A9 JR Z,SpawnBug_FindSlot Jump to SpawnBug_FindSlot if Robbie is empty-handed.
71AB DEC A Decrease the state of Robbie by one again (zero if he is carrying a can).
71AC JR NZ,SpawnBonusItem Jump to SpawnBonusItem unless Robbie is carrying a can.
SpawnBug_FindSlot 71AE LD HL,$5EB4 HL=State_Bugs (the first bug object).
71B1 LD B,$06 Set the bug counter to 06.
71B3 LD DE,$0008 DE=08 (the size of an object).
SpawnBug_FindSlot_Loop 71B6 LD A,(HL) A=the state of the bug.
71B7 AND A Test the state.
71B8 JP Z,CreateBug Jump to CreateBug if the bug is inactive.
71BB ADD HL,DE Move onto the next bug.
71BC DJNZ SpawnBug_FindSlot_Loop Decrease the bug counter by one and loop back to SpawnBug_FindSlot_Loop until all six bug slots have been checked.
Prev: 7145 Up: Map Next: 71BE