Prev: C5BB Up: Map Next: C63D
C5CE: Spawn Item
Used by the routine at StartGame.
Every sixteen frames, when the player is standing on a kind of tile that still has items to give, makes an item appear at the player's position. The item is placed in the first free one of the four objects from ObjectTable_Items, at a random position within the cell. The number of items that are left for each kind of tile is held in the table at ItemsLeft.
Wait until it is time to spawn an item.
SpawnItem C5CE LD A,($BC02) Return if the player is still materialising.
C5D1 CP $70
C5D3 RET NZ
C5D4 LD A,($BBB2) Return unless the frame counter is a multiple of sixteen.
C5D7 AND $0F
C5D9 RET NZ
C5DA LD IY,$BCCE Start with the first of the four item objects, set the distance from one object to the next (10 bytes) and set a counter for the four items.
C5DE LD DE,$0010
C5E1 LD B,$04
Find a free item object.
SpawnItem_Find C5E3 LD A,(IY+$00) Jump to SpawnItem_Spawn if this item object is free.
C5E6 AND A
C5E7 JR Z,SpawnItem_Spawn
C5E9 ADD IY,DE Move on to the next item object and loop back until all four have been tried, and then return.
C5EB DJNZ SpawnItem_Find
C5ED RET
Place the item in the player's cell, if the tile still has items left.
SpawnItem_Spawn C5EE LD A,($BC90) Fetch the column and row of the player's cell.
C5F1 LD L,A
C5F2 LD A,($BC92)
C5F5 LD H,A
C5F6 LD E,L
C5F7 LD D,H
C5F8 CALL FindMapTile Find out what kind of tile is in the cell.
C5FB LD C,A Fetch the number of items that are left for this kind of tile, and return if there are none.
C5FC LD B,$00
C5FE LD HL,$BBCE
C601 ADD HL,BC
C602 LD A,(HL)
C603 AND A
C604 RET Z
C605 DEC (HL) Take one from the number of items that are left.
C606 LD (IY+$02),E Set the column and row of the item to those of the player's cell, and the tile to the kind of tile.
C609 LD (IY+$04),D
C60C LD (IY+$05),C
C60F LD A,C Choose the type of the item (30, 34, 38 or 3C) from the kind of tile.
C610 AND $03
C612 ADD A,A
C613 ADD A,A
C614 OR $30
C616 LD (IY+$00),A Make the object an item.
C619 LD HL,($BBAA) Put the item at a random place along the X axis of the cell.
C61C LD A,L
C61D AND $7F
C61F ADD A,$40
C621 LD (IY+$01),A
C624 LD A,H Put the item at a random place along the Y axis of the cell.
C625 AND $7F
C627 ADD A,$40
C629 LD (IY+$03),A
C62C LD A,$08 Make the item eight units wide and deep.
C62E LD (IY+$08),A
C631 LD (IY+$09),A
C634 LD (IY+$0C),$F8 Set the drawing offsets of the item to F8 and 04.
C638 LD (IY+$0D),$04
C63C RET Return.
Prev: C5BB Up: Map Next: C63D