Routines |
Prev: D71C | Up: Map | Next: D794 |
|
||||||||
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):
|
||||||||
D730 | LD A,($EC9D) | Number of creatures currently on-screen in the tunnel | ||||||
D733 | INC A | Increase by 1 | ||||||
D734 | CP $03 | There's a limit of 3 creatures on-screen | ||||||
D736 | JR NC,$D794 | If adding this creature would make it 4, skip the routine. | ||||||
It's OK to generate a creature:
|
||||||||
D738 | LD ($EC9D),A | It's < 3 creatures. Store the creature count byte | ||||||
D73B | LD A,$0E | Item type #14 designates a tunnel object - boundary wall, bat or spider (creatures are later differentiated from walls using the byte at stored EB46) | ||||||
D73D | LD ($EB43),A | |||||||
D740 | LD A,$01 | Starting frame offset (no offset) | ||||||
D742 | LD ($EB50),A | |||||||
Randomize starting position of creature in relation to tunnel wall:
|
||||||||
D745 | LD A,C | Retrieve random number generated earlier | ||||||
D746 | AND $0F | Keep bits 0-4 (values = 0-15) | ||||||
D748 | SUB $07 | Subtract 7 (value range now between -7 and +8) | ||||||
D74A | LD B,A | Store in B register | ||||||
D74B | LD A,($EC9E) | Get tunnel horizontal position | ||||||
D74E | ADD A,B | Add the random offset calculated earlier (-7 to +8) | ||||||
D74F | LD ($EB48),A | Store as graphic's horizontal position (in half character/4-pixel steps) | ||||||
D752 | LD B,A | Put in B register | ||||||
Determine whether the creature will be a SPIDER or a BAT:
|
||||||||
D753 | LD A,C | Retrieve random number | ||||||
D754 | AND $01 | Check bit 1 for 0 or 1 (50/50) - to run one of the next two sections. | ||||||
D756 | JR Z,$D769 | |||||||
Generate a SPIDER
|
||||||||
D758 | LD A,$04 | Creature type = 4 | ||||||
D75A | LD ($EB46),A | |||||||
D75D | LD A,($EC9E) | Horizontal tunnel wall position (half-character/4-pixel steps) | ||||||
D760 | SUB B | Subtract the graphic's horizontal position calculated earlier | ||||||
D761 | ADD A,A | ...Double it... | ||||||
D762 | LD ($EB4C),A | ...and store as position (movement) offset | ||||||
D765 | LD A,$7D | Graphic number for spider graphic address at 98BB | ||||||
D767 | JR $D77D | |||||||
Generate a BAT
|
||||||||
D769 | LD A,$08 | Creature type = 8 | ||||||
D76B | LD ($EB46),A | |||||||
D76E | LD A,C | Retrieve random number generated earlier | ||||||
D76F | AND $7F | Filter out bit 7, giving a random number in the range of 0-127 | ||||||
D771 | SUB $3F | ...And subtract 63, giving a random number in the range of -63 to +64 | ||||||
D773 | LD ($EB4C),A | Store as horizontal position (movement) speed/offset | ||||||
D776 | LD A,$24 | Set vertical position (movement) speed/offset (36 pixels). This will cause the bat to start by moving quickly down the screen. | ||||||
D778 | LD ($EB4D),A | |||||||
D77B | LD A,$7F | Graphic number for bat graphic address at 98BF | ||||||
Set up creature graphic
|
||||||||
D77D | LD C,A | Temporarily store the graphic number in C register | ||||||
D77E | LD A,$FE | Tunnel item identifier (boundary wall, bat or spider) - ends up in byte 9 of data set at 7C00 | ||||||
D780 | LD ($EB4B),A | |||||||
D783 | LD A,$08 | Set vertical position (8 pixels from top of screen) | ||||||
D785 | LD ($EB4A),A | |||||||
D788 | LD A,C | Retrieve graphic number | ||||||
D789 | CALL $E0C2 | Set up the graphics | ||||||
D78C | CALL $E0B0 | ...and copy into room data set at 7C00 | ||||||
D78F | LD (HL),$FF | Set end-of-data marker at start of next data set | ||||||
D791 | LD ($EB72),HL | ...And store the address pointer to it. |
Prev: D71C | Up: Map | Next: D794 |