diff options
Diffstat (limited to 'src/client.rs')
-rw-r--r-- | src/client.rs | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/src/client.rs b/src/client.rs index 174d615..fff18af 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,5 +1,6 @@ use crate::client::network::*; use crate::protocol::*; +use crate::shared::champion::*; use crate::shared::health::*; use crate::shared::imperative::*; use crate::shared::projectile::*; @@ -17,13 +18,19 @@ const PLAYER_RADIUS: f32 = 10.; const PLAYER_HOVER_INDICATOR_RADIUS: f32 = 13.; const PLAYER_HOVER_RADIUS: f32 = 20.; -pub fn main(server_addr: Option<SocketAddr>, client_id: u64, transport: TransportConfig) { +pub fn main( + server_addr: Option<SocketAddr>, + client_id: u64, + transport: TransportConfig, + champion: Champion, +) { App::new() .add_plugins(DefaultPlugins) .add_plugins(ClientPlugin { server_addr, client_id, transport, + champion, }) .run(); } @@ -31,15 +38,20 @@ pub fn main(server_addr: Option<SocketAddr>, client_id: u64, transport: Transpor #[derive(Resource)] struct ClientId(pub u64); +#[derive(Resource)] +struct MyChampion(pub Champion); + struct ClientPlugin { pub server_addr: Option<SocketAddr>, pub client_id: u64, pub transport: TransportConfig, + pub champion: Champion, } impl Plugin for ClientPlugin { fn build(&self, app: &mut App) { app.insert_resource(ClientId(self.client_id)) + .insert_resource(MyChampion(self.champion)) .add_plugins(NetworkPlugin { server_addr: self.server_addr.clone(), client_id: self.client_id, @@ -63,9 +75,12 @@ impl Plugin for ClientPlugin { } } -fn setup(mut client: ClientMut, mut commands: Commands) { +fn setup(mut client: ClientMut, mut commands: Commands, champion: Res<MyChampion>) { commands.spawn(Camera2dBundle::default()); client.connect().unwrap(); + client + .send_message::<Channel1, SelectChampion>(SelectChampion(champion.0)) + .unwrap(); } fn render_players( @@ -200,14 +215,22 @@ fn gizmos_attack_indicator( client_id: Res<ClientId>, hoverables: Query<(&PlayerId, &PlayerPosition)>, mut gizmos: Gizmos, - players: Query<(&PlayerId, &PlayerPosition)>, + player_positions: Query<(&PlayerId, &PlayerPosition)>, + player_champions: Query<(&PlayerId, &Champion)>, windows: Query<&Window>, ) { - let Some(position) = player_position(&client_id, &players) else { + let Some(position) = player_position(&client_id, &player_positions) else { + return; + }; + let Some(champion) = player_champion(&client_id, &player_champions) else { return; }; if hovered_other_player(&cameras, &client_id, &hoverables, &windows).is_some() { - gizmos.circle_2d(position.0, ATTACK_RANGE, Color::YELLOW); + gizmos.circle_2d( + position.0, + Stats::from_champion(champion).attack_range, + Color::YELLOW, + ); } } @@ -223,6 +246,18 @@ fn player_position( None } +fn player_champion( + client_id: &Res<ClientId>, + players: &Query<(&PlayerId, &Champion)>, +) -> Option<Champion> { + for (id, champion) in players.iter() { + if id.0 == client_id.0 { + return Some(*champion); + } + } + None +} + const HEALTH_OFFSET: f32 = 4.; fn render_health(players: Query<(&Health, &PlayerPosition)>, mut gizmos: Gizmos) { |