Skip to content

Add damage system - HP threshold model (Implementation A) - #24

Open
wannerdev wants to merge 2 commits into
mainfrom
feature/damage-system-hp-threshold
Open

Add damage system - HP threshold model (Implementation A)#24
wannerdev wants to merge 2 commits into
mainfrom
feature/damage-system-hp-threshold

Conversation

@wannerdev

Copy link
Copy Markdown
Owner

Description

Implements a comprehensive damage system with HP-based level demotion, sun radiation damage, and visual damage indicators.

Implementation Approach

This is Implementation A - HP + Threshold Model with i-frames and automatic level demotion.

Core Features

Health System

  • Level 1: 50 HP max
  • Level 2: 85 HP max
  • Level 3: 120 HP max
  • Satellites spawn with full HP for their level

Level Demotion Thresholds

  • 100-67% HP: Level 3
  • 66-34% HP: Level 2
  • 33-1% HP: Level 1
  • 0% HP: Destroyed

Sun Radiation Damage

  • Heat radius: 1.5x sun radius
  • Damage: 5 HP per second when inside heat zone
  • Automatic tracking with SunExposure component
  • Damage stops when satellite leaves heat zone

I-Frame System

  • 0.5 second invulnerability after level demotion
  • Prevents multiple demotions from single collision
  • Prevents damage stacking exploits

Visual Feedback

  • Red glow around damaged satellites
  • Intensity increases as HP decreases
  • Only shows when HP < 66%
  • Alpha scales with damage (0.5 max)

Changes

  • Created damage_system module
  • Added Health component with level-based max HP
  • Added DamageEvent for extensible damage system
  • Added DemoteCooldown for i-frame tracking
  • Added SunExposure for radiation damage tracking
  • Implemented apply_sun_radiation_damage system
  • Implemented handle_damage_events system with demotion logic
  • Implemented draw_damage_effects for visual feedback
  • Integrated Health and DemoteCooldown into satellite spawning
  • Added DamageSystemPlugin to main app

Technical Implementation

Damage Event System

pub struct DamageEvent {
    pub target: Entity,
    pub amount: f32,
    pub source: Entity,
}
  • Extensible: Any system can trigger damage
  • Tracked: Source entity for damage attribution
  • Flexible: Can add collision damage, weapon damage, etc.

Sun Radiation

  • Tracks time in heat zone per satellite
  • Applies 5 HP damage every 1 second
  • Automatic component cleanup when leaving zone
  • No damage outside heat radius

Level Demotion Logic

  1. Check i-frame (skip if active)
  2. Apply damage to HP
  3. Calculate HP percentage
  4. Determine new level from thresholds
  5. Update sprite if level changed
  6. Start i-frame cooldown
  7. Despawn if HP reaches 0

Visual Damage Indicator

  • Red circle around satellite
  • Radius: 5.0 units
  • Alpha: (1.0 - hp_pct) * 0.5
  • Only renders when HP < 66%

Gameplay Impact

Strategic Depth

  • Players must avoid sun's heat zone
  • Close orbits are risky but rewarding
  • Level 3 satellites are more durable
  • Damage accumulates over time

Risk vs Reward

  • Closer to sun = more energy but more damage
  • Heat zone forces orbital planning
  • I-frames allow recovery time
  • Visual feedback helps decision making

Balancing

  • 5 HP/sec sun damage
  • Level 1: 10 seconds in heat zone
  • Level 2: 17 seconds in heat zone
  • Level 3: 24 seconds in heat zone

Benefits

  • Adds challenge and strategy
  • Makes positioning important
  • Provides clear visual feedback
  • Extensible for future damage sources
  • Prevents instant death from damage stacking
  • Smooth level transitions

Testing

  • Launch satellite into sun's heat zone
  • Verify red glow appears as HP decreases
  • Check level demotion at 66% and 33% HP
  • Verify satellite destroyed at 0% HP
  • Test i-frame prevents rapid demotion
  • Confirm sprite updates on level change
  • Check damage stops outside heat zone

Future Enhancements

  • Collision damage based on relative speed
  • Asteroid impact damage
  • Repair/healing mechanics
  • HP regeneration over time
  • Damage numbers floating text
  • Shield system (see Implementation B)

Related Feature

Implements: Damage System (HP + Threshold Model)

Suna AI Agent and others added 2 commits October 20, 2025 04:07
- Created damage_system module with Health and DemoteCooldown components
- Implemented sun radiation damage system (5 HP/sec in heat radius)
- Added collision damage based on relative speed and mass
- Level demotion thresholds: 100-67% L3, 66-34% L2, 33-1% L1, 0% destroyed
- I-frame system prevents multi-demote (0.5s cooldown)
- Visual damage effects (red glow based on HP percentage)
- Level-based max HP: L1=50, L2=85, L3=120
- Satellites spawn with full HP for their level
- Automatic sprite updates on level change
- DamageEvent system for extensible damage sources
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant