spawn projectiles at player location

This commit is contained in:
2022-08-16 15:23:29 +02:00
parent 5ddbf6fc7d
commit 56fdaabb1a
3 changed files with 40 additions and 30 deletions

View File

@@ -13,8 +13,8 @@ use bevy_renet::{
};
use daggmask_shared::{
client_connection_config, setup_level, ClientChannel, NetworkFrame, PlayerCommand, PlayerInput,
ServerChannel, ServerMessages, PROTOCOL_ID,
client_connection_config, setup_level, ClientChannel, NetworkFrame, PlayerCommand, PlayerId,
PlayerInput, ServerChannel, ServerMessages, PROTOCOL_ID,
};
use renet_visualizer::{RenetClientVisualizer, RenetVisualizerStyle};
@@ -123,14 +123,14 @@ fn update_visulizer_system(
}
fn player_input(
controlled_player_query: Query<(&Transform, &Aimer)>,
controlled_player_query: Query<&Aimer>,
keyboard_input: Res<Input<KeyCode>>,
mut player_input: ResMut<PlayerInput>,
mouse_button_input: Res<Input<MouseButton>>,
mut player_commands: EventWriter<PlayerCommand>,
most_recent_tick: Res<MostRecentTick>,
) {
let (transform, aimer) = controlled_player_query.single();
let aimer = controlled_player_query.single();
player_input.left = keyboard_input.pressed(KeyCode::A) || keyboard_input.pressed(KeyCode::Left);
player_input.right =
@@ -140,13 +140,9 @@ fn player_input(
player_input.most_recent_tick = most_recent_tick.0;
if mouse_button_input.just_pressed(MouseButton::Left) {
info!(
"player at origin {} fired at {}",
transform.translation, aimer.aiming_at
);
info!("player fired at {}", aimer.aiming_at);
player_commands.send(PlayerCommand::BasicAttack {
origin: Vec2::new(transform.translation.x, transform.translation.y),
direction: aimer.aiming_at,
});
}
@@ -218,9 +214,12 @@ fn client_sync_players(
});
if client_id == id {
client_entity.insert(ControlledPlayer).insert(Aimer {
aiming_at: Vec2::new(0., 0.),
});
client_entity
.insert(ControlledPlayer)
.insert(Aimer {
aiming_at: Vec2::new(0., 0.),
})
.insert(PlayerId { id });
}
let player_info = PlayerInfo {