Prev: 55116 Up: Map Next: 55256
55148: 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 2) or a health bonus (type 3), 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 55148 LD IX,48398 Use the object for the bonus.
55152 LD A,(IX+0) Return if there is a bonus already.
55155 AND A
55156 RET NZ
Choose a cell that is not solid and not too close.
55157 CALL RandomNumber Update the random number generator.
55160 LD A,(48272) Fetch the column and the row of the player's cell.
55163 LD L,A
55164 LD A,(48274)
55167 LD H,A
55168 LD A,(48042) Choose a column that is the same as the player's, or four on, from the random seed.
55171 AND 7
55173 AND 252
55175 ADD A,L Add the choice to the column, and keep it within the village.
55176 AND 31
55178 LD L,A
55179 LD (IX+2),A Set the column of the bonus.
55182 LD A,(48043) Choose a row from four back to three on, using the second random seed.
55185 AND 7
55187 ADD A,252
55189 ADD A,H
55190 LD H,A Add the choice to the row, and set the row of the bonus.
55191 AND 31
55193 LD (IX+4),A
55196 CALL FindMapTile Find the tile of the cell.
55199 DEC A Return if the tile is solid (1 or 2).
55200 CP 2
55202 RET C
55203 LD C,2 Set the distance to two cells.
55205 CALL CheckPlayerClose
55208 RET C Check whether the cell is closer to the player than that, and return if it is.
Place the bonus in the cell.
55209 LD A,(48050) Make the type of the bonus 2 or 3, from the frame counter, and set it.
55212 AND 1
55214 OR 2
55216 LD (IX+0),A
55219 LD A,(48042) Set the position of the bonus along the X axis within the cell to a random place.
55222 AND 127
55224 ADD A,64
55226 LD (IX+1),A
55229 LD A,(48043) Set the position of the bonus along the Y axis within the cell to a random place.
55232 AND 127
55234 ADD A,64
55236 LD (IX+3),A
55239 LD (IX+8),16 Set the width of the bonus to 16.
55243 LD (IX+9),16 Set the depth of the bonus to 16.
55247 LD (IX+12),244 Set the X offset of the sprite.
55251 LD (IX+13),4 Set the Y offset of the sprite.
55255 RET Return.
Prev: 55116 Up: Map Next: 55256