![]() |
Routines |
| Prev: CDDF | Up: Map | Next: CE79 |
|
Used by the routine at StartGame.
Starts a ball (a type 80 object, which turns into a creature - see UpdateBall) in one of the short-lived objects at ObjectTable_Transient. It is done on every fourth frame, once the player has finished materialising, and the ball is placed in a cell that is next to the player or the same one as the player, as long as that cell is not solid.
|
||||
| SpawnBall | CDE8 | LD A,($BC02) | Return unless the player has finished materialising. | |
| CDEB | CP $70 | |||
| CDED | RET NZ | |||
| CDEE | LD A,($BBB2) | Return unless this is the fourth frame (the frame counter is 03 modulo four). | ||
| CDF1 | CPL | |||
| CDF2 | AND $03 | |||
| CDF4 | RET NZ | |||
| CDF5 | LD IY,$BD9E | Point at the first short-lived object, set the distance from one object to the next (10 bytes) and set a counter for the six objects. | ||
| CDF9 | LD DE,$0010 | |||
| CDFC | LD B,$06 | |||
| SpawnBall_Loop | CDFE | LD A,(IY+$00) | Jump to SpawnBall_Found if the object is free. | |
| CE01 | AND A | |||
| CE02 | JR Z,SpawnBall_Found | |||
| CE04 | ADD IY,DE | Move on to the next object and loop back until all six have been checked. | ||
| CE06 | DJNZ SpawnBall_Loop | |||
| CE08 | RET | Return, as there is no free object. | ||
| SpawnBall_Found | CE09 | LD HL,$CE79 | Point at the template for a ball. | |
| CE0C | PUSH IY | Point DE at the free object (using the stack). | ||
| CE0E | POP DE | |||
| CE0F | LD BC,$0010 | Copy the template into the object. | ||
| CE12 | LDIR | |||
|
Choose the cell for the ball: the player's cell, with the column and row each moved by one cell, or not moved, using the random seeds.
|
||||
| CE14 | LD A,($BC90) | Fetch the column and row of the player's cell. | ||
| CE17 | LD L,A | |||
| CE18 | LD A,($BC92) | |||
| CE1B | LD H,A | |||
| CE1C | LD A,($BBAA) | Jump to SpawnBall_Row to keep the column as it is if the first random number is less than 55. | ||
| CE1F | CP $55 | |||
| CE21 | JR C,SpawnBall_Row | |||
| CE23 | CP $AA | Jump to SpawnBall_NextColumn to move the ball on one column if the number is less than AA. | ||
| CE25 | JR C,SpawnBall_NextColumn | |||
| CE27 | DEC L | Move the ball back one column... | ||
| CE28 | DEC L | |||
| SpawnBall_NextColumn | CE29 | INC L | ... or on one column. | |
| SpawnBall_Row | CE2A | LD A,($BBAB) | Jump to SpawnBall_Place to keep the row as it is if the second random number is less than 55. | |
| CE2D | CP $55 | |||
| CE2F | JR C,SpawnBall_Place | |||
| CE31 | CP $AA | Jump to SpawnBall_NextRow to move the ball on one row if the number is less than AA. | ||
| CE33 | JR C,SpawnBall_NextRow | |||
| CE35 | DEC H | Move the ball back one row... | ||
| CE36 | DEC H | |||
| SpawnBall_NextRow | CE37 | INC H | ... or on one row. | |
| SpawnBall_Place | CE38 | LD A,L | Wrap the column round, to stay within the village. | |
| CE39 | AND $1F | |||
| CE3B | LD L,A | |||
| CE3C | LD A,H | Wrap the row round, to stay within the village. | ||
| CE3D | AND $1F | |||
| CE3F | LD H,A | |||
| CE40 | PUSH HL | Find out what kind of tile is in the cell. | ||
| CE41 | CALL FindMapTile | |||
| CE44 | POP HL | |||
| CE45 | DEC A | Return without making a ball if the tile is solid (01 or 02). | ||
| CE46 | CP $02 | |||
| CE48 | RET C | |||
| CE49 | LD (IY+$02),L | Set the column and the row of the ball. | ||
| CE4C | LD (IY+$04),H | |||
|
Choose the position of the ball within the cell using the random seeds.
|
||||
| CE4F | CALL RandomNumber | Update the random number generator. | ||
| CE52 | LD A,($BBAA) | Fetch the first random number and jump to SpawnBall_X if it is less than C0. | ||
| CE55 | CP $C0 | |||
| CE57 | JR C,SpawnBall_X | |||
| CE59 | SUB $40 | Bring the number into the range 80 to BF. | ||
| SpawnBall_X | CE5B | ADD A,$20 | Add 20 to get a position within the cell from 20 to DF, and set it as the X position of the ball. | |
| CE5D | LD (IY+$01),A | |||
| CE60 | LD A,($BBAB) | Fetch the second random number and jump to SpawnBall_Y if it is less than C0. | ||
| CE63 | CP $C0 | |||
| CE65 | JR C,SpawnBall_Y | |||
| CE67 | SUB $40 | Bring the number into the range 80 to BF. | ||
| SpawnBall_Y | CE69 | ADD A,$20 | Add 20 to get a position within the cell from 20 to DF, and set it as the Y position of the ball. | |
| CE6B | LD (IY+$03),A | |||
| CE6E | LD A,($BBB2) | Return if the frame counter is 80 or more. | ||
| CE71 | CP $80 | |||
| CE73 | RET NC | |||
| CE74 | SET 5,(IY+$07) | Set the flag that makes the ball chase the player, and return. | ||
| CE78 | RET | |||
| Prev: CDDF | Up: Map | Next: CE79 |