Prev: A8D9 Up: Map Next: AA01
A8F4: Check Map Object Collisions
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 1B 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 A8F4 LD A,($96AB) Fetch the flag that is set once the crystals are delivered.
A8F7 AND A Return if it is set.
A8F8 RET NZ
A8F9 LD B,$04 Set the number of slots to four.
A8FB LD IX,$A80B Use the first slot.
A8FF LD HL,($C902) Fetch the position of the ship.
A902 LD L,$64 The ship is always at the same horizontal position.
A904 LD A,($CCBB) Fetch the horizontal scroll speed.
A907 NEG Negate it.
A909 ADD A,L Subtract it from the horizontal position.
A90A LD L,A Store the horizontal position.
A90B LD A,($CCBA) Fetch the vertical scroll speed.
A90E NEG Negate it.
A910 ADD A,H Subtract it from the vertical position.
A911 LD H,A Store the vertical position.
A912 LD ($CE3A),HL Store the position of the ship.
A915 LD D,$28 The ship is 28 pixels wide.
A917 LD A,($C1A9) Fetch the height of the ship.
A91A LD E,A Put it in E.
A91B LD ($BA09),DE Store the size of the ship.
CheckMapObjectCollisions_Loop A91F PUSH BC Save the slot counter.
A920 PUSH IX Save the address of the slot.
A922 LD A,(IX+$00) Fetch the type of the object.
A925 INC A Is it FF, which is free?
A926 JP Z,CheckMapObjectCollisions_Next Jump to CheckMapObjectCollisions_Next if so.
A929 LD A,(IX+$13) Fetch the state of the object.
A92C AND %00001111 Keep the bottom four bits.
A92E CP $0B Jump to CheckMapObjectCollisions_Next if the state is 0B.
A930 JP Z,CheckMapObjectCollisions_Next
A933 BIT 7,(IX+$10) Jump to CheckMapObjectCollisions_Next if the object is not on the screen.
A937 JP Z,CheckMapObjectCollisions_Next
A93A LD A,(IX+$12) Fetch the vertical position of the object on the screen.
A93D CP $28 Jump to CheckMapObjectCollisions_Next if it is too far up.
A93F JP C,CheckMapObjectCollisions_Next
A942 LD H,A Store it in H.
A943 LD A,(IX+$11) Fetch the horizontal position of the object on the screen.
A946 CP $30 Jump to CheckMapObjectCollisions_Next if it is too far to the left.
A948 JP C,CheckMapObjectCollisions_Next
A94B CP $A0 Jump to CheckMapObjectCollisions_Next if it is too far to the right.
A94D JP NC,CheckMapObjectCollisions_Next
A950 LD L,A Store it in L.
A951 LD ($ABA4),HL Store the position of the object as the first box.
A954 CALL FetchFrameSprite Find the sprite of the object.
A957 LD A,(DE) Fetch the width of the sprite in bytes.
A958 ADD A,A Multiply it by eight to get the width in pixels.
A959 ADD A,A Double A.
A95A ADD A,A Double A.
A95B LD ($ABA6),A Store it as the width of the first box.
A95E INC DE Move on to the height.
A95F LD A,(DE) Fetch the height of the sprite.
A960 LD ($ABA7),A Store it as the height of the first box.
A963 LD HL,($CE3A) Fetch the position of the ship.
A966 LD DE,($BA09) Fetch the size of the ship.
A96A LD ($AD46),IX Save the address of the slot.
A96E LD IX,$ABA4 Use the first box.
A972 CALL TestBoxesOverlap Test whether the boxes overlap.
A975 LD A,($5C1C) Fetch the result.
A978 AND A Jump to CheckMapObjectCollisions_Hit if they do.
A979 JR NZ,CheckMapObjectCollisions_Hit
CheckMapObjectCollisions_Next A97B POP IX Restore the address of the slot.
A97D LD BC,$001A Move on to the next slot...
A980 ADD IX,BC IX gains BC.
A982 POP BC Restore the slot counter.
A983 DEC B Decrease the slot counter.
A984 JP NZ,CheckMapObjectCollisions_Loop Jump back to CheckMapObjectCollisions_Loop for each slot.
A987 RET Return.
The ship has touched an object.
CheckMapObjectCollisions_Hit A988 LD IY,($AD46) Fetch the address of the slot.
A98C LD A,(IY+$00) Fetch the type of the object.
A98F CP $1B Jump to CheckMapObjectCollisions_Bounce unless it is type 1B.
A991 JR NZ,CheckMapObjectCollisions_Bounce
A993 LD A,(IY+$13) Fetch the state of the object.
A996 AND %00001111 Keep the bottom four bits.
A998 CP $04 Jump to CheckMapObjectCollisions_Refuel if the state is four.
A99A JR Z,CheckMapObjectCollisions_Refuel
A99C CP $05 Jump to CheckMapObjectCollisions_Bounce unless the state is five.
A99E JR NZ,CheckMapObjectCollisions_Bounce
CheckMapObjectCollisions_Refuel A9A0 LD HL,$4200 Use the value for a full fuel gauge.
A9A3 LD ($CC4B),HL Fill the fuel gauge.
A9A6 SET 4,(IY+$10) Mark the object to be removed.
A9AA LD A,(IY+$18) Fetch the position of the object in the map table.
A9AD AND %00000001 Keep the bits of A that are set in 01.
A9AF LD H,A H=A.
A9B0 LD L,(IY+$19) Read offset 19 of IY into L.
A9B3 LD DE,$5C94 The map table.
A9B6 ADD HL,DE HL gains DE.
A9B7 SET 7,(HL) Mark the entry in the map table as destroyed.
A9B9 LD A,$FF A=FF.
A9BB LD ($8FC3),A The damage counter.
A9BE CALL DamageShip_Hit Flash the ship.
A9C1 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 A9C4 LD A,$FF Set the flag for the ship bouncing.
A9C6 LD ($D0BC),A Update the collision kind.
A9C9 LD A,(IX+$00) Fetch the left edge of the box of the object.
A9CC CP $8B Bounce horizontally if it is 8B or more.
A9CE CALL NC,BounceHorizontally
A9D1 LD A,(IX+$00) Fetch the left edge of the box of the object.
A9D4 ADD A,(IX+$02) Add its width to get the right edge.
A9D7 CP $65 Bounce horizontally if it is less than 65.
A9D9 CALL C,BounceHorizontally
A9DC LD A,($C903) Fetch the vertical position of the ship.
A9DF LD H,A Store it in H.
A9E0 SUB E Subtract the height of the ship...
A9E1 INC A ...and add one to get the top of the ship.
A9E2 CP (IX+$01) Bounce vertically if the top of the ship is not above the object.
A9E5 CALL NC,BounceVertically
A9E8 LD A,($CCBA) Fetch the vertical scroll speed.
A9EB NEG Negate it.
A9ED BIT 7,A Jump to CheckMapObjectCollisions_Done if it is negative.
A9EF JR NZ,CheckMapObjectCollisions_Done
A9F1 LD A,(IX+$01) Fetch the bottom edge of the box of the object.
A9F4 SUB (IX+$03) Subtract its height.
A9F7 ADD A,$09 Add nine.
A9F9 CP H Bounce vertically if that is not above the bottom of the ship.
A9FA CALL NC,BounceVertically
CheckMapObjectCollisions_Done A9FD POP IX Restore the address of the slot.
A9FF POP BC Restore the slot counter.
AA00 RET Return.
Prev: A8D9 Up: Map Next: AA01