aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-24 06:26:22 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-24 06:27:47 +0100
commit1751960338fc7a08fec438a9b53c78118a35063a (patch)
tree101d8a45a35723ba6c4c9775b1ebcb494c3be7b6
parentfff6538cde0bb83c9f0166b60f7f2ff5a5b15f8d (diff)
feat: add tower range/ target indicator
-rw-r--r--src/client.rs50
-rw-r--r--src/protocol.rs3
-rw-r--r--src/shared/faction.rs2
-rw-r--r--src/shared/player.rs4
-rw-r--r--src/shared/tower.rs6
5 files changed, 60 insertions, 5 deletions
diff --git a/src/client.rs b/src/client.rs
index a1aa250..12f12c0 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -14,6 +14,7 @@ use crate::shared::player::*;
use crate::shared::projectile::*;
use crate::shared::shape::*;
use crate::shared::stats::*;
+use crate::shared::tower::*;
use bevy::input::keyboard::*;
use bevy::input::mouse::MouseButton;
use bevy::prelude::*;
@@ -86,6 +87,8 @@ impl Plugin for ClientPlugin {
render_area_of_effects,
render_health,
render_buffs,
+ render_tower_target,
+ render_tower_range,
),
)
.add_systems(
@@ -581,6 +584,18 @@ fn player_position(
None
}
+fn other_player_position(
+ player_id: PlayerId,
+ players: &Query<(&PlayerId, &PlayerPosition)>,
+) -> Option<PlayerPosition> {
+ for (id, position) in players.iter() {
+ if *id == player_id {
+ return Some(*position);
+ }
+ }
+ None
+}
+
fn player_effective_stats(
client_id: &Res<ClientId>,
players: &Query<(&PlayerId, &EffectiveStats)>,
@@ -659,6 +674,41 @@ fn render_buffs(players: Query<(&Buffs, &PlayerPosition, &Shape)>, mut gizmos: G
}
}
+fn render_tower_range(
+ towers: Query<(&PlayerPosition, &EffectiveStats, &Faction), With<Tower>>,
+ mut gizmos: Gizmos,
+) {
+ for (player_position, effective_stats, faction) in towers.iter() {
+ gizmos.circle_2d(
+ player_position.0,
+ effective_stats.0.attack_range,
+ faction.to_color(),
+ );
+ }
+}
+
+fn render_tower_target(
+ towers: Query<(&Tower, &PlayerPosition, &Faction)>,
+ player_positions: Query<(&PlayerId, &PlayerPosition)>,
+ mut gizmos: Gizmos,
+) {
+ for (tower, player_position, faction) in towers.iter() {
+ let Some(last_target) = tower.last_target else {
+ continue;
+ };
+ let Some(target_player_position) =
+ other_player_position(last_target.player_id, &player_positions)
+ else {
+ continue;
+ };
+ gizmos.line_2d(
+ player_position.0,
+ target_player_position.0,
+ faction.to_color(),
+ );
+ }
+}
+
fn hotbar_cooldown(
client_id: Res<ClientId>,
cooldowns: Query<(&PlayerId, &Cooldown)>,
diff --git a/src/protocol.rs b/src/protocol.rs
index c04fed6..87fa9c0 100644
--- a/src/protocol.rs
+++ b/src/protocol.rs
@@ -11,6 +11,7 @@ use crate::shared::player::*;
use crate::shared::projectile::*;
use crate::shared::shape::*;
use crate::shared::stats::*;
+use crate::shared::tower::*;
use bevy::prelude::*;
use lightyear::prelude::*;
use serde::Deserialize;
@@ -53,6 +54,8 @@ pub enum Components {
AreaOfEffect(AreaOfEffect),
Buffs(Buffs),
Shape(Shape),
+ Tower(Tower),
+ Faction(Faction),
}
#[derive(Channel)]
diff --git a/src/shared/faction.rs b/src/shared/faction.rs
index 2f7ac33..d3086d8 100644
--- a/src/shared/faction.rs
+++ b/src/shared/faction.rs
@@ -1,7 +1,7 @@
use crate::shared::*;
use std::str::FromStr;
-#[derive(Component, Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
+#[derive(Message, Component, Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
pub enum Faction {
Purple,
Yellow,
diff --git a/src/shared/player.rs b/src/shared/player.rs
index d166a7d..606a3b2 100644
--- a/src/shared/player.rs
+++ b/src/shared/player.rs
@@ -58,7 +58,7 @@ impl PlayerBundle {
}
}
-#[derive(Component, Message, Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
+#[derive(Component, Message, Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
pub struct PlayerId(pub ClientId);
#[derive(Component, Message, Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
@@ -67,5 +67,5 @@ pub struct PlayerPosition(pub Vec2);
#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct PlayerColor(pub Color);
-#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
+#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)]
pub struct Player;
diff --git a/src/shared/tower.rs b/src/shared/tower.rs
index 4601112..28ccc13 100644
--- a/src/shared/tower.rs
+++ b/src/shared/tower.rs
@@ -62,12 +62,14 @@ impl TowerBundle {
}
}
-#[derive(Component, Default)]
+#[derive(
+ Message, Component, Default, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Debug,
+)]
pub struct Tower {
pub last_target: Option<LastTarget>,
}
-#[derive(Component, Clone, Copy)]
+#[derive(Component, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct LastTarget {
pub entity: Entity,
pub player_id: PlayerId,