From 170389ce7abaead6f28097c6b9897f542c6c6a51 Mon Sep 17 00:00:00 2001 From: Martin Indra Date: Mon, 4 Jul 2022 19:50:13 +0200 Subject: [PATCH] Implement simple attacking functionality Relates to #24. --- Cargo.lock | 1 + crates/attacking/Cargo.toml | 1 + crates/attacking/src/attack.rs | 136 +++++++++++++++++++++++++++++++++ crates/attacking/src/lib.rs | 6 +- crates/behaviour/src/chase.rs | 2 +- 5 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 crates/attacking/src/attack.rs diff --git a/Cargo.lock b/Cargo.lock index b237f1b21..3e500fa1f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1619,6 +1619,7 @@ name = "de_attacking" version = "0.1.0-dev" dependencies = [ "bevy", + "de_behaviour", "de_core", "de_index", "de_objects", diff --git a/crates/attacking/Cargo.toml b/crates/attacking/Cargo.toml index 9aa2cf29c..733458926 100644 --- a/crates/attacking/Cargo.toml +++ b/crates/attacking/Cargo.toml @@ -12,6 +12,7 @@ de_objects = { path = "../objects", version = "0.1.0-dev" } de_terrain = { path = "../terrain", version = "0.1.0-dev" } de_index = { path = "../index", version = "0.1.0-dev" } de_spawner = { path = "../spawner", version = "0.1.0-dev" } +de_behaviour = { path = "../behaviour", version = "0.1.0-dev" } # Other bevy = "0.7.0" diff --git a/crates/attacking/src/attack.rs b/crates/attacking/src/attack.rs new file mode 100644 index 000000000..2c53e10d1 --- /dev/null +++ b/crates/attacking/src/attack.rs @@ -0,0 +1,136 @@ +use std::{cmp::Ordering, collections::BinaryHeap}; + +use bevy::prelude::*; +use de_behaviour::ChaseTarget; +use de_core::state::GameState; +use de_objects::LaserCannon; +use iyes_loopless::prelude::*; +use parry3d::query::Ray; + +use crate::laser::LaserFireEvent; +use crate::{sightline::LineOfSight, AttackingLabels}; + +pub(crate) struct AttackPlugin; + +impl Plugin for AttackPlugin { + fn build(&self, app: &mut App) { + app.add_system_set_to_stage( + CoreStage::Update, + SystemSet::new() + .with_system( + update + .run_in_state(GameState::Playing) + .label(AttackingLabels::Update), + ) + .with_system( + aim_and_fire + .run_in_state(GameState::Playing) + .label(AttackingLabels::Aim) + .after(AttackingLabels::Update) + .before(AttackingLabels::Fire), + ), + ); + } +} + +fn update(time: Res