# Default health and maximum health # Screen to handle smooth health updates screen health_update(): timer 0.02 repeat True action If(health != target_health, SetVariable("health", health + (1 if health < target_health else -1)), Hide("health_update")) # Screen to handle smooth max health updates screen max_health_update(): timer 0.02 repeat True action If(max_health != target_max_health, SetVariable("max_health", max_health + (1 if max_health < target_max_health else -1)), Hide("max_health_update")) init python: health = 20 max_health = 100 current_max_health = max_health # Create an intermediate variable overlay_image = None # Default value for overlay_image # Set the initial health bar position health_bar_pos = (-8, 37) # You can adjust this as needed # Function to update health with smooth transition def update_health(change): """Smoothly updates the health bar based on a positive or negative change.""" global health global overlay_image global target_health # New variable to track the target health target_health = health + change # Add or subtract the change target_health = max(0, min(target_health, max_health)) # Ensure health stays within bounds # Define the base speed multiplier base_speed = 4.0 delay = 0.02 # Adjust delay for smoother updates # Set the overlay image based on whether health is increasing or decreasing if change < 0: overlay_image = "images/Characters/ICONS/JoeIcon5.png" # Losing health overlay elif change > 0: overlay_image = "images/Characters/ICONS/JoeIcon4.png" # Healing overlay else: overlay_image = "images/Characters/ICONS/JoeIcon3.png" # Default image # Trigger a screen update to show the overlay image renpy.restart_interaction() # Show the non-blocking screen to update health over time renpy.show_screen("health_update") # Hide the overlay image after the update is finished renpy.pause(target_health, hard=False) # No pause blocking gameplay overlay_image = "" # Clear the overlay image after the health update is done renpy.restart_interaction() # Trigger another screen update to remove the overlay # Function to update max health with smooth transition def update_max_health(change): """Smoothly updates the max health bar based on a positive or negative change.""" global max_health global health global health_bar_pos # Assuming this is your health bar position variable global target_max_health # New variable to track the target max health target_max_health = max_health + change # Add or subtract the change target_max_health = max(1, target_max_health) # Ensure max_health stays above 1 # Store the initial health to max_health proportion initial_health_ratio = health / max_health # Define the base speed multiplier base_speed = 5.0 delay = 0.02 # Adjust delay for smoother updates # Show the non-blocking screen to update max health over time renpy.show_screen("max_health_update") # Screen for character status with health bar screen char_status(): # Calculate the color dynamically based on health value $ health_percentage = health / max_health $ green_visible = health_percentage > 0.66 # Show green if health is above 66% $ yellow_visible = health_percentage > 0.33 and health_percentage <= 0.66 # Show yellow if health is between 33-66% $ red_visible = health_percentage <= 0.33 # Show red if health is below 33% $ white_visible = health_percentage <= 0.15 # Show white if health is below 15% $ red_location = red_visible # Location of red bar based on health percentage # Calculate the width of the current health bar based on health and max_health $ max_health_width = 600 # Set the maximum width of the health bar to 600px (you can adjust this value) $ current_health_width = (health / max_health) * max_health_width # Scale width based on health and max_health # Store the previous health for comparing to detect health loss $ previous_health = getattr(store, "previous_health", health) # Retrieve previous health or set to current health $ losing_health = health < previous_health # Check if health has decreased $ healing_health = health > previous_health # Check if health is increasing # Determine which character portrait to display based on health percentage $ portrait_image = "images/Characters/ICONS/JoeIcon.png" # Default (above 85%) if health >= max_health * 0.8: # Above 65% but below 85% $ portrait_image = "images/Characters/ICONS/JoeIcon.png" elif health > max_health * 0.60: # Above 65% but below 85% $ portrait_image = "images/Characters/ICONS/JoeIcon11.png" elif health > max_health * 0.45: # Above 45% but below 65% $ portrait_image = "images/Characters/ICONS/JoeIcon2.png" elif health > max_health * 0.21: # Above 25% but below 45% $ portrait_image = "images/Characters/ICONS/JoeIcon3.png" elif health > 0: # Above 0% but below 25% $ portrait_image = "joeiconcritical" # Update previous_health for the next check $ store.previous_health = health frame: background None pos (400, 200) xysize (600, 380) # Character portrait: Dynamically change based on health status add portrait_image xysize (79, 76) pos (-48, 50) # Overlay image for health gain/loss if overlay_image: add overlay_image pos (-48, 50) xysize (79, 76) # Display current health and max health to the left of the bar text "[int(health)]/[int(max_health)] HP" size 15 color "#FFFFFF" pos (-50, 5) font "fonts/Winter Lemon.ttf" # Health bar bar: value health range max_health xanchor 0.0 pos health_bar_pos # Use the dynamically set position xysize (max_health * 2, 40) # Scale the width based on health and max_health # Left-side bar represents current health, color changes dynamically if green_visible: left_bar Frame("#22ee70", 0, 0) if yellow_visible: left_bar Frame("#FFFF00", 0, 0) if red_visible: left_bar Frame("#FF0000", 0, 0) # Right-side bar (depleted health) in gray or red right_bar Frame("#610707", 0, 0) # White bar that fades in and out when health is below 15% if white_visible: frame: background "#FFFFFF" # White color for the flashing effect xysize (current_health_width, 40) pos (red_location, 50) at repeat_fade_in_out # Animation to handle the fade in and out of the white bar transform repeat_fade_in_out: alpha 0 linear 0.2 alpha 0.5 linear 0.3 alpha 0 repeat # Function to upgrade health label upgrade_health: # Increase max health and fill new space in yellow $ max_health += 20.0 $ health = max_health # Fully heal after upgrade return #############START LABEL########### label start: show screen char_status "You gain health!" $ update_health(50) $ update_health(-10) "You lost health!" $ update_health(50) "You gain health!" $ update_health(25) "You regained health!" "changed max health!" $ update_max_health(70) # Increase max_health by 20 $ update_health(100) "changed max health!" $ update_max_health(20) # Increase max_health by 20 $ update_health(40) "changed max health!" $ update_max_health(20) # Increase max_health by 20 $ update_health(40)