diff --git a/Cargo.lock b/Cargo.lock index 73791c6..d464352 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -1656,7 +1656,6 @@ dependencies = [ "building", "combat", "state", - "ui_range_indicator", ] [[package]] @@ -1678,10 +1677,8 @@ dependencies = [ "avian3d", "bevy", "building", - "combat", "input", "physics", - "ui_range_indicator", ] [[package]] @@ -2019,7 +2016,6 @@ dependencies = [ "ui_health_bar", "ui_ingame", "ui_pause", - "ui_range_indicator", "ui_state", "upgrade", ] @@ -5311,7 +5307,6 @@ dependencies = [ "bevy_egui", "building", "building_placement", - "combat", "input", "resources", "state", @@ -5330,15 +5325,6 @@ dependencies = [ "ui_state", ] -[[package]] -name = "ui_range_indicator" -version = "0.1.0" -dependencies = [ - "bevy", - "combat", - "input", -] - [[package]] name = "ui_state" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 02dfe34..1456ab4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,5 +57,4 @@ building_barrager = { path = "crates/building_barrager" } resource_graveyard = { path = "crates/resource_graveyard" } upgrade = { path = "crates/upgrade" } ui_health_bar = { path = "crates/ui_health_bar" } -ui_range_indicator = { path = "crates/ui_range_indicator" } #new internal crates go here diff --git a/assets/settings/input_map.ron b/assets/settings/input_map.ron index b82ce27..ed21f50 100755 --- a/assets/settings/input_map.ron +++ b/assets/settings/input_map.ron @@ -3,20 +3,20 @@ MouseButton(Middle): [ CameraOrbitEnable, ], - KeyCode(ShiftLeft): [ - MultiPlaceTower, - ], - KeyCode(F1): [ - ToggleDebugUI, - ], MouseButton(Right): [ PlaceTower, ], + MouseButton(Left): [ + CameraPanEnable, + ], + KeyCode(ShiftLeft): [ + MultiPlaceTower, + ], MouseScroll: [ CameraZoom, ], - MouseButton(Left): [ - CameraPanEnable, + KeyCode(F1): [ + ToggleDebugUI, ], MouseMovementX: [ CameraYaw, diff --git a/crates/building/src/lib.rs b/crates/building/src/lib.rs index 7433f54..53ad324 100755 --- a/crates/building/src/lib.rs +++ b/crates/building/src/lib.rs @@ -8,7 +8,7 @@ use bevy::{ platform::collections::HashMap, prelude::*, }; -use combat::{Health, Range, Team}; +use combat::{Health, Team}; use input::Selectable; use resources::{Cost, Resources}; use state::GameSystemSet; @@ -32,10 +32,6 @@ pub struct Building { pub info: Entity, } -#[derive(Component)] -#[require(Range)] -pub struct Core; - #[derive(Component, Clone)] #[require(Name, Cost, UpgradeTree)] #[component(on_add = register_building_info)] @@ -118,13 +114,7 @@ pub fn valid_placement( collider_query: &Query<&Building>, size: Vec3, position: Vec3, - core_position_range: Option<(Vec3, f32)>, ) -> bool { - if let Some((core_position, core_range)) = core_position_range - && !Range(core_range).within(position, core_position) - { - return false; - } !spatial_query .shape_intersections( // shrink the collider a bit to allow for buildings right next to each other @@ -143,7 +133,6 @@ fn place_building( mut resources: ResMut, info_query: Query<(&BuildingInfo, &Cost, &Name), With>, building_query: Query<&Building>, - core_query: Query<(&GlobalTransform, &Range), With>, spatial_query: SpatialQuery, ) { for PlaceBuilding { @@ -161,16 +150,7 @@ fn place_building( } let size_v3 = info.size.as_vec3(); let (collider, position) = info.get_placed_collider_and_position(location.as_vec3()); - if !valid_placement( - &spatial_query, - &building_query, - size_v3, - position, - core_query - .single() - .ok() - .map(|(gtf, r)| (gtf.translation(), r.0)), - ) { + if !valid_placement(&spatial_query, &building_query, size_v3, position) { error!("tried to place building colliding with other building"); continue; } diff --git a/crates/building_barrager/src/lib.rs b/crates/building_barrager/src/lib.rs index 33bd1e2..2f6cc6a 100644 --- a/crates/building_barrager/src/lib.rs +++ b/crates/building_barrager/src/lib.rs @@ -8,7 +8,7 @@ use avian3d::prelude::{Collider, LinearVelocity, RigidBody}; use bevy::prelude::*; use building::{BuildingInfo, BuildingPreview, PREVIEW_ALPHA, PopulatePlacedBuilding}; use combat::{ - Defense, Health, Range, + Defense, Health, projectiles::{Fire, Projectile, ProjectileLauncher, get_shotgun_launch_vectors}, }; use combat_damagers::ContactDamage; @@ -181,9 +181,9 @@ fn populate( Health::new(20.0), Defense::new(7.0), ContactDamage::new(2.0), - Range(10.0), ProjectileLauncher::new( Duration::from_secs(1), + 50.0, 5.0, Vec3::Y * (SIZE.y as f32 + 0.5), Duration::from_secs(10), diff --git a/crates/building_core/Cargo.toml b/crates/building_core/Cargo.toml index 33bfc44..ff3173d 100755 --- a/crates/building_core/Cargo.toml +++ b/crates/building_core/Cargo.toml @@ -9,7 +9,6 @@ bevy = { workspace = true } combat = { path = "../combat" } building = { path = "../building" } state = { path = "../state" } -ui_range_indicator = { path = "../ui_range_indicator" } [lints] workspace = true diff --git a/crates/building_core/src/lib.rs b/crates/building_core/src/lib.rs index 7861693..3d114c1 100755 --- a/crates/building_core/src/lib.rs +++ b/crates/building_core/src/lib.rs @@ -3,9 +3,8 @@ #![allow(clippy::too_many_arguments)] use bevy::prelude::*; -use building::{BuildingInfo, BuildingPreview, Core, PREVIEW_ALPHA, PopulatePlacedBuilding}; -use combat::{Defense, Health, Range}; -use ui_range_indicator::CustomRangeIndicator; +use building::{BuildingInfo, BuildingPreview, PREVIEW_ALPHA, PopulatePlacedBuilding}; +use combat::{Defense, Health}; pub struct BuildingCorePlugin; @@ -15,6 +14,9 @@ impl Plugin for BuildingCorePlugin { } } +#[derive(Component)] +pub struct Core; + #[derive(Resource)] struct CoreResources { mesh: Handle, @@ -70,7 +72,6 @@ fn register( fn populate( trigger: Trigger, mut commands: Commands, - mut materials: ResMut>, res: Res, ) { if trigger.event().info != res.info_entity { @@ -80,15 +81,7 @@ fn populate( Core, Health::new(100.0), Defense::new(5.0), - Range(25.0), Mesh3d(res.mesh.clone()), MeshMaterial3d(res.material.clone()), - CustomRangeIndicator::new(materials.add(StandardMaterial { - alpha_mode: AlphaMode::Blend, - base_color: Color::srgba(0.6, 0.2, 0.2, 0.4), - unlit: true, - double_sided: true, - ..default() - })), )); } diff --git a/crates/building_placement/Cargo.toml b/crates/building_placement/Cargo.toml index 4f90c75..abc807c 100644 --- a/crates/building_placement/Cargo.toml +++ b/crates/building_placement/Cargo.toml @@ -10,8 +10,6 @@ avian3d = { workspace = true } building = { path = "../building" } physics = { path = "../physics" } input = { path = "../input" } -combat = { path = "../combat" } -ui_range_indicator = { path = "../ui_range_indicator" } [lints] workspace = true diff --git a/crates/building_placement/src/lib.rs b/crates/building_placement/src/lib.rs index 04ed9b0..bee063b 100644 --- a/crates/building_placement/src/lib.rs +++ b/crates/building_placement/src/lib.rs @@ -4,11 +4,9 @@ use avian3d::prelude::SpatialQuery; use bevy::prelude::*; -use building::{Building, BuildingInfo, BuildingPreview, Core, PlaceBuilding, valid_placement}; -use combat::Range; +use building::{Building, BuildingInfo, BuildingPreview, PlaceBuilding, valid_placement}; use input::{Cancellable, Inputs, Selected, actions::InputAction}; use physics::Ground; -use ui_range_indicator::DisplayCustomRangeIndicator; pub struct BuildingPlacementPlugin; @@ -48,59 +46,11 @@ fn cancel_preview( } } -fn select_preview( - mut reader: EventReader, - mut old_query: Query<(Entity, &mut Visibility), With>, - core_query: Query>, - new_query: Query<(), With>, - mut commands: Commands, -) { - let Some(SelectBuildingPreview(opt_entity)) = reader.read().last() else { - return; - }; - for (entity, mut vis) in old_query.iter_mut() { - if *opt_entity != Some(entity) { - commands - .entity(entity) - .remove::<(ActiveBuildingPreview, Cancellable)>(); - *vis = Visibility::Hidden; - } - } - let Some(new_entity) = opt_entity else { - if let Ok(core_entity) = core_query.single() { - commands - .entity(core_entity) - .remove::(); - } - return; - }; - if !new_query.contains(*new_entity) { - error!("tried to select a building without a preview!"); - if let Ok(core_entity) = core_query.single() { - commands - .entity(core_entity) - .remove::(); - } - return; - } - commands.entity(*new_entity).insert(( - Visibility::Visible, - ActiveBuildingPreview::default(), - Cancellable, - )); - if let Ok(core_entity) = core_query.single() { - commands - .entity(core_entity) - .insert(DisplayCustomRangeIndicator); - } -} - fn move_preview( trigger: Trigger>, preview: Single<(&mut Transform, &mut ActiveBuildingPreview, &BuildingPreview)>, info_query: Query<&BuildingInfo>, building_query: Query<&Building>, - core_query: Query<(&GlobalTransform, &Range), With>, spatial_query: SpatialQuery, ) { let Some(dest) = trigger.event().hit.position else { @@ -119,10 +69,6 @@ fn move_preview( &building_query, info.size.as_vec3(), position, - core_query - .single() - .ok() - .map(|(gtf, r)| (gtf.translation(), r.0)), ) { info!("invalid placement!!!!!"); return; @@ -150,3 +96,34 @@ fn place_preview( location: active.0, }); } + +fn select_preview( + mut reader: EventReader, + mut old_query: Query<(Entity, &mut Visibility), With>, + new_query: Query<(), With>, + mut commands: Commands, +) { + let Some(SelectBuildingPreview(opt_entity)) = reader.read().last() else { + return; + }; + for (entity, mut vis) in old_query.iter_mut() { + if *opt_entity != Some(entity) { + commands + .entity(entity) + .remove::<(ActiveBuildingPreview, Cancellable)>(); + *vis = Visibility::Hidden; + } + } + let Some(new_entity) = opt_entity else { + return; + }; + if !new_query.contains(*new_entity) { + error!("tried to select a building without a preview!"); + return; + } + commands.entity(*new_entity).insert(( + Visibility::Visible, + ActiveBuildingPreview::default(), + Cancellable, + )); +} diff --git a/crates/combat/src/lib.rs b/crates/combat/src/lib.rs index 985e63d..ca9bf79 100755 --- a/crates/combat/src/lib.rs +++ b/crates/combat/src/lib.rs @@ -253,18 +253,3 @@ fn tick_invulnerability( } } } - -#[derive(Component, Deref, DerefMut)] -pub struct Range(pub f32); - -impl Range { - pub fn within(&self, a: Vec3, b: Vec3) -> bool { - a.distance_squared(b) < self.0 * self.0 - } -} - -impl Default for Range { - fn default() -> Self { - Self(5.) - } -} diff --git a/crates/combat/src/projectiles.rs b/crates/combat/src/projectiles.rs index 0c4c98c..2257dc4 100644 --- a/crates/combat/src/projectiles.rs +++ b/crates/combat/src/projectiles.rs @@ -10,7 +10,7 @@ use physics::PhysicsLayers; use rand::{Rng, thread_rng}; use state::GameSystemSet; -use crate::{Range, Team}; +use crate::Team; pub(crate) struct ProjectilePlugin; @@ -46,18 +46,20 @@ impl From<&ProjectileLauncher> for Projectile { } #[derive(Component, Clone)] -#[require(Team, Range)] +#[require(Team)] pub struct ProjectileLauncher { pub fire_timer: Timer, pub fire_offset: Vec3, pub spread: f32, pub lifetime: Duration, + pub range: f32, pub damage: f32, } impl ProjectileLauncher { pub fn new( fire_interval: Duration, + range: f32, damage: f32, fire_offset: Vec3, lifetime: Duration, @@ -65,6 +67,7 @@ impl ProjectileLauncher { ) -> Self { Self { fire_timer: Timer::new(fire_interval, TimerMode::Once), + range, spread, damage, fire_offset, @@ -88,19 +91,13 @@ pub struct Fire { fn fire_launcher( mut commands: Commands, - mut launcher_query: Query<( - Entity, - &mut ProjectileLauncher, - &Range, - &Team, - &GlobalTransform, - )>, + mut launcher_query: Query<(Entity, &mut ProjectileLauncher, &Team, &GlobalTransform)>, spatial_query: SpatialQuery, enemy_query: Query<(&Team, &GlobalTransform)>, time: Res