Prev: 682C Up: Map Next: 689F
6832: Animate Snapdragons
Used by the routine at Run_Game_Frame.
Animates the snapdragons in the current room. Each snapdragon has a 3-frame snapping animation and faces toward Percy based on his horizontal position.
Snapdragon definitions are stored in a table at Table_SnapdragonDefinition.
AnimateSnapdragons 6832 LD HL,$689F HL=Table_SnapdragonDefinition.
6835 LD A,($5FC5) B=*CurrentRoom.
6838 LD B,A
AnimateSnapdragons_Loop 6839 LD A,(HL) Fetch the room number for this snapdragon.
683A CP $FF Return if the terminator has been reached (this is the end of the table).
683C RET Z
683D CP B Call AnimateSnapdragon if this snapdragon is in the current room.
683E CALL Z,AnimateSnapdragon
Advance to the next table entry (04 bytes per snapdragon).
6841 INC HL Advance HL by four.
6842 INC HL
6843 INC HL
6844 INC HL
6845 JR AnimateSnapdragons_Loop Jump to AnimateSnapdragons_Loop to process the next entry.
Processes a single snapdragon. Cycles the animation frame, determines whether the snapdragon should face left or right based on Percy's position, looks up the graphic data and draws the snapdragon to the screen.
AnimateSnapdragon 6847 PUSH HL Stash the snapdragon table pointer on the stack.
Advance to the animation counter and cycle it through 00-02.
6848 INC HL Advance to the animation counter byte.
6849 INC (HL) Increment the animation counter.
684A LD A,(HL) A=*HL.
684B CP $03 Jump to AnimateSnapdragon_CheckDirection if the animation counter hasn't reached 03 yet.
684D JR NZ,AnimateSnapdragon_CheckDirection
684F XOR A Reset the animation counter back to 00.
6850 LD (HL),A
Determine whether the snapdragon should face toward Percy based on his character column position. If Percy is to the right, 03 is added to the frame index to use the right-facing set.
AnimateSnapdragon_CheckDirection 6851 PUSH AF Stash the animation frame on the stack.
Calculate Percy's character column (X position / 8).
6852 LD A,($DAC0) A=*Percy_X_Position (Percy's X position).
6855 RRCA Rotate right three positions (divide by 08).
6856 RRCA
6857 RRCA
6858 AND %00011111 Keep only bits 0-4 (character column 00-1F).
685A LD C,A Store the result in C.
Compare Percy's column with the snapdragon's column from the table.
685B INC HL Advance to the snapdragon's position byte.
685C LD A,(HL) A=*HL.
685D AND %00011111 Keep only bits 0-4 (snapdragon's character column).
685F CP C Jump to AnimateSnapdragon_FacingLeft if Percy is to the left of the snapdragon.
6860 JR NC,AnimateSnapdragon_FacingLeft
Percy is to the right so add 03 to use the right-facing frames.
6862 POP AF Restore the animation frame from the stack.
6863 ADD A,$03 A+=03.
6865 JR AnimateSnapdragon_LookupGraphic Jump to AnimateSnapdragon_LookupGraphic.
AnimateSnapdragon_FacingLeft 6867 POP AF Restore the animation frame from the stack.
Look up the graphic data for the current frame. Each frame is 20 bytes, stored from Sprite_12 onwards. Frames 00-02 face left, frames 03-05 face right.
Frame Sprite ID Sprite Frame Sprite ID Sprite
Left Right
00 12 udg44379-56x4 03 15 udg44475-56x4
01 13 udg44411-56x4 04 16 udg44507-56x4
02 14 udg44443-56x4 05 17 udg44539-56x4
AnimateSnapdragon_LookupGraphic 6868 LD DE,$AD5B DE=Sprite_12 (snapdragon graphic data).
686B LD H,$00 H=00.
686D LD L,A L=A.
686E ADD HL,HL Multiply HL by 20 (bytes per frame).
686F ADD HL,HL
6870 ADD HL,HL
6871 ADD HL,HL
6872 ADD HL,HL
6873 ADD HL,DE Add the graphic data base address.
6874 EX DE,HL Exchange so DE points to the graphic data.
Retrieve the snapdragon's screen position from the table and draw it as a 2x2 character cell graphic.
6875 POP HL Restore the snapdragon table pointer from the stack.
6876 PUSH HL Keep a copy of the snapdragons table pointer on the stack.
6877 INC HL Advance to the screen position bytes.
6878 INC HL
6879 LD C,(HL) Load the screen position into HL (using the stack).
687A INC HL
687B LD B,(HL)
687C PUSH BC
687D POP HL
Draw the top-left and bottom-left cells.
687E PUSH HL Stash the screen position twice on the stack.
687F PUSH HL
6880 CALL Handler_DrawWorm_Frame Call Handler_DrawWorm_Frame to draw the top-left cell.
6883 POP HL Restore the screen position from the stack.
6884 LD BC,$0020 Add 0020 to move down one character row.
6887 ADD HL,BC
6888 CALL Handler_DrawWorm_Frame Call Handler_DrawWorm_Frame to draw the bottom-left cell.
Draw the top-right and bottom-right cells.
688B POP HL Restore the screen position from the stack.
688C INC L Move one character column to the right.
688D PUSH HL Stash the adjusted position on the stack.
688E CALL Handler_DrawWorm_Frame Call Handler_DrawWorm_Frame to draw the top-right cell.
6891 POP HL Restore the position from the stack.
6892 LD BC,$0020 Add 0020 to move down one character row.
6895 ADD HL,BC
6896 CALL Handler_DrawWorm_Frame Call Handler_DrawWorm_Frame to draw the bottom-right cell.
Restore the snapdragon table pointer and reload the current room number.
6899 POP HL Restore the snapdragon table pointer from the stack.
689A LD A,($5FC5) B=*CurrentRoom.
689D LD B,A
689E RET Return.
Prev: 682C Up: Map Next: 689F