Prev: 26668 Up: Map Next: 26783
26674: 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 26674 LD HL,26783 HL=Table_SnapdragonDefinition.
26677 LD A,(24517) B=*CurrentRoom.
26680 LD B,A
AnimateSnapdragons_Loop 26681 LD A,(HL) Fetch the room number for this snapdragon.
26682 CP 255 Return if the terminator has been reached (this is the end of the table).
26684 RET Z
26685 CP B Call AnimateSnapdragon if this snapdragon is in the current room.
26686 CALL Z,AnimateSnapdragon
Advance to the next table entry (4 bytes per snapdragon).
26689 INC HL Advance HL by four.
26690 INC HL
26691 INC HL
26692 INC HL
26693 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 26695 PUSH HL Stash the snapdragon table pointer on the stack.
Advance to the animation counter and cycle it through 0-2.
26696 INC HL Advance to the animation counter byte.
26697 INC (HL) Increment the animation counter.
26698 LD A,(HL) A=*HL.
26699 CP 3 Jump to AnimateSnapdragon_CheckDirection if the animation counter hasn't reached 3 yet.
26701 JR NZ,AnimateSnapdragon_CheckDirection
26703 XOR A Reset the animation counter back to 0.
26704 LD (HL),A
Determine whether the snapdragon should face toward Percy based on his character column position. If Percy is to the right, 3 is added to the frame index to use the right-facing set.
AnimateSnapdragon_CheckDirection 26705 PUSH AF Stash the animation frame on the stack.
Calculate Percy's character column (X position / 8).
26706 LD A,(56000) A=*Percy_X_Position (Percy's X position).
26709 RRCA Rotate right three positions (divide by 8).
26710 RRCA
26711 RRCA
26712 AND %00011111 Keep only bits 0-4 (character column 0-31).
26714 LD C,A Store the result in C.
Compare Percy's column with the snapdragon's column from the table.
26715 INC HL Advance to the snapdragon's position byte.
26716 LD A,(HL) A=*HL.
26717 AND %00011111 Keep only bits 0-4 (snapdragon's character column).
26719 CP C Jump to AnimateSnapdragon_FacingLeft if Percy is to the left of the snapdragon.
26720 JR NC,AnimateSnapdragon_FacingLeft
Percy is to the right so add 3 to use the right-facing frames.
26722 POP AF Restore the animation frame from the stack.
26723 ADD A,3 A+=3.
26725 JR AnimateSnapdragon_LookupGraphic Jump to AnimateSnapdragon_LookupGraphic.
AnimateSnapdragon_FacingLeft 26727 POP AF Restore the animation frame from the stack.
Look up the graphic data for the current frame. Each frame is 32 bytes, stored from Sprite_12 onwards. Frames 0-2 face left, frames 3-5 face right.
Frame Sprite ID Sprite Frame Sprite ID Sprite
Left Right
0 18 udg44379-56x4 3 21 udg44475-56x4
1 19 udg44411-56x4 4 22 udg44507-56x4
2 20 udg44443-56x4 5 23 udg44539-56x4
AnimateSnapdragon_LookupGraphic 26728 LD DE,44379 DE=Sprite_12 (snapdragon graphic data).
26731 LD H,0 H=0.
26733 LD L,A L=A.
26734 ADD HL,HL Multiply HL by 32 (bytes per frame).
26735 ADD HL,HL
26736 ADD HL,HL
26737 ADD HL,HL
26738 ADD HL,HL
26739 ADD HL,DE Add the graphic data base address.
26740 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.
26741 POP HL Restore the snapdragon table pointer from the stack.
26742 PUSH HL Keep a copy of the snapdragons table pointer on the stack.
26743 INC HL Advance to the screen position bytes.
26744 INC HL
26745 LD C,(HL) Load the screen position into HL (using the stack).
26746 INC HL
26747 LD B,(HL)
26748 PUSH BC
26749 POP HL
Draw the top-left and bottom-left cells.
26750 PUSH HL Stash the screen position twice on the stack.
26751 PUSH HL
26752 CALL Handler_DrawWorm_Frame Call Handler_DrawWorm_Frame to draw the top-left cell.
26755 POP HL Restore the screen position from the stack.
26756 LD BC,32 Add 0032 to move down one character row.
26759 ADD HL,BC
26760 CALL Handler_DrawWorm_Frame Call Handler_DrawWorm_Frame to draw the bottom-left cell.
Draw the top-right and bottom-right cells.
26763 POP HL Restore the screen position from the stack.
26764 INC L Move one character column to the right.
26765 PUSH HL Stash the adjusted position on the stack.
26766 CALL Handler_DrawWorm_Frame Call Handler_DrawWorm_Frame to draw the top-right cell.
26769 POP HL Restore the position from the stack.
26770 LD BC,32 Add 0032 to move down one character row.
26773 ADD HL,BC
26774 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.
26777 POP HL Restore the snapdragon table pointer from the stack.
26778 LD A,(24517) B=*CurrentRoom.
26781 LD B,A
26782 RET Return.
Prev: 26668 Up: Map Next: 26783