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
|
|
@ -253,3 +253,12 @@ fn tick_invulnerability(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Deref, DerefMut)]
|
||||
pub struct Range(pub f32);
|
||||
|
||||
impl Default for Range {
|
||||
fn default() -> Self {
|
||||
Self(5.)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use physics::PhysicsLayers;
|
|||
use rand::{Rng, thread_rng};
|
||||
use state::GameSystemSet;
|
||||
|
||||
use crate::Team;
|
||||
use crate::{Range, Team};
|
||||
|
||||
pub(crate) struct ProjectilePlugin;
|
||||
|
||||
|
|
@ -46,20 +46,18 @@ impl From<&ProjectileLauncher> for Projectile {
|
|||
}
|
||||
|
||||
#[derive(Component, Clone)]
|
||||
#[require(Team)]
|
||||
#[require(Team, Range)]
|
||||
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,
|
||||
|
|
@ -67,7 +65,6 @@ impl ProjectileLauncher {
|
|||
) -> Self {
|
||||
Self {
|
||||
fire_timer: Timer::new(fire_interval, TimerMode::Once),
|
||||
range,
|
||||
spread,
|
||||
damage,
|
||||
fire_offset,
|
||||
|
|
@ -91,13 +88,19 @@ pub struct Fire {
|
|||
|
||||
fn fire_launcher(
|
||||
mut commands: Commands,
|
||||
mut launcher_query: Query<(Entity, &mut ProjectileLauncher, &Team, &GlobalTransform)>,
|
||||
mut launcher_query: Query<(
|
||||
Entity,
|
||||
&mut ProjectileLauncher,
|
||||
&Range,
|
||||
&Team,
|
||||
&GlobalTransform,
|
||||
)>,
|
||||
spatial_query: SpatialQuery,
|
||||
enemy_query: Query<(&Team, &GlobalTransform)>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
let delta = time.delta();
|
||||
for (launcher_entity, mut launcher, team, gtf) in launcher_query.iter_mut() {
|
||||
for (launcher_entity, mut launcher, range, team, gtf) in launcher_query.iter_mut() {
|
||||
// see if enough time has passed to shoot
|
||||
launcher.fire_timer.tick(delta);
|
||||
if !launcher.fire_timer.finished() {
|
||||
|
|
@ -106,7 +109,7 @@ fn fire_launcher(
|
|||
|
||||
// see if enemy in range
|
||||
let enemies = spatial_query.shape_intersections(
|
||||
&Collider::sphere(launcher.range),
|
||||
&Collider::sphere(range.0),
|
||||
gtf.translation(),
|
||||
Quat::default(),
|
||||
&SpatialQueryFilter::from_mask(team.enemy_layers()),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue