Prev: 55068 Up: Map Next: 55188
55088: Tunnel section - Generate a SPIDER or BAT encounter
Input
C Pseudo-random number generated (56070) in previous routine
The previous routine has decided to generate a creature in the tunnel.
First check that there aren't already too many creatures (3). If not, generate one (50/50 chance of SPIDER/BAT):
55088 LD A,(60573) Number of creatures currently on-screen in the tunnel
55091 INC A Increase by 1
55092 CP 3 There's a limit of 3 creatures on-screen
55094 JR NC,55188 If adding this creature would make it 4, skip the routine.
It's OK to generate a creature:
55096 LD (60573),A It's < 3 creatures. Store the creature count byte
55099 LD A,14 Item type #14 designates a tunnel object - boundary wall, bat or spider (creatures are later differentiated from walls using the byte at stored 60230)
55101 LD (60227),A
55104 LD A,1 Starting frame offset (no offset)
55106 LD (60240),A
Randomize starting position of creature in relation to tunnel wall:
55109 LD A,C Retrieve random number generated earlier
55110 AND 15 Keep bits 0-4 (values = 0-15)
55112 SUB 7 Subtract 7 (value range now between -7 and +8)
55114 LD B,A Store in B register
55115 LD A,(60574) Get tunnel horizontal position
55118 ADD A,B Add the random offset calculated earlier (-7 to +8)
55119 LD (60232),A Store as graphic's horizontal position (in half character/4-pixel steps)
55122 LD B,A Put in B register
Determine whether the creature will be a SPIDER or a BAT:
55123 LD A,C Retrieve random number
55124 AND 1 Check bit 1 for 0 or 1 (50/50) - to run one of the next two sections.
55126 JR Z,55145
Generate a SPIDER
55128 LD A,4 Creature type = 4
55130 LD (60230),A
55133 LD A,(60574) Horizontal tunnel wall position (half-character/4-pixel steps)
55136 SUB B Subtract the graphic's horizontal position calculated earlier
55137 ADD A,A ...Double it...
55138 LD (60236),A ...and store as position (movement) offset
55141 LD A,125 Graphic number for spider graphic address at 39099
55143 JR 55165
Generate a BAT
55145 LD A,8 Creature type = 8
55147 LD (60230),A
55150 LD A,C Retrieve random number generated earlier
55151 AND 127 Filter out bit 7, giving a random number in the range of 0-127
55153 SUB 63 ...And subtract 63, giving a random number in the range of -63 to +64
55155 LD (60236),A Store as horizontal position (movement) speed/offset
55158 LD A,36 Set vertical position (movement) speed/offset (36 pixels). This will cause the bat to start by moving quickly down the screen.
55160 LD (60237),A
55163 LD A,127 Graphic number for bat graphic address at 39103
Set up creature graphic
55165 LD C,A Temporarily store the graphic number in C register
55166 LD A,254 Tunnel item identifier (boundary wall, bat or spider) - ends up in byte 9 of data set at 31744
55168 LD (60235),A
55171 LD A,8 Set vertical position (8 pixels from top of screen)
55173 LD (60234),A
55176 LD A,C Retrieve graphic number
55177 CALL 57538 Set up the graphics
55180 CALL 57520 ...and copy into room data set at 31744
55183 LD (HL),255 Set end-of-data marker at start of next data set
55185 LD (60274),HL ...And store the address pointer to it.
Prev: 55068 Up: Map Next: 55188