Prev: 29274 Up: Map Next: 29388
29282: Create Bug
Used by the routine at SpawnBug.
Creates a new bug in an inactive bug object, at the cubby hole whose number is in BugStart_CubbyHole. The type and the colour are chosen using the level, and the random number (see BugTypeTable). The bug is cancelled if Robbie is too close to it.
Input
HL The inactive bug object
CreateBug 29282 PUSH HL Stash HL on the stack.
29283 EX DE,HL Switch DE and HL.
29284 LD HL,24342 Copy 8 bytes of data from DefaultState_Bug to DE.
29287 LD BC,8
29290 LDIR
29292 POP IX Restore IX from the stack (the old value in HL).
29294 LD A,(24083) A=BugStart_CubbyHole.
29297 CP 5 Jump to CreateBug_Right if the cubby hole is on the right.
29299 JR NC,CreateBug_Right
29301 LD (IX+1),8 Write 8 to the X position of the bug.
29305 SET 6,(IX+0) Set bit 6 of the state of the bug (this has no effect as the state is overwritten at 29354).
This entry point is used by the routine at CreateBug_Right.
CreateBug_Row 29309 RRCA Rotate the row number round so it is in bits 5-7.
29310 RRCA
29311 RRCA
29312 AND %11100000 Keep only bits 5-7.
29314 ADD A,55 Add 55.
29316 LD (IX+2),A Write it to the Y position of the bug.
29319 LD A,(24119) A=the level from ActivePlayer_Level.
29322 CP 1 Jump to CreateBug_Level1 if it is level 1.
29324 JR Z,CreateBug_Level1
29326 CP 2 Jump to CreateBug_Level2 if it is level 2.
29328 JR Z,CreateBug_Level2
29330 CP 3 Jump to CreateBug_Level3 if it is level 3.
29332 JR Z,CreateBug_Level3
29334 CP 4 Jump to CreateBug_Type if it is a lower level.
29336 JR C,CreateBug_Type
29338 LD A,R A=the refresh register.
This entry point is used by the routines at CreateBug_Level1, CreateBug_Level2 and CreateBug_Level3.
CreateBug_Type 29340 AND %00000011 Keep only bits 0-1.
29342 LD C,A C=A.
29343 SLA A Multiply A by two.
29345 ADD A,C Add C to make it three times the bug type.
29346 LD C,A C=the offset into the table (three bytes for each type of bug).
29347 LD B,0 Clear the high byte of the offset in B.
29349 LD HL,29417 HL=BugTypeTable.
29352 ADD HL,BC Add the offset.
29353 LD A,(HL) A=the type of the bug.
29354 LD (IX+0),A Write it to the state of the bug.
29357 INC HL Move onto the first colour.
29358 LD A,(24089) A=the random number from RandomNumber.
29361 BIT 6,A Jump to CreateBug_Colour if bit 6 is not set.
29363 JR Z,CreateBug_Colour
29365 INC HL Move onto the second colour.
CreateBug_Colour 29366 LD A,(HL) A=the colour of the bug.
29367 LD (IX+3),A Write it to the colour of the bug.
29370 LD E,0 E=0 (no collision).
29372 LD HL,24174 HL=State_Robbie_Pos_Y (the Y position of Robbie).
29375 CALL BugCollision_Y Check whether the bug is on top of Robbie using BugCollision_Y.
29378 DEC E Decrease the collision result in E by one (zero means that the bug is on top of Robbie).
29379 JR NZ,CreateBug_Done Jump to CreateBug_Done if the bug is not on top of Robbie.
29381 LD (IX+0),0 Write 0 to the state of the bug (cancel it).
CreateBug_Done 29385 JP SpawnBonusItem Jump to SpawnBonusItem.
Prev: 29274 Up: Map Next: 29388