Prev: 725A Up: Map Next: 72CC
7262: 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 7262 PUSH HL Stash HL on the stack.
7263 EX DE,HL Switch DE and HL.
7264 LD HL,$5F16 Copy 08 bytes of data from DefaultState_Bug to DE.
7267 LD BC,$0008
726A LDIR
726C POP IX Restore IX from the stack (the old value in HL).
726E LD A,($5E13) A=BugStart_CubbyHole.
7271 CP $05 Jump to CreateBug_Right if the cubby hole is on the right.
7273 JR NC,CreateBug_Right
7275 LD (IX+$01),$08 Write 08 to the X position of the bug.
7279 SET 6,(IX+$00) Set bit 6 of the state of the bug (this has no effect as the state is overwritten at 72AA).
This entry point is used by the routine at CreateBug_Right.
CreateBug_Row 727D RRCA Rotate the row number round so it is in bits 5-7.
727E RRCA
727F RRCA
7280 AND %11100000 Keep only bits 5-7.
7282 ADD A,$37 Add 37.
7284 LD (IX+$02),A Write it to the Y position of the bug.
7287 LD A,($5E37) A=the level from ActivePlayer_Level.
728A CP $01 Jump to CreateBug_Level1 if it is level 01.
728C JR Z,CreateBug_Level1
728E CP $02 Jump to CreateBug_Level2 if it is level 02.
7290 JR Z,CreateBug_Level2
7292 CP $03 Jump to CreateBug_Level3 if it is level 03.
7294 JR Z,CreateBug_Level3
7296 CP $04 Jump to CreateBug_Type if it is a lower level.
7298 JR C,CreateBug_Type
729A 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 729C AND %00000011 Keep only bits 0-1.
729E LD C,A C=A.
729F SLA A Multiply A by two.
72A1 ADD A,C Add C to make it three times the bug type.
72A2 LD C,A C=the offset into the table (three bytes for each type of bug).
72A3 LD B,$00 Clear the high byte of the offset in B.
72A5 LD HL,$72E9 HL=BugTypeTable.
72A8 ADD HL,BC Add the offset.
72A9 LD A,(HL) A=the type of the bug.
72AA LD (IX+$00),A Write it to the state of the bug.
72AD INC HL Move onto the first colour.
72AE LD A,($5E19) A=the random number from RandomNumber.
72B1 BIT 6,A Jump to CreateBug_Colour if bit 6 is not set.
72B3 JR Z,CreateBug_Colour
72B5 INC HL Move onto the second colour.
CreateBug_Colour 72B6 LD A,(HL) A=the colour of the bug.
72B7 LD (IX+$03),A Write it to the colour of the bug.
72BA LD E,$00 E=00 (no collision).
72BC LD HL,$5E6E HL=State_Robbie_Pos_Y (the Y position of Robbie).
72BF CALL BugCollision_Y Check whether the bug is on top of Robbie using BugCollision_Y.
72C2 DEC E Decrease the collision result in E by one (zero means that the bug is on top of Robbie).
72C3 JR NZ,CreateBug_Done Jump to CreateBug_Done if the bug is not on top of Robbie.
72C5 LD (IX+$00),$00 Write 00 to the state of the bug (cancel it).
CreateBug_Done 72C9 JP SpawnBonusItem Jump to SpawnBonusItem.
Prev: 725A Up: Map Next: 72CC