![]() |
Routines |
| Prev: 44886 | Up: Map | Next: 45177 |
|
Used by the routine at Run_Game.
Lets a flying creature into the room every now and then. Nothing happens unless the sum of the tick counter and the frame counter is a multiple of eight.
If one of the four creature records that start at First_Creature_Record is free, it is filled in with a type that comes from bits 2 and 4 of the tick counter: 48 (eagle), 52 (gargoyle), 64 (vulture) or 68 (jellyfish). Only the vultures and the jellyfish appear until the flag at Creature_Spawn_Flag has been set, which happens when Sabreman kills a guardian.
The creature starts in a room next to the one that Sabreman is in. It is on the left or the right if the room has a gap in that wall (the choice is made from bit 0 of the tick counter), and it is above or below otherwise. Its position inside the room, and its attribute, come from the frame counter.
Handle_Flying_Creature then makes the creature fly into the room that Sabreman is in.
|
||||
| Spawn_Flying_Creature | 45018 | LD A,(36566) | Fetch the tick counter from GameTimer and keep it in B. | |
| 45021 | LD B,A | |||
| 45022 | LD A,(23672) | Fetch the low byte of FRAMES. | ||
| 45025 | ADD A,B | Add the tick counter to make a pseudo-random number. | ||
| 45026 | AND %00000111 | Keep only the low three bits. | ||
| 45028 | RET NZ | Return unless the result is zero (a creature can only appear on one pass in eight). | ||
| 45029 | LD HL,36826 | Point at the first of the four creature records (First_Creature_Record). | ||
| 45032 | LD DE,16 | Set the size of a record to 16. | ||
| 45035 | LD B,4 | Set the number of records to 4. | ||
| Spawn_Flying_Creature_Find_Record | 45037 | LD A,(HL) | Fetch the type of the record. | |
| 45038 | AND A | Jump to Spawn_Flying_Creature_Choose_Type if the record is not in use (the type is zero). | ||
| 45039 | JR Z,Spawn_Flying_Creature_Choose_Type | |||
| 45041 | ADD HL,DE | Move on to the next record. | ||
| 45042 | DJNZ Spawn_Flying_Creature_Find_Record | Loop back until all of the records have been tried. | ||
| 45044 | RET | Return as all of the records are in use. | ||
| Spawn_Flying_Creature_Choose_Type | 45045 | LD A,(43692) | Fetch the flags of the room that Sabreman is in. | |
| 45048 | LD E,A | Store them in E. | ||
| 45049 | LD A,(36601) | Fetch the creature spawn flag. | ||
| 45052 | AND A | Test the flag. | ||
| 45053 | LD A,(36566) | Fetch the tick counter. | ||
| 45056 | JR NZ,Spawn_Flying_Creature_Store_Type | Jump to Spawn_Flying_Creature_Store_Type if the flag is set. | ||
| 45058 | OR %00010000 | Set bit 4, which limits the choice to the vulture and the jellyfish. | ||
| Spawn_Flying_Creature_Store_Type | 45060 | PUSH AF | Stash the tick counter on the stack. | |
| 45061 | AND %00010100 | Keep only bits 2 and 4. | ||
| 45063 | ADD A,48 | Add 48 to make the type. | ||
| 45065 | LD (HL),A | Store the type in the record. | ||
| 45066 | POP AF | Restore the tick counter. | ||
| 45067 | INC HL | Move on to the x position. | ||
| 45068 | BIT 0,A | Jump to Spawn_Flying_Creature_Test_Left if bit 0 of the tick counter is set. | ||
| 45070 | JR NZ,Spawn_Flying_Creature_Test_Left | |||
|
Bit 0 of the tick counter is reset, so use the right of the room if it has no right wall, and the left otherwise.
|
||||
| 45072 | BIT 2,E | Jump to Spawn_Flying_Creature_From_Right if the room has no right wall. | ||
| 45074 | JR Z,Spawn_Flying_Creature_From_Right | |||
| 45076 | BIT 6,E | Jump to Spawn_Flying_Creature_Vertically if the room has a left wall too. | ||
| 45078 | JR NZ,Spawn_Flying_Creature_Vertically | |||
|
The creature comes in from the room on the left.
|
||||
| Spawn_Flying_Creature_From_Left | 45080 | AND %01111111 | Keep only the low seven bits of the tick counter. | |
| 45082 | ADD A,72 | Add 72 to make the x position. | ||
| 45084 | LD (HL),A | Store the x position. | ||
| 45085 | INC HL | Move on to the room x. | ||
| 45086 | LD A,(36636) | Fetch the room x of Sabreman. | ||
| 45089 | DEC A | Subtract one to get the room on the left. | ||
| Spawn_Flying_Creature_Store_Room_X | 45090 | LD (HL),A | Store the room x. | |
| 45091 | INC HL | Move on to the y position. | ||
| 45092 | LD A,(23672) | Fetch the low byte of the frame counter. | ||
| 45095 | AND %00111111 | Keep only the low six bits. | ||
| 45097 | ADD A,64 | Add 64 to make the y position. | ||
| 45099 | LD (HL),A | Store the y position. | ||
| 45100 | INC HL | Move on to the room y. | ||
| 45101 | LD A,(36638) | Fetch the room y of Sabreman. | ||
| 45104 | LD (HL),A | Store it as the room y of the creature. | ||
| 45105 | INC HL | Move on to the attribute. | ||
| 45106 | LD A,(23672) | Fetch the low byte of the frame counter. | ||
| 45109 | AND %00000011 | Keep only the low two bits. | ||
| 45111 | ADD A,66 | Add 66 to make a bright attribute. | ||
| 45113 | LD (HL),A | Store the attribute of the creature. | ||
| 45114 | RET | Return. | ||
| Spawn_Flying_Creature_Test_Left | 45115 | BIT 6,E | Jump to Spawn_Flying_Creature_From_Left if the room has no left wall. | |
| 45117 | JR Z,Spawn_Flying_Creature_From_Left | |||
| 45119 | BIT 2,E | Jump to Spawn_Flying_Creature_Vertically if the room has a right wall. | ||
| 45121 | JR NZ,Spawn_Flying_Creature_Vertically | |||
|
The creature comes in from the room on the right.
|
||||
| Spawn_Flying_Creature_From_Right | 45123 | AND %00111111 | Keep only the low six bits of the tick counter. | |
| 45125 | ADD A,64 | Add 64 to make the x position. | ||
| 45127 | LD (HL),A | Store the x position. | ||
| 45128 | INC HL | Move on to the room x. | ||
| 45129 | LD A,(36636) | Fetch the room x of Sabreman. | ||
| 45132 | INC A | Add one to get the room on the right. | ||
| 45133 | JR Spawn_Flying_Creature_Store_Room_X | Jump to Spawn_Flying_Creature_Store_Room_X to store the room x. | ||
|
The creature comes in from the room above or below.
|
||||
| Spawn_Flying_Creature_Vertically | 45135 | AND %01111111 | Keep only the low seven bits of the tick counter. | |
| 45137 | ADD A,72 | Add 72 to make the x position. | ||
| 45139 | LD (HL),A | Store the x position. | ||
| 45140 | INC HL | Move on to the room x. | ||
| 45141 | LD A,(36636) | Fetch the room x of Sabreman. | ||
| 45144 | LD (HL),A | Store it as the room x of the creature. | ||
| 45145 | INC HL | Move on to the y position. | ||
| 45146 | LD A,(23672) | Fetch the low byte of the frame counter. | ||
| 45149 | AND %00111111 | Keep only the low six bits. | ||
| 45151 | ADD A,64 | Add 64 to make the y position. | ||
| 45153 | LD (HL),A | Store the y position. | ||
| 45154 | INC HL | Move on to the room y. | ||
| 45155 | LD A,(36638) | Fetch the room y of Sabreman. | ||
| 45158 | BIT 0,E | Jump to Spawn_Flying_Creature_From_Above if the room has no ceiling. | ||
| 45160 | JR Z,Spawn_Flying_Creature_From_Above | |||
| 45162 | INC A | Add one to get the room below. | ||
| 45163 | JR Spawn_Flying_Creature_Store_Room_Y | Jump to Spawn_Flying_Creature_Store_Room_Y to store the room y. | ||
| Spawn_Flying_Creature_From_Above | 45165 | DEC A | Subtract one to get the room above. | |
| Spawn_Flying_Creature_Store_Room_Y | 45166 | LD (HL),A | Store the room y. | |
| 45167 | INC HL | Move on to the attribute. | ||
| 45168 | LD A,(23672) | Fetch the low byte of the frame counter. | ||
| 45171 | AND %00000011 | Keep only the low two bits. | ||
| 45173 | ADD A,66 | Add 66 to make a bright attribute. | ||
| 45175 | LD (HL),A | Store the attribute of the creature. | ||
| 45176 | RET | Return. | ||
| Prev: 44886 | Up: Map | Next: 45177 |