From 69584a302d132dc2bcc3837437e7347a3e0a5114 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Thu, 14 Mar 2024 06:43:53 +0100 Subject: feat: players can teleport --- src/shared.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/shared.rs (limited to 'src/shared.rs') diff --git a/src/shared.rs b/src/shared.rs new file mode 100644 index 0000000..b907b57 --- /dev/null +++ b/src/shared.rs @@ -0,0 +1,40 @@ +use crate::protocol::Replicate; +use bevy::prelude::*; +use lightyear::prelude::*; +use serde::Deserialize; +use serde::Serialize; + +pub const CLIENT_ID: u64 = 0; +pub const KEY: [u8; 32] = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +]; +pub const PROTOCOL_ID: u64 = 0; +pub const SERVER_PORT: u16 = 16384; + +#[derive(Bundle)] +pub struct PlayerBundle { + id: PlayerId, + position: PlayerPosition, + color: PlayerColor, + replicate: Replicate, +} + +#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct PlayerId(pub ClientId); + +#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct PlayerPosition(pub Vec2); + +#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct PlayerColor(pub Color); + +impl PlayerBundle { + pub fn new(id: ClientId, position: Vec2, color: Color) -> Self { + PlayerBundle { + id: PlayerId(id), + position: PlayerPosition(position), + color: PlayerColor(color), + replicate: Replicate::default(), + } + } +} -- cgit v1.2.3