diff --git a/assets/maps/map1.map b/assets/maps/map1.map index e59edea..cff8a2a 100644 --- a/assets/maps/map1.map +++ b/assets/maps/map1.map @@ -754,24 +754,6 @@ } // brush 83 { -( 1151.375 512 -256 ) ( 1151.375 512 -255 ) ( 1151.375 511 -256 ) fence [ 1.9967346175427393e-16 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 -( 1168 256 -224 ) ( 1168 256 -223 ) ( 1169 256 -224 ) fence [ -1 1.9967346175427393e-16 0 0 ] [ 0 0 -1 0 ] 0 1 1 -( 1136 512 -256 ) ( 1136 511 -256 ) ( 1137 512 -256 ) fence [ -1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 -( 1168 256 256 ) ( 1169 256 256 ) ( 1168 255 256 ) fence [ 1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 -( 1136 512 -256 ) ( 1137 512 -256 ) ( 1136 512 -255 ) fence [ 1 -1.9967346175427393e-16 0 0 ] [ 0 0 -1 0 ] 0 1 1 -( 1152 256 -224 ) ( 1152 255 -224 ) ( 1152 256 -223 ) fence [ -1.9967346175427393e-16 -1 0 0 ] [ 0 0 -1 0 ] 0 1 1 -} -// brush 84 -{ -( 1151.375 256 -256 ) ( 1151.375 256 -255 ) ( 1151.375 255 -256 ) fence [ 1.9967346175427393e-16 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 -( 1168 0 -224 ) ( 1168 0 -223 ) ( 1169 0 -224 ) fence [ -1 1.9967346175427393e-16 0 0 ] [ 0 0 -1 0 ] 0 1 1 -( 1136 256 -256 ) ( 1136 255 -256 ) ( 1137 256 -256 ) fence [ -1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 -( 1168 0 256 ) ( 1169 0 256 ) ( 1168 -1 256 ) fence [ 1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 -( 1136 256 -256 ) ( 1137 256 -256 ) ( 1136 256 -255 ) fence [ 1 -1.9967346175427393e-16 0 0 ] [ 0 0 -1 0 ] 0 1 1 -( 1152 0 -224 ) ( 1152 -1 -224 ) ( 1152 0 -223 ) fence [ -1.9967346175427393e-16 -1 0 0 ] [ 0 0 -1 0 ] 0 1 1 -} -// brush 85 -{ ( 1151.375 0 -256 ) ( 1151.375 0 -255 ) ( 1151.375 -1 -256 ) fence [ 1.9967346175427393e-16 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 ( 1168 -256 -224 ) ( 1168 -256 -223 ) ( 1169 -256 -224 ) fence [ -1 1.9967346175427393e-16 0 0 ] [ 0 0 -1 0 ] 0 1 1 ( 1136 0 -256 ) ( 1136 -1 -256 ) ( 1137 0 -256 ) fence [ -1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 @@ -779,7 +761,7 @@ ( 1136 0 -256 ) ( 1137 0 -256 ) ( 1136 0 -255 ) fence [ 1 -1.9967346175427393e-16 0 0 ] [ 0 0 -1 0 ] 0 1 1 ( 1152 -256 -224 ) ( 1152 -257 -224 ) ( 1152 -256 -223 ) fence [ -1.9967346175427393e-16 -1 0 0 ] [ 0 0 -1 0 ] 0 1 1 } -// brush 86 +// brush 84 { ( 3840 768 -320 ) ( 3840 769 -320 ) ( 3840 768 -319 ) tile [ 0 -1 0 0 ] [ 0 0 -1 0 ] 0 1 1 ( 3840 768 -320 ) ( 3840 768 -319 ) ( 3841 768 -320 ) tile [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 @@ -788,7 +770,7 @@ ( 5888 5376 -256 ) ( 5889 5376 -256 ) ( 5888 5376 -255 ) tile [ -1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 ( 5888 1088 -256 ) ( 5888 1088 -255 ) ( 5888 1089 -256 ) tile [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 } -// brush 87 +// brush 85 { ( -256 3840 -320 ) ( -256 3841 -320 ) ( -256 3840 -319 ) tile [ 0 -1 0 0 ] [ 0 0 -1 0 ] 0 1 1 ( 3008 3840 -320 ) ( 3008 3840 -319 ) ( 3009 3840 -320 ) tile [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 @@ -797,7 +779,7 @@ ( 3840 5376 -256 ) ( 3841 5376 -256 ) ( 3840 5376 -255 ) tile [ -1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 ( 3840 5376 -256 ) ( 3840 5376 -255 ) ( 3840 5377 -256 ) tile [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 } -// brush 88 +// brush 86 { ( -256 5376 -320 ) ( -256 5377 -320 ) ( -256 5376 -319 ) tile [ 0 -1 0 0 ] [ 0 0 -1 0 ] 0 1 1 ( -256 5376 -320 ) ( -256 5376 -319 ) ( -255 5376 -320 ) tile [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 @@ -806,7 +788,7 @@ ( 640 7424 -256 ) ( 641 7424 -256 ) ( 640 7424 -255 ) tile [ -1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 ( 1792 5824 -256 ) ( 1792 5824 -255 ) ( 1792 5825 -256 ) tile [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 } -// brush 89 +// brush 87 { ( 768 768 -320 ) ( 768 768 -319 ) ( 768 767 -320 ) tile [ 0 -1 0 0 ] [ 0 0 -1 0 ] 0 1 1 ( 832 -256 -256 ) ( 832 -256 -255 ) ( 833 -256 -256 ) tile [ -1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 @@ -815,7 +797,7 @@ ( 768 768 -320 ) ( 769 768 -320 ) ( 768 768 -319 ) tile [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 ( 5888 -256 -256 ) ( 5888 -257 -256 ) ( 5888 -256 -255 ) tile [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 } -// brush 90 +// brush 88 { ( -256 -768 -320 ) ( -256 -767 -320 ) ( -256 -768 -319 ) tile [ 0 -1 0 0 ] [ 0 0 -1 0 ] 0 1 1 ( 640 -768 -320 ) ( 640 -768 -319 ) ( 641 -768 -320 ) tile [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 @@ -824,7 +806,7 @@ ( 704 1280 -256 ) ( 705 1280 -256 ) ( 704 1280 -255 ) tile [ -1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 ( 768 -704 -256 ) ( 768 -704 -255 ) ( 768 -703 -256 ) tile [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 } -// brush 91 +// brush 89 { ( 640 880 -256 ) ( 640 881 -256 ) ( 640 880 -255 ) crate [ 0 -1 0 -16 ] [ 0 0 -1 0 ] 270 1 1 ( 640 880 -256 ) ( 640 880 -255 ) ( 641 880 -256 ) crate [ 1 0 0 0 ] [ 0 0 -1 0 ] 270 1 1 @@ -833,7 +815,7 @@ ( 768 1008 -224 ) ( 769 1008 -224 ) ( 768 1008 -223 ) crate [ -1 0 0 0 ] [ 0 0 -1 0 ] 270 1 1 ( 768 1008 -224 ) ( 768 1008 -223 ) ( 768 1009 -224 ) crate [ 0 1 0 16 ] [ 0 0 -1 0 ] 270 1 1 } -// brush 92 +// brush 90 { ( 3840 2288 -256 ) ( 3840 2289 -256 ) ( 3840 2288 -255 ) fence [ 1.5931734312618293e-15 1 0 -16 ] [ 0 0 -1 0 ] 90 1 1 ( 3840 2303.375000000001 -256 ) ( 3840 2303.375000000001 -255 ) ( 3841 2303.375000000001 -256 ) fence [ -1 1.5931734312618293e-15 0 0 ] [ 0 0 -1 0 ] 90 1 1 @@ -842,7 +824,7 @@ ( 4096 2304 -224 ) ( 4097 2304 -224 ) ( 4096 2304 -223 ) fence [ 1 -1.5931734312618293e-15 0 0 ] [ 0 0 -1 0 ] 90 1 1 ( 4864 2320 -224 ) ( 4864 2320 -223 ) ( 4864 2321 -224 ) fence [ -1.5931734312618293e-15 -1 0 16 ] [ 0 0 -1 0 ] 90 1 1 } -// brush 93 +// brush 91 { ( 4560 2304 -128 ) ( 4560 2560 -256 ) ( 4560 2560 -128 ) crate [ 0 -1 0 0 ] [ 0 0 -1 0 ] 180 1 1 ( 4816 2304 -128 ) ( 4560 2304 -256 ) ( 4560 2304 -128 ) crate [ 1 0 0 48 ] [ 0 0 -1 0 ] 0 1 1 @@ -851,7 +833,7 @@ ( 4816 2560 -128 ) ( 4560 2560 -256 ) ( 4816 2560 -256 ) crate [ -1 0 0 80 ] [ 0 0 -1 0 ] 0 1 1 ( 4816 2560 -128 ) ( 4816 2304 -256 ) ( 4816 2304 -128 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 } -// brush 94 +// brush 92 { ( 4688 2560 -128 ) ( 4688 2816 -256 ) ( 4688 2816 -128 ) crate [ 0 -1 0 0 ] [ 0 0 -1 0 ] 180 1 1 ( 4816 2560 -128 ) ( 4560 2560 -256 ) ( 4560 2560 -128 ) crate [ 1 0 0 48 ] [ 0 0 -1 0 ] 180 1 1 @@ -860,7 +842,7 @@ ( 4816 2688 -128 ) ( 4560 2688 -256 ) ( 4816 2688 -256 ) crate [ -1 0 0 -48 ] [ 0 0 -1 0 ] 90 1 1 ( 4816 2816 -128 ) ( 4816 2560 -256 ) ( 4816 2560 -128 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 180 1 1 } -// brush 95 +// brush 93 { ( 4864 3056 -256 ) ( 4864 3057 -256 ) ( 4864 3056 -255 ) fence [ 1.5931734312618293e-15 1 0 -16 ] [ 0 0 -1 0 ] 90 1 1 ( 4864 3071.375000000001 -256 ) ( 4864 3071.375000000001 -255 ) ( 4865 3071.375000000001 -256 ) fence [ -1 1.5931734312618293e-15 0 0 ] [ 0 0 -1 0 ] 90 1 1 @@ -869,7 +851,7 @@ ( 5120 3072 -224 ) ( 5121 3072 -224 ) ( 5120 3072 -223 ) fence [ 1 -1.5931734312618293e-15 0 0 ] [ 0 0 -1 0 ] 90 1 1 ( 5888 3088 -224 ) ( 5888 3088 -223 ) ( 5888 3089 -224 ) fence [ -1.5931734312618293e-15 -1 0 16 ] [ 0 0 -1 0 ] 90 1 1 } -// brush 96 +// brush 94 { ( 1536 5568 -128 ) ( 1536 5824 -256 ) ( 1536 5824 -128 ) crate [ 0 -1 0 64 ] [ 0 0 -1 0 ] 180 1 1 ( 1792 5568 -128 ) ( 1536 5568 -256 ) ( 1536 5568 -128 ) crate [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 @@ -878,7 +860,7 @@ ( 1792 5824 -128 ) ( 1536 5824 -256 ) ( 1792 5824 -256 ) crate [ -1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 ( 1792 5824 -128 ) ( 1792 5568 -256 ) ( 1792 5568 -128 ) crate [ 0 1 0 -64 ] [ 0 0 -1 0 ] 0 1 1 } -// brush 97 +// brush 95 { ( 1664 5824 -128 ) ( 1664 6080 -256 ) ( 1664 6080 -128 ) crate [ 0 -1 0 64 ] [ 0 0 -1 0 ] 270 1 1 ( 1792 5824 -128 ) ( 1536 5824 -256 ) ( 1536 5824 -128 ) crate [ 1 0 0 0 ] [ 0 0 -1 0 ] 270 1 1 @@ -887,7 +869,7 @@ ( 1792 5952 -128 ) ( 1536 5952 -256 ) ( 1792 5952 -256 ) crate [ -1 0 0 0 ] [ 0 0 -1 0 ] 180 1 1 ( 1792 6080 -128 ) ( 1792 5824 -256 ) ( 1792 5824 -128 ) crate [ 0 1 0 -64 ] [ 0 0 -1 0 ] 270 1 1 } -// brush 98 +// brush 96 { ( 1664 5568 128 ) ( 1664 5824 0 ) ( 1664 5824 128 ) crate [ 0 -1 0 -64 ] [ 0 0 -1 0 ] 270 1 1 ( 1792 5568 128 ) ( 1536 5568 0 ) ( 1536 5568 128 ) crate [ 1 0 0 0 ] [ 0 0 -1 0 ] 270 1 1 @@ -946,3 +928,15 @@ ( 1152 256 -224 ) ( 1152 255 -224 ) ( 1152 256 -223 ) fence [ -1.9967346175427393e-16 -1 0 0 ] [ 0 0 -1 0 ] 0 1 1 } } +// entity 7 +{ +"classname" "pivot" +"origin" "1151.38 0 -248" +"name" "fence_01" +} +// entity 8 +{ +"classname" "pivot" +"origin" "1151.38 512 -248" +"name" "fence_02" +} diff --git a/src/gates.rs b/src/gates.rs new file mode 100644 index 0000000..0a65846 --- /dev/null +++ b/src/gates.rs @@ -0,0 +1,51 @@ +use std::collections::HashMap; + +use avian3d::math::PI; +use bevy::{prelude::*, state::commands}; + +use crate::tb_entities::{NamedEntity, Pivot}; + +#[derive(Resource)] +enum GatesState { + Init, + GateOpen1, +} + +pub fn plugin(app: &mut App) { + app.insert_resource(GatesState::Init); + app.add_systems(Update, update); +} + +fn update( + keyboard: Res>, + mut state: ResMut, + mut names_entities: Query<(&NamedEntity, &mut Transform), Without>, + pivot_entities: Query<(&Pivot, &Transform)>, +) { + if keyboard.just_pressed(KeyCode::Digit1) { + if matches!(*state, GatesState::Init) { + *state = GatesState::GateOpen1; + + let fences: HashMap<_, _> = vec![ + ("fence_01", Quat::from_rotation_y(PI / -2.)), + ("fence_02", Quat::from_rotation_y(PI / 2.)), + ] + .into_iter() + .collect(); + + for (named_entity, mut transform) in names_entities.iter_mut() { + if let Some(fence) = fences.get(named_entity.name.as_str()) { + let Some((_, t)) = pivot_entities + .iter() + .find(|(p, _)| &p.name == named_entity.name.as_str()) + else { + warn!("Pivot not found for {}", named_entity.name); + continue; + }; + + transform.rotate_around(t.translation, *fence); + } + } + } + } +} diff --git a/src/main.rs b/src/main.rs index 64a7f0a..199efac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ mod alien; mod camera; mod cash; +mod gates; mod heads_ui; mod player; mod tb_entities; @@ -58,6 +59,7 @@ fn main() { app.add_plugins(cash::plugin); app.add_plugins(player::plugin); app.add_plugins(heads_ui::plugin); + app.add_plugins(gates::plugin); app.insert_resource(AmbientLight { color: Color::WHITE, diff --git a/src/tb_entities.rs b/src/tb_entities.rs index cd3f22b..1bb6ae9 100644 --- a/src/tb_entities.rs +++ b/src/tb_entities.rs @@ -42,6 +42,13 @@ pub struct NamedEntity { pub name: String, } +#[derive(PointClass, Component, Reflect, Default)] +#[reflect(Component)] +#[require(Transform)] +pub struct Pivot { + pub name: String, +} + #[derive(PointClass, Component, Reflect, Default)] #[reflect(Component)] #[require(Transform)] diff --git a/trenchbroom/hedz/hedz.fgd b/trenchbroom/hedz/hedz.fgd index 75dd88b..d5828ed 100644 --- a/trenchbroom/hedz/hedz.fgd +++ b/trenchbroom/hedz/hedz.fgd @@ -69,6 +69,11 @@ name(string) : "name" : "" : "" ] +@PointClass base(transform) = pivot +[ + name(string) : "name" : "" : "" +] + @PointClass base(transform) model({ "path": "models/spawn.glb" }) = spawn_point [ ]