Prev: AB9A Up: Map Next: AD0D
AC3C: Test for collision with hazard
The hit handler for the static hazards, the barriers and tumbleweeds, hooked into every slot that spawn_hazards spawns.
IX[15] is a three-state machine. 0 is the untouched state: return unless IX[7] shows a hit, otherwise look the wobble parameters up by hero speed, stash them in IX[17] and IX[18], scale the approach speed, play the hit effect and move to state 2. 2 is the wobble itself: each call steps IX[16] through the amplitude table, decays the speed by a thirty-second, toggles the inverted flag and counts IX[18] down, and at zero it clears the speed and the flag and drops to state 1. 1 is finished, and returns at once.
If IX[15] is non-zero then jump forward.
Input
IX Address of hazard structure ($A188+)
hazard_hit AC3C LD A,(IX+$0F) IX[15] is the hit state: 0 untouched, 2 wobbling, 1 finished
AC3F AND A If IX[15] != 0 then goto hh_dec_test
AC40 JR NZ,hh_dec_test
IX[15] is zero.
AC42 LD A,(IX+$07) If IX[7] (hit counter) == 0 then return
AC45 AND A
AC46 RET Z
If we arrive here then a hit has occurred.
AC47 LD DE,($A24A) Load speed
AC4B JP P,hh_wobble_from_speed If IX[7] (hit counter) < 0 then DE = 280
AC4E LD DE,$0118
hh_wobble_from_speed AC51 LD B,D BC = DE
AC52 LD C,E
AC53 LD HL,$AD03 Point HL at wobble_params_by_speed table
This must be mapping the speed into the 5-entry array.
AC56 LD A,D A = D -- top part of speed
AC57 RL E E ROL 1 -- double speed
AC59 RLA A ROL 1
AC5A AND $03 A &= 3 -- mask top part to 3 (for ref. turbo speed = $1FF)
AC5C RR D RR D -- bit 0 of the speed's high byte into carry, added below
AC5E LD D,$00 D = 0
AC60 ADC A,D A = (A + D + carry) * 2 -- scale for element size of 2
AC61 ADD A,A
AC62 LD E,A E = A -- it's now an offset into wobble_params_by_speed
AC63 ADD HL,DE HL += DE
Copy two bytes to IX+17 from table
AC64 LD A,(HL)
AC65 LD (IX+$11),A
AC68 INC HL
AC69 LD A,(HL)
AC6A LD (IX+$12),A -- IX[18] is the wobble countdown during a hit
AC6D SLA C BC = speed * 2
AC6F RL B
AC71 LD A,B If that is $200 or more cap it at 350
AC72 CP $02
AC74 JR C,hh_set_horz_pos
AC76 LD BC,$015E
hh_set_horz_pos AC79 LD (IX+$0D),C Set the approach rate's low byte
AC7C INC (IX+$07) Increment hit counter
AC7F JR Z,hh_start_sfx If counter is zero then don't store it
AC81 LD (IX+$0E),B Set the approach rate's high byte
hh_start_sfx AC84 INC (IX+$01) Increment IX[1] -- distance/buffer offset
AC87 LD BC,$0503 Effect 5 (hazard hit), Priority 3
AC8A CALL start_sfx Call start_sfx
AC8D LD A,$02 A = 2 [set this to 1 and the hazard drives off like a car]
AC8F LD (IX+$0F),A Set IX[15] to 2 -- hit state: wobbling
hh_dec_test AC92 DEC A If --A == 0 return
AC93 RET Z
hh_set_wobble_amplitude AC94 LD HL,$ACDB IX[16] = wobble_amplitudes[IX[17]]
AC97 LD C,(IX+$11)
AC9A LD B,$00
AC9C ADD HL,BC
AC9D LD A,(HL)
AC9E LD (IX+$10),A
ACA1 INC (IX+$11) Increment IX[17]
ACA4 LD H,(IX+$0E) Load the approach rate into HL
ACA7 LD L,(IX+$0D)
ACAA LD D,H DE = HL
ACAB LD E,L
ACAC SRL D Divide the approach rate by 2
ACAE RR E
ACB0 SRL E Then by 16 once it's 8 bits
ACB2 SRL E
ACB4 SRL E
ACB6 SRL E
ACB8 SBC HL,DE Then subtract from the previous position
ACBA LD (IX+$0E),H Set horizontal position
ACBD LD (IX+$0D),L
ACC0 LD A,(IX+$13) Toggle the bottom bit of IX[19]
ACC3 XOR $01
ACC5 LD (IX+$13),A
ACC8 DEC (IX+$12) Decrement IX[18]
ACCB RET NZ If IX[19] != 0 then return
ACCC XOR A Zero the horizontal position
ACCD LD (IX+$0D),A
ACD0 LD (IX+$0E),A
ACD3 INC A Set IX[19] to 1
ACD4 LD (IX+$13),A
ACD7 LD (IX+$0F),A Set IX[15] to 1
ACDA RET Return
wobble_amplitudes ACDB DEFB $19,$28,$32,$37,$39,$37,$32,$28 hh_set_wobble_amplitude uses this
ACE3 DEFB $19,$00,$0F,$19,$1F,$22,$24,$22
ACEB DEFB $1F,$19,$0F,$00,$0A,$10,$13,$15
ACF3 DEFB $13,$10,$0A,$00,$06,$09,$0B,$09
ACFB DEFB $06,$00,$02,$00,$02,$00,$01,$00
wobble_params_by_speed AD03 DEFW $0622 AC53 uses this
AD05 DEFW $0C1C
AD07 DEFW $0E14
AD09 DEFW $120A
AD0B DEFW $1400
Prev: AB9A Up: Map Next: AD0D