Prev: AD0D Up: Map Next: ADA0
AD51: Hazard collision
Returns 1, and arms the hazard's hit timer, only if all of these hold: the hit timer is zero, so this hazard is not still in its cooldown; the horizontal clip is zero, so the hazard is fully on screen; the distance is under the threshold, 2 or 3 depending on the hazard's flags; the sign of fast_counter passes the speed gate for that distance; and the horizontal position overlaps the car's zone, $68 to $8F.
The hit timer written is the severity: 1 for a glancing blow at close range, up to 4 for a strike dead centre.
Used by the routines at check_hazard_collisions and advance_hazards.
Input
D Initialised to zero (when return value is required)
IX Address of a hazard structure
Output
D Return value
L Hazard[2]. AE7A, the only caller that could use it, discards it: it writes horz_pos and horz_clip before the CALL and never reads them back
H Hazard[3]. Discarded likewise
check_collision AD51 LD A,(IX+$07) Return if hit counter is non-zero
AD54 AND A
AD55 RET NZ
Otherwise we're... ?
AD56 LD L,(IX+$02) L = horizontal position, H = ?
AD59 LD H,(IX+$03)
AD5C LD A,H Return if top byte of HL was non-zero
AD5D AND A
AD5E RET NZ
AD5F LD A,(IX+$0F) A = IX[15] + 1 and set flags -- hazard anim counter thing
AD62 INC A
AD63 LD A,(IX+$01) A = IX[1] -- buffer offset/distance
AD66 LD C,$03 C = 3
AD68 JR NZ,ccl_1 Jump if (IX[15] + 1) was non-zero
AD6A LD C,$02 C = 2
ccl_1 AD6C CP C Return if distance >= C
AD6D RET NC
AD6E LD E,$04 E = 4
AD70 DEC A Reduce distance by 1
AD71 LD A,($A23F) Load fast_counter
AD74 JR NZ,ccl_2 Jump if A-- was non-zero
AD76 AND A Set flags for fast_counter
AD77 JP P,ccl_check_horz_pos Jump if positive
Otherwise zero or negative?
AD7A LD E,$01 E = 1
AD7C JR ccl_check_horz_pos Jump
ccl_2 AD7E AND A Set flags for fast_counter
AD7F RET P Return if positive
ccl_check_horz_pos AD80 LD A,L A = (horizontal position) & $F8
AD81 AND $F8
AD83 CP $90 Return if A >= 144
AD85 RET NC
AD86 ADD A,(IX+$08) A += IX[8] -- from hazard data table
AD89 CP $70 Return if A <= 112
AD8B RET C
AD8C SUB (IX+$08) A -= IX[8]
AD8F CP $68 Jump if A < 104
AD91 JR C,ccl_exit
AD93 DEC E E--
AD94 CP $78 Jump if A < 120
AD96 JR C,ccl_exit
AD98 INC E E += 2
AD99 INC E
ccl_exit AD9A LD (IX+$07),E IX[7] (hit_timer) = E -- 1 for a glancing blow, 2 normal, 4 for a dead centre strike
AD9D LD D,$01 D = 1 -- the collision return value. D doubles as the no-hit value the caller preloads and as the hit flag set here
AD9F RET Return
Prev: AD0D Up: Map Next: ADA0