range indicators, limit tower placement to within range of core
This commit is contained in:
parent
9c4787f5e2
commit
6a4978041c
16 changed files with 350 additions and 60 deletions
|
|
@ -8,7 +8,7 @@ use bevy::{
|
|||
platform::collections::HashMap,
|
||||
prelude::*,
|
||||
};
|
||||
use combat::{Health, Team};
|
||||
use combat::{Health, Range, Team};
|
||||
use input::Selectable;
|
||||
use resources::{Cost, Resources};
|
||||
use state::GameSystemSet;
|
||||
|
|
@ -32,6 +32,10 @@ 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)]
|
||||
|
|
@ -114,7 +118,13 @@ 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
|
||||
&& position.distance_squared(core_position) > core_range * core_range
|
||||
{
|
||||
return false;
|
||||
}
|
||||
!spatial_query
|
||||
.shape_intersections(
|
||||
// shrink the collider a bit to allow for buildings right next to each other
|
||||
|
|
@ -133,6 +143,7 @@ fn place_building(
|
|||
mut resources: ResMut<Resources>,
|
||||
info_query: Query<(&BuildingInfo, &Cost, &Name), With<UpgradeTree>>,
|
||||
building_query: Query<&Building>,
|
||||
core_query: Query<(&GlobalTransform, &Range), With<Core>>,
|
||||
spatial_query: SpatialQuery,
|
||||
) {
|
||||
for PlaceBuilding {
|
||||
|
|
@ -150,7 +161,16 @@ 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) {
|
||||
if !valid_placement(
|
||||
&spatial_query,
|
||||
&building_query,
|
||||
size_v3,
|
||||
position,
|
||||
core_query
|
||||
.single()
|
||||
.ok()
|
||||
.map(|(gtf, r)| (gtf.translation(), r.0)),
|
||||
) {
|
||||
error!("tried to place building colliding with other building");
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue