Prev: 631F Up: Map Next: 63BB
6338: Update Percy Animation
Used by the routine at MainGameLoop.
Update Percy's animation frame based on the current movement state and direction. The animation counter at *PercyAnimationCounter cycles through frames, with bit 7 indicating the second half of the cycle.
Input
IX Pointer to Percy's state data
UpdatePercyAnimation 6338 LD A,($5FB0) A=*PercyAnimationCounter.
633B BIT 7,A Jump to UpdatePercyAnimation_SecondHalf if in the second half of the cycle.
633D JR NZ,UpdatePercyAnimation_SecondHalf
First half so increment the counter.
633F INC A Increment A.
6340 CP $05 Jump to UpdatePercyAnimation_SwitchToSecondHalf if the counter has reached 05 (switch to second half).
6342 JR Z,UpdatePercyAnimation_SwitchToSecondHalf
6344 LD ($5FB0),A Write A to *PercyAnimationCounter.
6347 JR UpdatePercyAnimation_SetFrame Jump to UpdatePercyAnimation_SetFrame.
Second half so decrement the counter.
UpdatePercyAnimation_SecondHalf 6349 AND %00000111 Keep only bits 0-2 (frame index).
634B DEC A Decrement the frame index.
634C OR A Jump to UpdatePercyAnimation_SwitchToFirstHalf if the frame index has reached zero.
634D JR Z,UpdatePercyAnimation_SwitchToFirstHalf
634F ADD A,$80 Write A + 80 (keep bit 7 set) to *PercyAnimationCounter.
6351 LD ($5FB0),A
6354 JR UpdatePercyAnimation_SetFrame Jump to UpdatePercyAnimation_SetFrame.
Switch to the second half of the animation cycle.
UpdatePercyAnimation_SwitchToSecondHalf 6356 LD A,$84 Write 84 to *PercyAnimationCounter.
6358 LD ($5FB0),A
635B JR UpdatePercyAnimation_SetFrame Jump to UpdatePercyAnimation_SetFrame.
Switch back to the first half of the animation cycle.
UpdatePercyAnimation_SwitchToFirstHalf 635D LD A,$01 Write 01 to *PercyAnimationCounter.
635F LD ($5FB0),A
Select Percy's sprite frame based on direction and animation state. Frames are arranged in groups:
Byte Range State
01-04 Flying right
05-08 Flying left
09-0C Walking/ Standing right
0D-10 Walking/ Standing left
UpdatePercyAnimation_SetFrame 6362 LD A,(IX+$00) Jump to UpdatePercyAnimation_ChooseFrame if Percy's current X position (*IX+00) is the same as his previous X position (*IX+40).
6365 CP (IX+$40)
6368 JR Z,UpdatePercyAnimation_ChooseFrame
Percy has moved horizontally so cycle the wing flap counter between
01 and 04.
636A LD A,($5FAF) A=*PercyFlapCounter.
636D INC A Increment the flap counter.
636E CP $05 Jump to UpdatePercyAnimation_StoreFlap if it hasn't reached 05 yet.
6370 JR NZ,UpdatePercyAnimation_StoreFlap
6372 LD A,$01 Reset the flap counter to 01.
UpdatePercyAnimation_StoreFlap 6374 LD ($5FAF),A Write A to *PercyFlapCounter.
Determine whether Percy is airborne or grounded, and facing left or right.
UpdatePercyAnimation_ChooseFrame 6377 LD A,(IX+$01) Jump to UpdatePercyAnimation_Grounded if Percy's Y position (*IX+01) is on the ground, or if *LandedOnPlatformFlag is set (and percy has landed on a platform).
637A CP $90
637C JR NC,UpdatePercyAnimation_Grounded
637E LD A,($5FAD)
6381 OR A
6382 JR NZ,UpdatePercyAnimation_Grounded
Percy is airborne so select flying frame based on direction.
6384 LD A,($5FA5) Jump to UpdatePercyAnimation_FlyingRight if *PercyFacingDirection is unset (Percy is facing right).
6387 OR A
6388 JR Z,UpdatePercyAnimation_FlyingRight
Flying left: frame = flap counter + 00.
638A LD A,($5FB0) A=*PercyAnimationCounter.
638D AND %00000111 Keep only bits 0-2 (animation frame index).
638F LD (IX+$03),A Write A to *IX+03.
6392 RET Return.
Flying right: frame = flap counter + 04.
UpdatePercyAnimation_FlyingRight 6393 LD A,($5FB0) A=*PercyAnimationCounter.
6396 AND %00000111 Keep only bits 0-2.
6398 ADD A,$04 Write A + 04 to *IX+03.
639A LD (IX+$03),A
639D RET Return.
Percy is on the ground or landed so select grounded frame.
UpdatePercyAnimation_Grounded 639E LD A,$01 Write 01 to *MovementSpeed (reset movement speed).
63A0 LD ($5FAE),A
63A3 LD A,($5FA5) Jump to UpdatePercyAnimation_GroundedRight if *PercyFacingDirection is unset (Percy is facing right).
63A6 OR A
63A7 JR Z,UpdatePercyAnimation_GroundedRight
Grounded left: frame = flap counter + 08.
63A9 LD A,($5FAF) Write *PercyFlapCounter + 08 to *IX+03.
63AC ADD A,$08
63AE LD (IX+$03),A
63B1 RET Return.
Grounded right: frame = flap counter + 0C.
UpdatePercyAnimation_GroundedRight 63B2 LD A,($5FAF) Write *PercyFlapCounter + 0C to *IX+03.
63B5 ADD A,$0C
63B7 LD (IX+$03),A
63BA RET Return.
Prev: 631F Up: Map Next: 63BB