Prev: 28997 Up: Map Next: 29118
29028: 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 6 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 29028 LD A,(24086) A=the number of bugs from CurrentBug_ID.
29031 CP 3 Jump to SpawnBug_Delay if there are fewer than three bugs.
29033 JR C,SpawnBug_Delay
29035 LD A,(24119) A=the level from ActivePlayer_Level.
29038 CP 6 Jump to SpawnBug_Delay if the level is 6 or more.
29040 JR NC,SpawnBug_Delay
29042 EX AF,AF' Get the random number back from AF'.
29043 AND %00011111 Keep only bits 0-4 (a one in thirty-two chance).
29045 JR NZ,SpawnBonusItem Jump to SpawnBonusItem unless the result is zero.
29047 LD A,(24086) A=the number of bugs from CurrentBug_ID.
29050 CP 6 Jump to SpawnBonusItem if there are six bugs.
29052 JR NC,SpawnBonusItem
SpawnBug_Delay 29054 LD A,(24098) A=PlayDelay_Counter (the "get ready" delay).
29057 AND A Test the delay.
29058 JR NZ,SpawnBonusItem Jump to SpawnBonusItem if the delay is not over.
29060 LD A,(24087) A=the game timer from GameTimer.
29063 AND %00001111 Keep only bits 0-3.
29065 CP 10 Jump to SpawnBonusItem if it is 10 or more.
29067 JR NC,SpawnBonusItem
29069 LD C,A C=the cubby hole number.
29070 LD B,0 B=0.
29072 LD HL,24099 HL=CubbyHoles.
29075 ADD HL,BC Add the cubby hole number.
29076 LD A,(HL) A=the contents of the cubby hole.
29077 AND A Test the contents.
29078 JR NZ,SpawnBonusItem Jump to SpawnBonusItem if the cubby hole is not empty.
29080 LD A,(24204) A=the state of the flower from State_Flower.
29083 CP 19 Jump to SpawnBonusItem if the flower is blooming.
29085 JR Z,SpawnBonusItem
29087 LD A,C A=the cubby hole number.
29088 LD (24083),A Write it to BugStart_CubbyHole.
29091 LD A,(24172) A=the state of Robbie from State_Robbie_Active.
29094 AND %00111111 Keep only bits 0-5.
29096 DEC A Decrease the state of Robbie by one (zero if he is empty-handed).
29097 JR Z,SpawnBug_FindSlot Jump to SpawnBug_FindSlot if Robbie is empty-handed.
29099 DEC A Decrease the state of Robbie by one again (zero if he is carrying a can).
29100 JR NZ,SpawnBonusItem Jump to SpawnBonusItem unless Robbie is carrying a can.
SpawnBug_FindSlot 29102 LD HL,24244 HL=State_Bugs (the first bug object).
29105 LD B,6 Set the bug counter to 6.
29107 LD DE,8 DE=8 (the size of an object).
SpawnBug_FindSlot_Loop 29110 LD A,(HL) A=the state of the bug.
29111 AND A Test the state.
29112 JP Z,CreateBug Jump to CreateBug if the bug is inactive.
29115 ADD HL,DE Move onto the next bug.
29116 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: 28997 Up: Map Next: 29118