Prev: 25686 Up: Map Next: 25831
25728: Update Energy Bar
Used by the routine at MainGameLoop.
Animates Percy's energy bar at the bottom of the screen. The bar depletes when Percy is airborne and refills when Percy is on the ground. If the bar fully depletes, Percy enters the falling state.
Input
IX Pointer to Percy's state data
UpdateEnergyBar 25728 LD HL,21228 HL=21228 (screen buffer location for the energy bar).
If *FallingState is non-zero, it's acting as a cooldown timer so decrement it and return.
25731 LD A,(24487) A=*FallingState.
25734 OR A Jump to UpdateEnergyBar_CheckPosition if *FallingState is zero (Percy isn't falling).
25735 JR Z,UpdateEnergyBar_CheckPosition
25737 DEC A Decrement the cooldown timer.
25738 LD (24487),A Write A to *FallingState.
25741 RET Return.
Check if Percy is on the ground (Y >= 144). If so, the energy bar
refills. Otherwise it depletes.
UpdateEnergyBar_CheckPosition 25742 LD A,(IX+1) Load A with Percy's Y position (from *IX+1).
25745 CP 144 Jump to UpdateEnergyBar_Refill if Percy is at, or below the ground level (144).
25747 JR NC,UpdateEnergyBar_Refill
Percy is airborne so deplete the energy bar. Uses a slower frame delay of 7 frames between each step.
25749 LD A,(24491) Increment the *EnergyBarDelayCounter.
25752 INC A
25753 LD (24491),A
25756 CP 7 Return if it's not yet time to update the energy bar.
25758 RET NZ
Reset the frame counter and check if Percy is on a platform (energy doesn't deplete while landed).
25759 XOR A Write 0 to reset *EnergyBarDelayCounter.
25760 LD (24491),A
25763 LD A,(24493) Return if *LandedOnPlatformFlag is set, indicating Percy is landed on a platform.
25766 OR A
25767 RET NZ
Deplete the energy bar by shifting pixels left. Scans rightward from the current position to find the rightmost filled byte, then shifts it left by one pixel.
UpdateEnergyBar_Deplete_FindByte 25768 LD A,(HL) Jump to UpdateEnergyBar_Deplete_ScanLeft if *HL is zero (no pixels here).
25769 OR A
25770 JR Z,UpdateEnergyBar_Deplete_ScanLeft
25772 SLA (HL) Shift *HL left one pixel (remove one pixel of energy).
Copy the updated byte to the three pixel rows below to give the energy bar its height.
UpdateEnergyBar_CopyRows 25774 LD A,(HL) A=*HL.
25775 INC H Copy to the first row below.
25776 LD (HL),A
25777 INC H Copy to the second row below.
25778 LD (HL),A
25779 INC H Copy to the third row below.
25780 LD (HL),A
25781 RET Return.
Current byte is empty so scan leftward for the next filled byte.
UpdateEnergyBar_Deplete_ScanLeft 25782 DEC L Move one byte to the left.
25783 LD A,L Jump to UpdateEnergyBar_Depleted if the energy bar is fully depleted (reached 224 the left edge of the bar).
25784 CP 224
25786 JR Z,UpdateEnergyBar_Depleted
25788 JR UpdateEnergyBar_Deplete_FindByte Jump to UpdateEnergyBar_Deplete_FindByte to check this byte.
This entry point is used by the routine at Run_Main_Loop_Body.
Percy is on the ground so refill the energy bar. Uses a faster frame delay of 3 frames between each step.
UpdateEnergyBar_Refill 25790 LD A,(24491) Increment the *EnergyBarDelayCounter.
25793 INC A
25794 LD (24491),A
25797 CP 3 Return if not yet time to update the bar.
25799 RET C
25800 XOR A Write 0 to reset *EnergyBarDelayCounter.
25801 LD (24491),A
This entry point is used by the routines at Start_Level and Handle_Butterfly.
Refill the energy bar by shifting pixels right (filling from the left). Scans leftward to find the first non-full byte and fills it one pixel at a time.
UpdateEnergyBar_Refill_Shift 25804 LD HL,21217 HL=21217 (left edge of the energy bar).
UpdateEnergyBar_Refill_FindByte 25807 LD A,(HL) A=*HL.
25808 CP 255 Jump to UpdateEnergyBar_Refill_ScanRight if this byte is full (scan next byte).
25810 JR Z,UpdateEnergyBar_Refill_ScanRight
25812 SRL (HL) Shift *HL right one pixel.
25814 SET 7,(HL) Set bit 7 of *HL (fill from the left).
25816 JR UpdateEnergyBar_CopyRows Jump to UpdateEnergyBar_CopyRows to copy the result to the rows below.
Current byte is fully filled so scan rightward for the next byte to fill.
UpdateEnergyBar_Refill_ScanRight 25818 INC L Move one byte to the right.
25819 LD A,L Return if the bar is fully refilled (the scan reached 237 which is the right edge of the bar).
25820 CP 237
25822 RET Z
25823 JR UpdateEnergyBar_Refill_FindByte Jump to UpdateEnergyBar_Refill_FindByte to check this byte.
Energy bar has fully depleted so set Percy to the falling state.
UpdateEnergyBar_Depleted 25825 LD A,255 Write 255 to *FallingState.
25827 LD (24487),A
25830 RET Return.
Prev: 25686 Up: Map Next: 25831