Prev: 9D41 Up: Map Next: 9E04
9D91: Handler: Flame
Handles a flame (sprite IDs 34-37) which has been started by SpawnFlame. A flame which is not in the player's room is counted off by ExpireActor. In the player's room it burns for a limited time, drifting around in a random direction (which is changed by ChooseFlameDirection whenever its timer runs out or it is blocked) and bouncing off the edges of the screen. It flickers by changing sprite and colour every time it is handled, and it plays a crackling sound. If it touches the player (while the player is coloured INK:WHITE, PAPER:BLACK (BRIGHT)) the player is hit. When its time is up, or the player is dead, the flame is blown up.
Input
IX Flame record
Count off the flame if it is not in the same room as the player.
HandlerFlame 9D91 LD A,($9703) Fetch the room of the player from 9703.
9D94 CP (IX+$01) Jump to ExpireActor if the flame is in a different room to the player.
9D97 JP NZ,ExpireActor
9D9A LD A,$17 Write 17 to Actor_Width (the width of the flame).
9D9C LD ($96AD),A
9D9F CALL StoreEntity Remember the previous position of the flame.
Explode the flame if the player is not alive.
9DA2 LD A,($9702) Fetch the sprite ID of the player.
9DA5 SUB $10 Subtract 10 (the first Sabreman sprite ID).
9DA7 CP $20 Jump to BlowUpActor if the player is not alive.
9DA9 JP NC,BlowUpActor
Explode the flame when its lifetime runs out.
9DAC DEC (IX+$08) Decrease the lifetime of the flame by one and jump to BlowUpFlame if it has run out.
9DAF JP Z,BlowUpFlame
Choose a new direction when the direction timer has run out.
9DB2 DEC (IX+$02) Decrease the direction timer by one and choose a new direction if it has run out.
9DB5 CALL Z,ChooseFlameDirection
Work out the new position of the flame and bounce off the edges of the screen.
9DB8 CALL CalculateNewPosition Work out the new position of the flame.
9DBB BIT 0,B Jump to BounceFlameHorizontally if the flame has hit the left or right edge of the screen.
9DBD JR NZ,BounceFlameHorizontally
9DBF BIT 1,B Jump to BounceFlameVertically if the flame has hit the top or bottom edge of the screen.
9DC1 JR NZ,BounceFlameVertically
This entry point is used by the routines at BounceFlameHorizontally and BounceFlameVertically.
Stop the flame moving through objects in the room. If it did not manage to move then choose a new direction.
HandlerFlame_Move 9DC3 LD BC,$170F Set the height of the flame in B to 17 and the width in C to 0F.
9DC6 CALL SlideActorPastObjects Stop the flame passing through objects in the room.
9DC9 CALL TestPositionUnchanged Test whether the flame has stayed where it was.
9DCC CALL Z,ChooseFlameDirection Choose a new direction if the flame has stayed where it was.
Flicker the flame by choosing one of the four flame sprites and a colour at random.
9DCF LD A,($9695) Fetch the random seed from RandomNumber.
9DD2 AND %00000011 Keep only bits 0-1.
9DD4 OR %00110100 Set bits 2, 4-5.
9DD6 LD (IX+$00),A Set the sprite ID of the flame.
9DD9 CALL ChooseFlameColour Choose a colour for the flame.
9DDC LD (IX+$05),A Set the colour of the flame.
Store the new position.
9DDF LD (IX+$03),E Set the X position of the flame.
9DE2 LD (IX+$04),D Set the Y position of the flame.
Hit the player if the flame touches the player, but only if the player is coloured INK:WHITE, PAPER:BLACK (BRIGHT).
9DE5 LD A,($9707) Fetch the colour of the player from 9707.
9DE8 CP $47 Jump to HandlerFlame_Draw if the player is not coloured INK:WHITE, PAPER:BLACK (BRIGHT).
9DEA JR NZ,HandlerFlame_Draw
9DEC LD BC,$130F Set the height of the flame in B to 13 and the width in C to 0F.
9DEF CALL TestPlayerTouchingActor Test whether the flame is touching the player.
9DF2 JR NC,HandlerFlame_Draw Jump to HandlerFlame_Draw if the flame is not touching the player.
9DF4 LD A,($9705) Fetch the X position of the player from 9705.
9DF7 RLCA Rotate bit 7 (which half of the screen the player is in) into bit 0.
9DF8 AND %00000001 Keep only bit 0.
9DFA INC A Add one, so the hit direction is 01 or 02.
9DFB LD ($9704),A Store the hit direction in 9704 (the player's state).
Draw the flame and make the crackling sound.
HandlerFlame_Draw 9DFE CALL DisplayActor Display the flame.
9E01 JP PlayFlameSound Jump to PlayFlameSound to play the flame sound.
Prev: 9D41 Up: Map Next: 9E04