Bevy Power System
A comprehensive power/energy system for Bevy games with regeneration, limits, knockouts, leveling, and UI components.
Features
- Power Management: Track current and maximum power with automatic regeneration
- Power Limits: Apply temporary or permanent power restrictions with visual feedback
- Knockout System: Handle zero-power states with revival mechanics
- Leveling System: Experience-based progression with power bonuses
- Regeneration: Smart power recovery with delays and ramping
- Built-in UI: Animated power bar with limit visualization
- Event-Driven: Clean API using Bevy's message system
Quick Start
Add to your Cargo.toml:
[]
= "0.1.0"
= "0.17.1"
Basic setup:
use *;
use *;
Core Components
PowerBar
Tracks current and maximum power:
// Default: 100 max power
commands.spawn;
// Custom max power
commands.spawn;
// Full customization
commands.spawn;
Power Limits
Apply restrictions that reduce available power:
Safe vs Force Methods
The crate provides both safe (try_*) and force methods:
// Safe methods - won't cause knockout
if power_system.try_spend else
if power_system.try_limit_points else
// Force methods - always execute
power_system.spend; // May cause knockout
power_system.limit_points; // May cause knockout
Power System API
The PowerSystem SystemParam provides convenient access to all power operations:
Regeneration System
Power automatically regenerates after not spending for a configurable delay:
- Delay: Time before regeneration starts (default: 2.5 seconds)
- Ramping: Regeneration rate increases over time
- Reset on Spend: Using power resets the regeneration timer
- Cooldown Reset: Some limits can force regeneration to restart
// Customize regeneration in PowerBundle::custom()
custom
Knockout System
When power reaches zero or max power becomes zero (due to limits):
Examples
Run the included examples to see the system in action:
# Interactive demo with buttons
# Dash ability implementation
# Simple keyboard controls
Dash Demo Controls
- WASD: Move player
- SPACE: Dash (costs 10 power, 1-second cooldown)
- R: Regenerate 20 power
- L: Apply power limit
- C: Clear limits
- T: Toggle between safe/force methods
UI System
The crate includes a built-in power bar UI that automatically:
- Shows current/max power with text
- Displays power percentage as a fill bar
- Changes color based on power state (low, regenerating, knocked out)
- Visualizes active limits as colored segments
- Updates in real-time
The UI is automatically added when you include the PowerSystemPlugin.
Events
The system uses Bevy's message system for clean event handling:
Available events:
KnockedOutEventLevelUpEventSpendPowerEventPowerChangeEventApplyLimitEventLiftLimitEventReviveEvent
System Architecture
The plugin is organized into system sets that run in order:
- PowerSystemSet::Input - Handle events and input
- PowerSystemSet::Update - Update power states, regeneration, limits
- PowerSystemSet::UI - Update visual components
This ensures consistent execution order and allows you to schedule your systems appropriately.
Use Cases
This system is perfect for:
- RPGs: Mana/energy systems with spell costs and regeneration
- Action Games: Stamina systems for abilities like dashing, jumping
- Strategy Games: Resource management with temporary modifiers
- Survival Games: Hunger/thirst systems with food effects
- Fighting Games: Special move meters with cooldowns