diff --git a/src/damage_system_shields.rs b/src/damage_system_shields.rs new file mode 100644 index 0000000..114805f --- /dev/null +++ b/src/damage_system_shields.rs @@ -0,0 +1,274 @@ +use bevy::prelude::*; +use crate::GameplaySystem; +use crate::sun_system::{Satellite, Level, SolarSystemAssets, Sun}; +use crate::physics::velocity::Velocity; +use crate::physics::calc_gravity::Attractee; +use crate::collision::HitBox; + +#[derive(Component, Debug, Copy, Clone)] +pub struct Shields { + pub current: f32, + pub max: f32, + pub regen_per_sec: f32, +} + +impl Shields { + pub fn new(level: f32) -> Self { + let (max, regen) = match level as i32 { + 1 => (30.0, 5.0), + 2 => (50.0, 8.0), + 3 => (75.0, 12.0), + _ => (30.0, 5.0), + }; + Self { current: max, max, regen_per_sec: regen } + } +} + +#[derive(Component, Debug, Copy, Clone)] +pub struct Hull { + pub hp: f32, + pub max_hp: f32, +} + +impl Hull { + pub fn new(level: f32) -> Self { + let max_hp = match level as i32 { + 1 => 50.0, + 2 => 85.0, + 3 => 120.0, + _ => 50.0, + }; + Self { hp: max_hp, max_hp } + } +} + +#[derive(Event)] +pub struct DamageEvent { + pub target: Entity, + pub amount: f32, + pub source: Entity, +} + +#[derive(Component)] +struct ShieldHit { + elapsed: f32, + duration: f32, +} + +#[derive(Component)] +struct SunExposure { + time_in_heat: f32, +} + +#[derive(Component, Default)] +pub struct DemoteCooldown(pub Timer); + +impl DemoteCooldown { + pub fn new(_level: f32) -> Self { + Self(Timer::from_seconds(0.0, TimerMode::Once)) + } +} + +pub struct DamageSystemShieldsPlugin; + +impl Plugin for DamageSystemShieldsPlugin { + fn build(&self, app: &mut App) { + app.add_event::(); + app.add_systems(Update, ( + apply_sun_radiation_damage, + handle_damage_events, + regenerate_shields, + update_shield_hit_effects, + draw_shield_effects, + draw_hull_damage_effects, + ).in_set(GameplaySystem)); + } +} + +fn apply_sun_radiation_damage( + mut commands: Commands, + sun_query: Query<(&Transform, &HitBox), With>, + mut satellite_query: Query<(Entity, &Transform, Option<&mut SunExposure>), With>, + time: Res