![]() |
Routines |
| Prev: 52703 | Up: Map | Next: 52857 |
|
Used by the routine at StartGame.
Starts a ball (a type 128 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 | 52712 | LD A,(48130) | Return unless the player has finished materialising. | |
| 52715 | CP 112 | |||
| 52717 | RET NZ | |||
| 52718 | LD A,(48050) | Return unless this is the fourth frame (the frame counter is 3 modulo four). | ||
| 52721 | CPL | |||
| 52722 | AND 3 | |||
| 52724 | RET NZ | |||
| 52725 | LD IY,48542 | Point at the first short-lived object, set the distance from one object to the next (16 bytes) and set a counter for the six objects. | ||
| 52729 | LD DE,16 | |||
| 52732 | LD B,6 | |||
| SpawnBall_Loop | 52734 | LD A,(IY+0) | Jump to SpawnBall_Found if the object is free. | |
| 52737 | AND A | |||
| 52738 | JR Z,SpawnBall_Found | |||
| 52740 | ADD IY,DE | Move on to the next object and loop back until all six have been checked. | ||
| 52742 | DJNZ SpawnBall_Loop | |||
| 52744 | RET | Return, as there is no free object. | ||
| SpawnBall_Found | 52745 | LD HL,52857 | Point at the template for a ball. | |
| 52748 | PUSH IY | Point DE at the free object (using the stack). | ||
| 52750 | POP DE | |||
| 52751 | LD BC,16 | Copy the template into the object. | ||
| 52754 | 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.
|
||||
| 52756 | LD A,(48272) | Fetch the column and row of the player's cell. | ||
| 52759 | LD L,A | |||
| 52760 | LD A,(48274) | |||
| 52763 | LD H,A | |||
| 52764 | LD A,(48042) | Jump to SpawnBall_Row to keep the column as it is if the first random number is less than 85. | ||
| 52767 | CP 85 | |||
| 52769 | JR C,SpawnBall_Row | |||
| 52771 | CP 170 | Jump to SpawnBall_NextColumn to move the ball on one column if the number is less than 170. | ||
| 52773 | JR C,SpawnBall_NextColumn | |||
| 52775 | DEC L | Move the ball back one column... | ||
| 52776 | DEC L | |||
| SpawnBall_NextColumn | 52777 | INC L | ... or on one column. | |
| SpawnBall_Row | 52778 | LD A,(48043) | Jump to SpawnBall_Place to keep the row as it is if the second random number is less than 85. | |
| 52781 | CP 85 | |||
| 52783 | JR C,SpawnBall_Place | |||
| 52785 | CP 170 | Jump to SpawnBall_NextRow to move the ball on one row if the number is less than 170. | ||
| 52787 | JR C,SpawnBall_NextRow | |||
| 52789 | DEC H | Move the ball back one row... | ||
| 52790 | DEC H | |||
| SpawnBall_NextRow | 52791 | INC H | ... or on one row. | |
| SpawnBall_Place | 52792 | LD A,L | Wrap the column round, to stay within the village. | |
| 52793 | AND 31 | |||
| 52795 | LD L,A | |||
| 52796 | LD A,H | Wrap the row round, to stay within the village. | ||
| 52797 | AND 31 | |||
| 52799 | LD H,A | |||
| 52800 | PUSH HL | Find out what kind of tile is in the cell. | ||
| 52801 | CALL FindMapTile | |||
| 52804 | POP HL | |||
| 52805 | DEC A | Return without making a ball if the tile is solid (1 or 2). | ||
| 52806 | CP 2 | |||
| 52808 | RET C | |||
| 52809 | LD (IY+2),L | Set the column and the row of the ball. | ||
| 52812 | LD (IY+4),H | |||
|
Choose the position of the ball within the cell using the random seeds.
|
||||
| 52815 | CALL RandomNumber | Update the random number generator. | ||
| 52818 | LD A,(48042) | Fetch the first random number and jump to SpawnBall_X if it is less than 192. | ||
| 52821 | CP 192 | |||
| 52823 | JR C,SpawnBall_X | |||
| 52825 | SUB 64 | Bring the number into the range 128 to 191. | ||
| SpawnBall_X | 52827 | ADD A,32 | Add 32 to get a position within the cell from 32 to 223, and set it as the X position of the ball. | |
| 52829 | LD (IY+1),A | |||
| 52832 | LD A,(48043) | Fetch the second random number and jump to SpawnBall_Y if it is less than 192. | ||
| 52835 | CP 192 | |||
| 52837 | JR C,SpawnBall_Y | |||
| 52839 | SUB 64 | Bring the number into the range 128 to 191. | ||
| SpawnBall_Y | 52841 | ADD A,32 | Add 32 to get a position within the cell from 32 to 223, and set it as the Y position of the ball. | |
| 52843 | LD (IY+3),A | |||
| 52846 | LD A,(48050) | Return if the frame counter is 128 or more. | ||
| 52849 | CP 128 | |||
| 52851 | RET NC | |||
| 52852 | SET 5,(IY+7) | Set the flag that makes the ball chase the player, and return. | ||
| 52856 | RET | |||
| Prev: 52703 | Up: Map | Next: 52857 |