![]() |
Routines |
| Prev: CB89 | Up: Map | Next: CC09 |
|
Used by the routine at RunGame.
Makes a random creature, when the countdown has finished, and there is room for it. It is called once for each frame.
The routine does not make a creature in a room that has a special object in it. Otherwise it counts down the timer at SpawnTimer (which is set by SetCreatureTimer) and, when that is over, tries once for every four frames (judging by the random seed) to make a creature in one of the two object records reserved for creatures. If both are being used, nothing is done.
The creature that is made comes from the template of an object at CreatureTemplate, which is copied into the free record. After that the template is changed to a new creature of a random type, in a random place that is high above the floor, ready for the next time. If it is found to overlap another object there, its type is set to zero instead, which makes the object that is copied the next time one that does not exist.
|
||||
|
Return if the room has a special object or the timer is still running.
|
||||
| CreateCreature | CBAB | LD A,($A742) | Fetch the special object flag. | |
| CBAE | AND A | Return if there is a special object in the room. | ||
| CBAF | RET NZ | |||
| CBB0 | LD HL,$A73D | Take the creature timer, SpawnTimer. | ||
| CBB3 | DEC (HL) | Decrease the timer. | ||
| CBB4 | RET NZ | Return if it is not zero. | ||
| CBB5 | LD (HL),$01 | Set the timer to one, so that it is zero again after the next frame unless it is changed. | ||
|
Try once every four frames, then find a free creature slot.
|
||||
| CBB7 | LD A,($A70D) | Fetch the random seed. | ||
| CBBA | AND %00000011 | Keep the lowest two bits. | ||
| CBBC | RET NZ | Return unless they are zero. | ||
| CBBD | CALL SetCreatureTimer | Call SetCreatureTimer to set the timer. | ||
| CBC0 | LD HL,$A7EF | Start at the first of the objects for creatures, ObjectsTable_Creatures. | ||
| CBC3 | LD BC,$0020 | Set the size of an object, 20, in BC. | ||
| CBC6 | LD DE,$CC11 | Take the template of the creature, CreatureTemplate. | ||
| CBC9 | LD A,(HL) | Fetch the type of the object. | ||
| CBCA | AND A | Jump to CreateCreature_Copy if it is free. | ||
| CBCB | JR Z,CreateCreature_Copy | |||
| CBCD | ADD HL,BC | Move on to the second object for creatures. | ||
| CBCE | LD A,(HL) | Fetch the type of the object. | ||
| CBCF | AND A | Return if it is not free either. | ||
| CBD0 | RET NZ | |||
|
Copy the template, then pick a new creature for next time.
|
||||
| CreateCreature_Copy | CBD1 | EX DE,HL | Put the template against the free object. | |
| CBD2 | PUSH HL | Take the template as the object being filled in (using the stack). | ||
| CBD3 | POP IX | |||
| CBD5 | LDIR | Copy the template into the free object. | ||
| CBD7 | LD A,($A70D) | Fetch the random seed. | ||
| CBDA | AND %00101111 | Keep bits 0-3 and bit 5. | ||
| CBDC | ADD A,$68 | Add the start of the area for creatures, 68. | ||
| CBDE | LD (IX+$01),A | Set the x position of the creature in the template. | ||
| CBE1 | LD A,R | Fetch a random number from the refresh register. | ||
| CBE3 | AND %00101111 | Keep bits 0-3 and bit 5. | ||
| CBE5 | ADD A,$68 | Add the start of the area for creatures, 68. | ||
| CBE7 | LD (IX+$02),A | Set the y position of the creature in the template. | ||
| CBEA | LD A,($A70D) | Fetch the random seed. | ||
| CBED | RRA | Move bits 3-5 to bits 0-2. | ||
| CBEE | RRA | |||
| CBEF | RRA | |||
| CBF0 | AND %00000111 | Keep them. | ||
| CBF2 | LD L,A | Put the offset in L. | ||
| CBF3 | LD H,$00 | Clear H. | ||
| CBF5 | LD DE,$CC09 | Take the types of creatures, CreatureTypes. | ||
| CBF8 | ADD HL,DE | Add the offset. | ||
| CBF9 | LD A,(HL) | Fetch the type of creature. | ||
| CBFA | LD (IX+$00),A | Set the type of the creature in the template. | ||
| CBFD | CALL CalculatePixelCoordinates | Call CalculatePixelCoordinates to work out where the creature is on the screen. | ||
| CC00 | CALL TestObjectIntersections | Call TestObjectIntersections to find out if the creature overlaps an object where it is. | ||
| CC03 | RET NC | Return if it does not. | ||
|
Clear the template if the new place overlaps another object.
|
||||
| CC04 | LD (IX+$00),$00 | Set the type in the template to zero. | ||
| CC08 | RET | Return. | ||
| Prev: CB89 | Up: Map | Next: CC09 |