← CBDC Advance an object's animation Map CC56 → Update the objects' behaviors
CBFE: Spawn and death reaction state machine
The reaction state machine shared by every inhabitant handler. It animates an object's spawn and its death. Every other reaction state passes through to the handler.
Input
IX the object's 9-byte sprite record (one slot of object_table)
IY the object's 16-byte logic record (layout at obj2_record)
Output
F carry set if a reaction ran (skip the normal update); clear to proceed
The spawn reaction plays a 10-frame spawn animation. On its first played frame it sets the sprite's active flag and arms the spawn sound. At the end it leaves the inhabitant live.
The death reaction plays a 16-frame animation. On its first frame it arms the death burst sound. At the end it empties the slot and clears the sprite's active flag so nothing draws it. The animation step advances a frame every other call, so each animation spans twice its frame count in game frames. That is 20 game frames for spawn and 32 for death.
Death means the same for every handler that sets it. Each handler calls this machine before its update. Only the warp gate first pins its position. While a reaction is in progress the machine tells the handler to skip its own code for every frame of the animation. No handler can therefore cut a death short or clear it early. It always runs to the end that empties the slot.
There is therefore no inhabitant that starts dying, springs back and carries on. The object is destroyed and its pool slot freed. That holds whether the death came from a ball kill or the sweep. It holds equally for an overlap with a named slot or a blocked step.
The knock-backs objects do survive are handler-private states instead: the starburst's ball-knock and the orb's chew and spit. Those run in the handler, which this machine passes through when no reaction is in progress.
inhabitant_react_state CBFE LD A,(IY+$0C) Read the reaction state; with none in progress the handler proceeds normally.
CC01 OR A
CC02 JR Z,react_idle
CC04 CP $01 The spawn animation
CC06 JR NZ,react_check_dying
CC08 LD A,(IY+$0B) On the first played frame only, activate the sprite and arm the spawn sound.
CC0B CP $01
CC0D JR NZ,play_spawn_anim
CC0F SET 0,(IX+$08) Set the sprite's active flag so it becomes visible.
CC13 LD A,$01 Arm the 9-step spawn sound.
CC15 LD (spawn_counter),A
play_spawn_anim CC18 LD HL,anim_ball_b_spawn+$14 Advance the spawn animation through its 10-frame table.
CC1B CALL advance_anim
CC1E LD A,(IY+$0B) When the animation frame reaches the end of its sequence, the spawn is complete.
CC21 CP $0A
CC23 JR NZ,react_spawn_busy
CC25 XOR A Reset the animation frame and clear state – the inhabitant is now live.
CC26 LD (IY+$0B),A
CC29 LD (IY+$0C),A
react_spawn_busy CC2C SCF Carry set: a reaction ran this frame, so the handler skips its normal update.
CC2D RET
react_check_dying CC2E CP $02 The death animation; any other state proceeds normally.
CC30 JR NZ,react_idle
CC32 LD A,(IY+$0B) On the first frame only, arm the death sound.
CC35 OR A
CC36 JR NZ,play_death_anim
CC38 LD A,$01 Arm the 14-step death burst.
CC3A LD (death_burst_counter),A
play_death_anim CC3D LD HL,anim_death_burst+$2 Advance the death animation from its 16-frame table.
CC40 CALL advance_anim
CC43 LD A,(IY+$0B) The death animation is complete once the animation frame runs off the end of its sequence.
CC46 CP $10
CC48 JR NZ,react_death_busy
CC4A XOR A Empty the slot: clear its type so the inhabitant loop skips it from now on.
CC4B LD (IY+$08),A
CC4E RES 0,(IX+$08) Clear the sprite's active flag so nothing draws it.
react_death_busy CC52 SCF Carry set: a reaction ran this frame, skip the normal update.
CC53 RET
react_idle CC54 AND A Carry clear: no reaction in progress, the handler does its normal update.
CC55 RET
← CBDC Advance an object's animation Map CC56 → Update the objects' behaviors
Fork me on GitHub