Prev: A8A5 Up: Map Next: AA01
A8F4: Test the ship against the ground objects
Used by the routine at ship_pass.
Once a pass (ship_pass). The ship's box is 40 pixels wide from x=$64 and as high as its picture, at its y, both less this pass's scroll steps (scroll_down: across, up and down). Each of the first four ground-object records that is on the screen, between line $28 and the bottom and between x=$30 and $A0, and not of kind $0B, is boxed by its last drawn position and its graphic's size, and tested (boxes_overlap). At the first one that touches:
A refuel pad -- graphic $1B in frame 4 or 5, the fuel station's two frames (map kind $0E, object_part_pairs) -- fills the fuel (fuel), is used up (freed next pass and marked gone in map_object_kinds), and repairs the ship: the hit count (hit_count) is set to $FF before calling the damage handler in contact_damage, whose count then wraps to 0 and colours the ship white again. This branch never ran in the build's sessions.
Anything else is solid: the collision flag trail_collision is set (so draw_ship redraws the ship's trail), and the ship bounces -- across (bounce_across) if the object lies beyond either side of the ship, up or down (bounce_up_down) if the ship's top is level with or below the object's bottom, and again up or down if, while the vertical scroll step is not positive, the ship's bottom is within nine lines below the object's top.
ship_hits_ground_objects A8F4 LD A,(launch_state) Not once the rocket is launching (launch_state)
A8F7 AND A
A8F8 RET NZ
A8F9 LD B,$04 The four records
A8FB LD IX,ground_objects
A8FF LD HL,(ship_screen_x) The ship's box: x=$64 and y less the scroll steps
A902 LD L,$64
A904 LD A,(scroll_across)
A907 NEG
A909 ADD A,L
A90A LD L,A
A90B LD A,(scroll_down)
A90E NEG
A910 ADD A,H
A911 LD H,A
A912 LD (box_x),HL
A915 LD D,$28 40 pixels wide, the ship's height tall (kept in collision_object)
A917 LD A,(ship_height)
A91A LD E,A
A91B LD (collision_object),DE
ship_hits_ground_objects_0 A91F PUSH BC
A920 PUSH IX
A922 LD A,(IX+$00) A free record
A925 INC A
A926 JP Z,ship_hits_ground_objects_1
A929 LD A,(IX+$13) Kind $0B is never collided with
A92C AND $0F
A92E CP $0B
A930 JP Z,ship_hits_ground_objects_1
A933 BIT 7,(IX+$10) Not on the screen
A937 JP Z,ship_hits_ground_objects_1
A93A LD A,(IX+$12) Only from line $28 down and between x=$30 and $A0
A93D CP $28
A93F JP C,ship_hits_ground_objects_1
A942 LD H,A
A943 LD A,(IX+$11)
A946 CP $30
A948 JP C,ship_hits_ground_objects_1
A94B CP $A0
A94D JP NC,ship_hits_ground_objects_1
A950 LD L,A Box the object: where it was drawn, its graphic's width in pixels and height
A951 LD (collision_box),HL
A954 CALL object_graphic
A957 LD A,(DE)
A958 ADD A,A
A959 ADD A,A
A95A ADD A,A
A95B LD (collision_box_size),A
A95E INC DE
A95F LD A,(DE)
A960 LD ($ABA7),A
A963 LD HL,(box_x) Test the two boxes
A966 LD DE,(collision_object)
A96A LD (current_object),IX
A96E LD IX,collision_box
A972 CALL boxes_overlap
A975 LD A,(scratch_count) Touching?
A978 AND A
A979 JR NZ,ship_hits_ground_objects_2
ship_hits_ground_objects_1 A97B POP IX Next record
A97D LD BC,$001A
A980 ADD IX,BC
A982 POP BC
A983 DEC B
A984 JP NZ,ship_hits_ground_objects_0
A987 RET
ship_hits_ground_objects_2 A988 LD IY,(current_object) A refuel pad, graphic $1B in frame 4 or 5 (the fuel station)?
A98C LD A,(IY+$00)
A98F CP $1B
A991 JR NZ,ship_hits_ground_objects_4
A993 LD A,(IY+$13)
A996 AND $0F
A998 CP $04
A99A JR Z,ship_hits_ground_objects_3
A99C CP $05
A99E JR NZ,ship_hits_ground_objects_4
ship_hits_ground_objects_3 A9A0 LD HL,$4200 Fill the fuel
A9A3 LD (fuel),HL
A9A6 SET 4,(IY+$10) Free the pad next pass
A9AA LD A,(IY+$18) And mark it gone in the world's object table
A9AD AND $01
A9AF LD H,A
A9B0 LD L,(IY+$19)
A9B3 LD DE,map_object_kinds
A9B6 ADD HL,DE
A9B7 SET 7,(HL)
A9B9 LD A,$FF Repair the ship: the hit count wraps to zero in the damage handler, which colours the ship white
A9BB LD (hit_count),A
A9BE CALL damage_ship
A9C1 JP ship_hits_ground_objects_5
ship_hits_ground_objects_4 A9C4 LD A,$FF Something solid was hit
A9C6 LD (trail_collision),A
A9C9 LD A,(IX+$00) The object's box (IX is the box now) beyond x=$8B or ending short of x=$65: bounce across
A9CC CP $8B
A9CE CALL NC,bounce_across
A9D1 LD A,(IX+$00)
A9D4 ADD A,(IX+$02)
A9D7 CP $65
A9D9 CALL C,bounce_across
A9DC LD A,(ship_screen_y) The ship's top level with the object's bottom or lower: bounce up or down
A9DF LD H,A
A9E0 SUB E
A9E1 INC A
A9E2 CP (IX+$01)
A9E5 CALL NC,bounce_up_down
A9E8 LD A,(scroll_down) Not while the vertical scroll step is positive
A9EB NEG
A9ED BIT 7,A
A9EF JR NZ,ship_hits_ground_objects_5
A9F1 LD A,(IX+$01) The ship's bottom within nine lines below the object's top: bounce up or down
A9F4 SUB (IX+$03)
A9F7 ADD A,$09
A9F9 CP H
A9FA CALL NC,bounce_up_down
ship_hits_ground_objects_5 A9FD POP IX
A9FF POP BC
AA00 RET
Prev: A8A5 Up: Map Next: AA01