Prev: 25375 Up: Map Next: 25531
25400: 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 25400 LD A,(24496) A=*PercyAnimationCounter.
25403 BIT 7,A Jump to UpdatePercyAnimation_SecondHalf if in the second half of the cycle.
25405 JR NZ,UpdatePercyAnimation_SecondHalf
First half so increment the counter.
25407 INC A Increment A.
25408 CP 5 Jump to UpdatePercyAnimation_SwitchToSecondHalf if the counter has reached 5 (switch to second half).
25410 JR Z,UpdatePercyAnimation_SwitchToSecondHalf
25412 LD (24496),A Write A to *PercyAnimationCounter.
25415 JR UpdatePercyAnimation_SetFrame Jump to UpdatePercyAnimation_SetFrame.
Second half so decrement the counter.
UpdatePercyAnimation_SecondHalf 25417 AND %00000111 Keep only bits 0-2 (frame index).
25419 DEC A Decrement the frame index.
25420 OR A Jump to UpdatePercyAnimation_SwitchToFirstHalf if the frame index has reached zero.
25421 JR Z,UpdatePercyAnimation_SwitchToFirstHalf
25423 ADD A,128 Write A + 128 (keep bit 7 set) to *PercyAnimationCounter.
25425 LD (24496),A
25428 JR UpdatePercyAnimation_SetFrame Jump to UpdatePercyAnimation_SetFrame.
Switch to the second half of the animation cycle.
UpdatePercyAnimation_SwitchToSecondHalf 25430 LD A,132 Write 132 to *PercyAnimationCounter.
25432 LD (24496),A
25435 JR UpdatePercyAnimation_SetFrame Jump to UpdatePercyAnimation_SetFrame.
Switch back to the first half of the animation cycle.
UpdatePercyAnimation_SwitchToFirstHalf 25437 LD A,1 Write 1 to *PercyAnimationCounter.
25439 LD (24496),A
Select Percy's sprite frame based on direction and animation state. Frames are arranged in groups:
Byte Range State
1-4 Flying right
5-8 Flying left
9-12 Walking/ Standing right
13-16 Walking/ Standing left
UpdatePercyAnimation_SetFrame 25442 LD A,(IX+0) Jump to UpdatePercyAnimation_ChooseFrame if Percy's current X position (*IX+0) is the same as his previous X position (*IX+64).
25445 CP (IX+64)
25448 JR Z,UpdatePercyAnimation_ChooseFrame
Percy has moved horizontally so cycle the wing flap counter between
1 and 4.
25450 LD A,(24495) A=*PercyFlapCounter.
25453 INC A Increment the flap counter.
25454 CP 5 Jump to UpdatePercyAnimation_StoreFlap if it hasn't reached 5 yet.
25456 JR NZ,UpdatePercyAnimation_StoreFlap
25458 LD A,1 Reset the flap counter to 1.
UpdatePercyAnimation_StoreFlap 25460 LD (24495),A Write A to *PercyFlapCounter.
Determine whether Percy is airborne or grounded, and facing left or right.
UpdatePercyAnimation_ChooseFrame 25463 LD A,(IX+1) Jump to UpdatePercyAnimation_Grounded if Percy's Y position (*IX+1) is on the ground, or if *LandedOnPlatformFlag is set (and percy has landed on a platform).
25466 CP 144
25468 JR NC,UpdatePercyAnimation_Grounded
25470 LD A,(24493)
25473 OR A
25474 JR NZ,UpdatePercyAnimation_Grounded
Percy is airborne so select flying frame based on direction.
25476 LD A,(24485) Jump to UpdatePercyAnimation_FlyingRight if *PercyFacingDirection is unset (Percy is facing right).
25479 OR A
25480 JR Z,UpdatePercyAnimation_FlyingRight
Flying left: frame = flap counter + 0.
25482 LD A,(24496) A=*PercyAnimationCounter.
25485 AND %00000111 Keep only bits 0-2 (animation frame index).
25487 LD (IX+3),A Write A to *IX+3.
25490 RET Return.
Flying right: frame = flap counter + 4.
UpdatePercyAnimation_FlyingRight 25491 LD A,(24496) A=*PercyAnimationCounter.
25494 AND %00000111 Keep only bits 0-2.
25496 ADD A,4 Write A + 4 to *IX+3.
25498 LD (IX+3),A
25501 RET Return.
Percy is on the ground or landed so select grounded frame.
UpdatePercyAnimation_Grounded 25502 LD A,1 Write 1 to *MovementSpeed (reset movement speed).
25504 LD (24494),A
25507 LD A,(24485) Jump to UpdatePercyAnimation_GroundedRight if *PercyFacingDirection is unset (Percy is facing right).
25510 OR A
25511 JR Z,UpdatePercyAnimation_GroundedRight
Grounded left: frame = flap counter + 8.
25513 LD A,(24495) Write *PercyFlapCounter + 8 to *IX+3.
25516 ADD A,8
25518 LD (IX+3),A
25521 RET Return.
Grounded right: frame = flap counter + 12.
UpdatePercyAnimation_GroundedRight 25522 LD A,(24495) Write *PercyFlapCounter + 12 to *IX+3.
25525 ADD A,12
25527 LD (IX+3),A
25530 RET Return.
Prev: 25375 Up: Map Next: 25531