aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared.rs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-14 06:43:53 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-15 02:50:57 +0100
commit69584a302d132dc2bcc3837437e7347a3e0a5114 (patch)
treefae29ea706451e91a0dee99200fa661b78de3517 /src/shared.rs
parent9671dd79163e654f61896ec4f61142a71c2f82c0 (diff)
feat: players can teleport
Diffstat (limited to 'src/shared.rs')
-rw-r--r--src/shared.rs40
1 files changed, 40 insertions, 0 deletions
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(),
+ }
+ }
+}