Prev: D74C Up: Map Next: D7D8
D76C: Spawn Bonus
Used by the routine at StartGame.
Makes a bonus appear near the player, in the object at ObjectTable_Bonus, if there is not one already. The bonus is a speed bonus (type 02) or a health bonus (type 03), depending on the frame counter. It is placed in a cell that is not solid and is at least two cells from the player, at a random place within the cell.
Return if a bonus is already there.
SpawnBonus D76C LD IX,$BD0E Use the object for the bonus.
D770 LD A,(IX+$00) Return if there is a bonus already.
D773 AND A
D774 RET NZ
Choose a cell that is not solid and not too close.
D775 CALL RandomNumber Update the random number generator.
D778 LD A,($BC90) Fetch the column and the row of the player's cell.
D77B LD L,A
D77C LD A,($BC92)
D77F LD H,A
D780 LD A,($BBAA) Choose a column that is the same as the player's, or four on, from the random seed.
D783 AND $07
D785 AND $FC
D787 ADD A,L Add the choice to the column, and keep it within the village.
D788 AND $1F
D78A LD L,A
D78B LD (IX+$02),A Set the column of the bonus.
D78E LD A,($BBAB) Choose a row from four back to three on, using the second random seed.
D791 AND $07
D793 ADD A,$FC
D795 ADD A,H
D796 LD H,A Add the choice to the row, and set the row of the bonus.
D797 AND $1F
D799 LD (IX+$04),A
D79C CALL FindMapTile Find the tile of the cell.
D79F DEC A Return if the tile is solid (01 or 02).
D7A0 CP $02
D7A2 RET C
D7A3 LD C,$02 Set the distance to two cells.
D7A5 CALL CheckPlayerClose
D7A8 RET C Check whether the cell is closer to the player than that, and return if it is.
Place the bonus in the cell.
D7A9 LD A,($BBB2) Make the type of the bonus 02 or 03, from the frame counter, and set it.
D7AC AND $01
D7AE OR $02
D7B0 LD (IX+$00),A
D7B3 LD A,($BBAA) Set the position of the bonus along the X axis within the cell to a random place.
D7B6 AND $7F
D7B8 ADD A,$40
D7BA LD (IX+$01),A
D7BD LD A,($BBAB) Set the position of the bonus along the Y axis within the cell to a random place.
D7C0 AND $7F
D7C2 ADD A,$40
D7C4 LD (IX+$03),A
D7C7 LD (IX+$08),$10 Set the width of the bonus to 10.
D7CB LD (IX+$09),$10 Set the depth of the bonus to 10.
D7CF LD (IX+$0C),$F4 Set the X offset of the sprite.
D7D3 LD (IX+$0D),$04 Set the Y offset of the sprite.
D7D7 RET Return.
Prev: D74C Up: Map Next: D7D8