![]() |
Routines |
| Prev: 43225 | Up: Map | Next: 43521 |
|
Used by the routine at RunFrame.
Checks whether the ship is touching any of the first four map objects in the slots at MapObjectSlots. When it is, most objects bounce the ship back, but a type 27 object in state four or five fills the fuel gauge, which is held in FuelLevel, and flashes the ship, and is then removed and marked as destroyed in the map table.
|
||||
| CheckMapObjectCollisions | 43252 | LD A,(38571) | Fetch the flag that is set once the crystals are delivered. | |
| 43255 | AND A | Return if it is set. | ||
| 43256 | RET NZ | |||
| 43257 | LD B,4 | Set the number of slots to four. | ||
| 43259 | LD IX,43019 | Use the first slot. | ||
| 43263 | LD HL,(51458) | Fetch the position of the ship. | ||
| 43266 | LD L,100 | The ship is always at the same horizontal position. | ||
| 43268 | LD A,(52411) | Fetch the horizontal scroll speed. | ||
| 43271 | NEG | Negate it. | ||
| 43273 | ADD A,L | Subtract it from the horizontal position. | ||
| 43274 | LD L,A | Store the horizontal position. | ||
| 43275 | LD A,(52410) | Fetch the vertical scroll speed. | ||
| 43278 | NEG | Negate it. | ||
| 43280 | ADD A,H | Subtract it from the vertical position. | ||
| 43281 | LD H,A | Store the vertical position. | ||
| 43282 | LD (52794),HL | Store the position of the ship. | ||
| 43285 | LD D,40 | The ship is 40 pixels wide. | ||
| 43287 | LD A,(49577) | Fetch the height of the ship. | ||
| 43290 | LD E,A | Put it in E. | ||
| 43291 | LD (47625),DE | Store the size of the ship. | ||
| CheckMapObjectCollisions_Loop | 43295 | PUSH BC | Save the slot counter. | |
| 43296 | PUSH IX | Save the address of the slot. | ||
| 43298 | LD A,(IX+0) | Fetch the type of the object. | ||
| 43301 | INC A | Is it 255, which is free? | ||
| 43302 | JP Z,CheckMapObjectCollisions_Next | Jump to CheckMapObjectCollisions_Next if so. | ||
| 43305 | LD A,(IX+19) | Fetch the state of the object. | ||
| 43308 | AND %00001111 | Keep the bottom four bits. | ||
| 43310 | CP 11 | Jump to CheckMapObjectCollisions_Next if the state is 11. | ||
| 43312 | JP Z,CheckMapObjectCollisions_Next | |||
| 43315 | BIT 7,(IX+16) | Jump to CheckMapObjectCollisions_Next if the object is not on the screen. | ||
| 43319 | JP Z,CheckMapObjectCollisions_Next | |||
| 43322 | LD A,(IX+18) | Fetch the vertical position of the object on the screen. | ||
| 43325 | CP 40 | Jump to CheckMapObjectCollisions_Next if it is too far up. | ||
| 43327 | JP C,CheckMapObjectCollisions_Next | |||
| 43330 | LD H,A | Store it in H. | ||
| 43331 | LD A,(IX+17) | Fetch the horizontal position of the object on the screen. | ||
| 43334 | CP 48 | Jump to CheckMapObjectCollisions_Next if it is too far to the left. | ||
| 43336 | JP C,CheckMapObjectCollisions_Next | |||
| 43339 | CP 160 | Jump to CheckMapObjectCollisions_Next if it is too far to the right. | ||
| 43341 | JP NC,CheckMapObjectCollisions_Next | |||
| 43344 | LD L,A | Store it in L. | ||
| 43345 | LD (43940),HL | Store the position of the object as the first box. | ||
| 43348 | CALL FetchFrameSprite | Find the sprite of the object. | ||
| 43351 | LD A,(DE) | Fetch the width of the sprite in bytes. | ||
| 43352 | ADD A,A | Multiply it by eight to get the width in pixels. | ||
| 43353 | ADD A,A | Double A. | ||
| 43354 | ADD A,A | Double A. | ||
| 43355 | LD (43942),A | Store it as the width of the first box. | ||
| 43358 | INC DE | Move on to the height. | ||
| 43359 | LD A,(DE) | Fetch the height of the sprite. | ||
| 43360 | LD (43943),A | Store it as the height of the first box. | ||
| 43363 | LD HL,(52794) | Fetch the position of the ship. | ||
| 43366 | LD DE,(47625) | Fetch the size of the ship. | ||
| 43370 | LD (44358),IX | Save the address of the slot. | ||
| 43374 | LD IX,43940 | Use the first box. | ||
| 43378 | CALL TestBoxesOverlap | Test whether the boxes overlap. | ||
| 43381 | LD A,(23580) | Fetch the result. | ||
| 43384 | AND A | Jump to CheckMapObjectCollisions_Hit if they do. | ||
| 43385 | JR NZ,CheckMapObjectCollisions_Hit | |||
| CheckMapObjectCollisions_Next | 43387 | POP IX | Restore the address of the slot. | |
| 43389 | LD BC,26 | Move on to the next slot... | ||
| 43392 | ADD IX,BC | IX gains BC. | ||
| 43394 | POP BC | Restore the slot counter. | ||
| 43395 | DEC B | Decrease the slot counter. | ||
| 43396 | JP NZ,CheckMapObjectCollisions_Loop | Jump back to CheckMapObjectCollisions_Loop for each slot. | ||
| 43399 | RET | Return. | ||
|
The ship has touched an object.
|
||||
| CheckMapObjectCollisions_Hit | 43400 | LD IY,(44358) | Fetch the address of the slot. | |
| 43404 | LD A,(IY+0) | Fetch the type of the object. | ||
| 43407 | CP 27 | Jump to CheckMapObjectCollisions_Bounce unless it is type 27. | ||
| 43409 | JR NZ,CheckMapObjectCollisions_Bounce | |||
| 43411 | LD A,(IY+19) | Fetch the state of the object. | ||
| 43414 | AND %00001111 | Keep the bottom four bits. | ||
| 43416 | CP 4 | Jump to CheckMapObjectCollisions_Refuel if the state is four. | ||
| 43418 | JR Z,CheckMapObjectCollisions_Refuel | |||
| 43420 | CP 5 | Jump to CheckMapObjectCollisions_Bounce unless the state is five. | ||
| 43422 | JR NZ,CheckMapObjectCollisions_Bounce | |||
| CheckMapObjectCollisions_Refuel | 43424 | LD HL,16896 | Use the value for a full fuel gauge. | |
| 43427 | LD (52299),HL | Fill the fuel gauge. | ||
| 43430 | SET 4,(IY+16) | Mark the object to be removed. | ||
| 43434 | LD A,(IY+24) | Fetch the position of the object in the map table. | ||
| 43437 | AND %00000001 | Keep the bits of A that are set in 1. | ||
| 43439 | LD H,A | H=A. | ||
| 43440 | LD L,(IY+25) | Read offset 25 of IY into L. | ||
| 43443 | LD DE,23700 | The map table. | ||
| 43446 | ADD HL,DE | HL gains DE. | ||
| 43447 | SET 7,(HL) | Mark the entry in the map table as destroyed. | ||
| 43449 | LD A,255 | A=255. | ||
| 43451 | LD (36803),A | The damage counter. | ||
| 43454 | CALL DamageShip_Hit | Flash the ship. | ||
| 43457 | JP CheckMapObjectCollisions_Done | Jump to CheckMapObjectCollisions_Done. | ||
|
Any other object makes the ship bounce, if it is to the left or right of the ship or above or below it.
|
||||
| CheckMapObjectCollisions_Bounce | 43460 | LD A,255 | Set the flag for the ship bouncing. | |
| 43462 | LD (53436),A | Update the collision kind. | ||
| 43465 | LD A,(IX+0) | Fetch the left edge of the box of the object. | ||
| 43468 | CP 139 | Bounce horizontally if it is 139 or more. | ||
| 43470 | CALL NC,BounceHorizontally | |||
| 43473 | LD A,(IX+0) | Fetch the left edge of the box of the object. | ||
| 43476 | ADD A,(IX+2) | Add its width to get the right edge. | ||
| 43479 | CP 101 | Bounce horizontally if it is less than 101. | ||
| 43481 | CALL C,BounceHorizontally | |||
| 43484 | LD A,(51459) | Fetch the vertical position of the ship. | ||
| 43487 | LD H,A | Store it in H. | ||
| 43488 | SUB E | Subtract the height of the ship... | ||
| 43489 | INC A | ...and add one to get the top of the ship. | ||
| 43490 | CP (IX+1) | Bounce vertically if the top of the ship is not above the object. | ||
| 43493 | CALL NC,BounceVertically | |||
| 43496 | LD A,(52410) | Fetch the vertical scroll speed. | ||
| 43499 | NEG | Negate it. | ||
| 43501 | BIT 7,A | Jump to CheckMapObjectCollisions_Done if it is negative. | ||
| 43503 | JR NZ,CheckMapObjectCollisions_Done | |||
| 43505 | LD A,(IX+1) | Fetch the bottom edge of the box of the object. | ||
| 43508 | SUB (IX+3) | Subtract its height. | ||
| 43511 | ADD A,9 | Add nine. | ||
| 43513 | CP H | Bounce vertically if that is not above the bottom of the ship. | ||
| 43514 | CALL NC,BounceVertically | |||
| CheckMapObjectCollisions_Done | 43517 | POP IX | Restore the address of the slot. | |
| 43519 | POP BC | Restore the slot counter. | ||
| 43520 | RET | Return. | ||
| Prev: 43225 | Up: Map | Next: 43521 |