Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture the Flag Example Using Entity Layers #426

Merged
merged 22 commits into from
Aug 1, 2023
Merged

Conversation

dyc3
Copy link
Collaborator

@dyc3 dyc3 commented Jul 27, 2023

Objective

Created to test out the visibility layer API in #424

requires #424

Solution

Added a ctf example, where only the players on your team are glowing.

Currently somewhat bugged.

@dyc3 dyc3 mentioned this pull request Jul 27, 2023
5 tasks
@dyc3
Copy link
Collaborator Author

dyc3 commented Jul 28, 2023

This diff fixes the entity visibility bug, but I'm not applying it here because it needs to be fixed in #424 .

diff
diff --git a/examples/ctf.rs b/examples/ctf.rs
index 97c6a3f..6d88f7b 100644
--- a/examples/ctf.rs
+++ b/examples/ctf.rs
@@ -555,6 +555,7 @@ fn do_team_selector_portals(
             &mut Client,
             &mut VisibleEntityLayers,
             &UniqueId,
+            Option<&JoiningTeam>,
         ),
         Without<Team>,
     >,
@@ -573,6 +574,7 @@ fn do_team_selector_portals(
             mut client,
             mut ent_layers,
             unique_id,
+            joining,
         ) = player;
         if pos.0.y < SPAWN_BOX[1] as f64 - 5.0 {
             pos.0 = SPAWN_POS.into();
@@ -588,6 +590,13 @@ fn do_team_selector_portals(
         };
 
         if let Some(team) = team {
+            let main_layer = main_layers.single();
+            ent_layers.as_mut().0.remove(&main_layer);
+            if joining.is_none() {
+                commands.entity(player).insert(JoiningTeam);
+                return;
+            }
+
             *game_mode = GameMode::Survival;
             let mut inventory = Inventory::new(InventoryKind::Player);
             inventory.set_slot(36, Some(ItemStack::new(ItemKind::WoodenSword, 1, None)));
@@ -617,8 +626,6 @@ fn do_team_selector_portals(
             let chat_text: Text = "You are on team ".into_text() + team.team_text() + "!";
             client.send_chat_message(chat_text);
 
-            let main_layer = main_layers.single();
-            ent_layers.as_mut().0.remove(&main_layer);
             for t in Team::iter() {
                 let enemy_layer = ctf_layers.enemy_layers[&t];
                 if t == team {
@@ -650,10 +657,17 @@ fn do_team_selector_portals(
                 ..Default::default()
             });
             player_enemy.insert(ClonedEntity(player));
+
+            commands.entity(player).remove::<JoiningTeam>();
         }
     }
 }
 
+/// Used to delay spawning the cloned player by one tick.
+#[derive(Component)]
+#[component(storage = "SparseSet")]
+struct JoiningTeam;
+
 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
 struct TriggerArea {
     pub a: BlockPos,

@dyc3 dyc3 marked this pull request as ready for review August 1, 2023 12:20
examples/ctf.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
@dyc3 dyc3 merged commit 3eaff91 into layers Aug 1, 2023
7 of 13 checks passed
@dyc3 dyc3 deleted the layers-ctf-example branch August 1, 2023 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants