Routines |
Prev: 52118 | Up: Map | Next: 52263 |
Not defined in the room creature table (27532), but there are certain room items defined in the room object item sets at 29551 that can move around the screen, for example:
This routine determines if the item/creature in the room item set can move around the screen.
If so, it determines its movement using the movement pattern byte stored at 60301. Some creatures home in on Maroc, others move more haphazardly.
|
||||
52136 | LD A,(60301) | First byte from object state data set | ||
52139 | AND 7 | Keep bits 0-2 | ||
52141 | LD C,A | Store in C register | ||
52142 | CP 0 | Does this item move (any of bits 0-2 are set)? | ||
52144 | JP Z,52263 | If not, skip the next section | ||
This item moves:
|
||||
52147 | LD A,(60238) | Get the item properties byte | ||
52150 | AND 253 | Reset bit 2 to indicate that this item is not hidden - e.g. it might be a scorpion released from a bottle, or the mouse appearing from the mouse hole | ||
52152 | LD (60238),A | ...and re-store | ||
52155 | LD A,(60074) | Get game counter/timer | ||
52158 | AND 31 | Keep bits 0-4 (values 0-31) | ||
52160 | JP Z,52255 | To stop the item/creature's movement/speed getting out of hand, every 32nd frame, stop the creature/item by jumping out here and setting its vertical & horizontal movement speed to zero. | ||
52163 | CP 7 | Check if counter is < 7 | ||
52165 | JR C,52239 | If so, jump out (overall this will be around 1 in 4 times) - don't adjust this creature's current direction/speed/trajectory | ||
Game counter between 7 and 31 (will be ~3 times in every 4)
|
||||
52167 | LD A,C | Graphic movement data for graphics from C register (60301) | ||
52168 | AND 1 | Check bit 1 - if set, this indicates that the creature has a random element to its movement | ||
52170 | JR Z,52204 | If not set, skip the next routine, which randomly adjusts the creature's speed/direction | ||
CREATURES WITH A RANDOM ELEMENT TO THEIR MOVEMENT - randomly adjust this item's vertical and horizontal movement speed
|
||||
52172 | CALL 56070 | Generate pseudo-random number | ||
52175 | LD B,A | Temp store in B register | ||
52176 | AND 15 | Keep bits 0-3 (values 0-15) | ||
52178 | SUB 7 | Subtract 7 | ||
52180 | LD D,A | Store in D register - will be a number between -7 and +8 | ||
52181 | LD A,(60236) | Item's horizontal movement speed | ||
52184 | ADD A,D | Add (or subtract if negative) the random value to current speed | ||
52185 | LD (60236),A | ...and re-store altered horizontal movement speed | ||
52188 | LD A,B | Retrieve pseudo-random number | ||
52189 | RRA | |||
52190 | RRA | |||
52191 | RRA | Divide by 8 | ||
52192 | AND 15 | Keep bits 0-3 (values 0-15) | ||
52194 | SUB 7 | Subtract 7 | ||
52196 | LD D,A | Store in D register - will be a number between -7 and +8 | ||
52197 | LD A,(60237) | Item's vertical movement speed | ||
52200 | ADD A,D | Add (or subtract if negative) the random value to current speed | ||
52201 | LD (60237),A | ...and re-store altered horizontal movement speed | ||
Bit 1 (2) of the item's movement pattern byte indicates whether this creature/item will home in on Maroc.
|
||||
52204 | LD A,C | Retrieve movement pattern byte from C register | ||
52205 | AND 2 | Check bit 1 (2) | ||
52207 | JR Z,52239 | If set, this item/creature will try to home in on Maroc's position. If not (e.g. the mouse) skip the next set of instructions. | ||
CREATURES THAT HOME IN ON MAROC'S POSITION:
Calculate HORIZONTAL movement direction
|
||||
52209 | LD A,(60232) | Get the creature/item's horizontal position | ||
52212 | LD C,A | |||
52213 | LD A,(60096) | Maroc's horizontal screen position | ||
52216 | SUB C | Subtract the item's horizontal position | ||
52217 | RLA | Rotating the bits left... | ||
52218 | SBC A,A | ...and then using sub with carry will result in 0 or 255 (-1) - this indicates whether the difference is positive (Maroc is to the right) or negative (Maroc is to the left) | ||
52219 | XOR 7 | This XOR subsequently produces a value of either +7 or -7 | ||
52221 | LD (60236),A | ...Store this as the item/creature's horizontal movement speed | ||
Calculate VERTICAL movement direction
|
||||
52224 | LD A,(60234) | Get the creature/item's vertical position | ||
52227 | LD C,A | |||
52228 | LD A,(60097) | Maroc's vertical (Y-axis) screen position | ||
52231 | SUB C | Subtract the item's vertical position | ||
52232 | RLA | Rotating the bits left... | ||
52233 | SBC A,A | ...and then using sub with carry will result in 0 or 255 (-1) - this indicates whether the difference is positive (Maroc is below the creature/item) or negative (Maroc is above the creature/item) | ||
52234 | XOR 7 | This XOR subsequently produces a value of either +7 or -7 | ||
52236 | LD (60237),A | ...Store this as the item/creature's vertical movement speed | ||
Check if item/creature is within wall boundaries (room wall collision check)
|
||||
52239 | LD A,(60301) | Retrieve movement pattern byte | ||
52242 | AND 4 | Check if bit 2 is set | ||
52244 | JR NZ,52263 | If so, skip to the next routine | ||
52246 | LD A,(60234) | Graphic vertical position in room | ||
52249 | LD E,A | |||
52250 | CALL 57401 | Run the standard wall collision check, which keeps the creature/item within the room's boundary | ||
52253 | JR 52263 | |||
Jump from 52160 every 32nd game cycle. To reduce overly-erratic movement of creatures or items, this routine stops the item/creature moving. It also makes creature movement looks slightly more natural as they pause their movement occasionally.
|
||||
52255 | LD A,0 | Set the item/creature's vertical and horizontal movement speed to zero | ||
52257 | LD (60237),A | |||
52260 | LD (60236),A |
Prev: 52118 | Up: Map | Next: 52263 |