aboutsummaryrefslogtreecommitdiffstats
path: root/src/client.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/client.rs')
-rw-r--r--src/client.rs50
1 files changed, 43 insertions, 7 deletions
diff --git a/src/client.rs b/src/client.rs
index 96baeb8..8793c4a 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -32,15 +32,13 @@ impl Plugin for ClientPlugin {
transport: self.transport.clone(),
})
.add_systems(Startup, setup)
- .add_systems(Update, render_players)
- .add_systems(Update, render_projectiles)
- .add_systems(Update, move_players)
- .add_systems(Update, move_projectiles)
+ .add_systems(Update, (render_players, render_projectiles))
+ .add_systems(Update, (move_players, move_projectiles))
.add_systems(
FixedPreUpdate,
buffer_input.in_set(InputSystemSet::BufferInputs),
)
- .add_systems(Last, gizmos_hover_indicator);
+ .add_systems(Last, (gizmos_hover_indicator, gizmos_attack_indicator));
}
}
@@ -105,7 +103,7 @@ fn buffer_input(
windows: Query<&Window>,
) {
if mouse_input.just_pressed(MouseButton::Left) {
- if let Some((target_player, _)) = hovered_player(&windows, &cameras, &attackables) {
+ if let Some((target_player, _)) = hovered_other_player(&windows, &cameras, &attackables) {
client.add_input(Inputs::Imperative(Imperative::Attack(target_player)));
} else {
if let Some(world_position) = cursor_world_position(&windows, &cameras) {
@@ -121,7 +119,7 @@ fn gizmos_hover_indicator(
cameras: Query<(&Camera, &GlobalTransform)>,
windows: Query<&Window>,
) {
- let Some((_, position)) = hovered_player(&windows, &cameras, &hoverables) else {
+ let Some((_, position)) = hovered_other_player(&windows, &cameras, &hoverables) else {
return;
};
gizmos.circle_2d(position.0, PLAYER_HOVER_INDICATOR_RADIUS, Color::GREEN);
@@ -139,6 +137,20 @@ fn cursor_world_position(
camera.viewport_to_world_2d(camera_transform, cursor_position)
}
+fn hovered_other_player(
+ windows: &Query<&Window>,
+ cameras: &Query<(&Camera, &GlobalTransform)>,
+ hoverables: &Query<(&PlayerId, &PlayerPosition)>,
+) -> Option<(PlayerId, PlayerPosition)> {
+ let Some((id, position)) = hovered_player(windows, cameras, hoverables) else {
+ return None;
+ };
+ if id.0 == 0 {
+ return None;
+ }
+ Some((id, position))
+}
+
fn hovered_player(
windows: &Query<&Window>,
cameras: &Query<(&Camera, &GlobalTransform)>,
@@ -155,3 +167,27 @@ fn hovered_player(
}
hovered_player
}
+
+fn gizmos_attack_indicator(
+ cameras: Query<(&Camera, &GlobalTransform)>,
+ hoverables: Query<(&PlayerId, &PlayerPosition)>,
+ mut gizmos: Gizmos,
+ players: Query<(&PlayerId, &PlayerPosition)>,
+ windows: Query<&Window>,
+) {
+ let Some(position) = player_position(&players) else {
+ return;
+ };
+ if hovered_other_player(&windows, &cameras, &hoverables).is_some() {
+ gizmos.circle_2d(position.0, ATTACK_RANGE, Color::YELLOW);
+ }
+}
+
+fn player_position(players: &Query<(&PlayerId, &PlayerPosition)>) -> Option<PlayerPosition> {
+ for (id, position) in players.iter() {
+ if id.0 == 0 {
+ return Some(*position);
+ }
+ }
+ None
+}