gate open animation using new movables

This commit is contained in:
2025-03-09 21:06:51 +01:00
parent 7bc6995e18
commit 2a611c9eaa
6 changed files with 194 additions and 77 deletions

View File

@@ -641,57 +641,11 @@
} }
// entity 5 // entity 5
{ {
"classname" "named_entity"
"name" "fence_02"
// brush 0
{
( 1136 496 -256 ) ( 1136 497 -256 ) ( 1136 496 -255 ) origin [ 0 -1 0 0 ] [ 0 0 -1 0 ] 270 1 1
( 1136 496 -256 ) ( 1136 496 -255 ) ( 1137 496 -256 ) origin [ 1 0 0 0 ] [ 0 0 -1 0 ] 270 1 1
( 1136 496 -256 ) ( 1137 496 -256 ) ( 1136 497 -256 ) origin [ -1 0 0 0 ] [ 0 -1 0 0 ] 270 1 1
( 1168 528 -240 ) ( 1168 529 -240 ) ( 1169 528 -240 ) origin [ 1 0 0 0 ] [ 0 -1 0 0 ] 270 1 1
( 1168 528 -240 ) ( 1169 528 -240 ) ( 1168 528 -239 ) origin [ -1 0 0 0 ] [ 0 0 -1 0 ] 270 1 1
( 1168 528 -240 ) ( 1168 528 -239 ) ( 1168 529 -240 ) origin [ 0 1 0 0 ] [ 0 0 -1 0 ] 270 1 1
}
// brush 1
{
( 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
}
}
// entity 6
{
"classname" "named_entity"
"name" "fence_01"
// brush 0
{
( 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 1
{
( 1136 -16 -256 ) ( 1136 -15 -256 ) ( 1136 -16 -255 ) origin [ 0 -1 0 0 ] [ 0 0 -1 0 ] 270 1 1
( 1136 -16 -256 ) ( 1136 -16 -255 ) ( 1137 -16 -256 ) origin [ 1 0 0 0 ] [ 0 0 -1 0 ] 270 1 1
( 1136 -16 -256 ) ( 1137 -16 -256 ) ( 1136 -15 -256 ) origin [ -1 0 0 0 ] [ 0 -1 0 0 ] 270 1 1
( 1168 16 -240 ) ( 1168 17 -240 ) ( 1169 16 -240 ) origin [ 1 0 0 0 ] [ 0 -1 0 0 ] 270 1 1
( 1168 16 -240 ) ( 1169 16 -240 ) ( 1168 16 -239 ) origin [ -1 0 0 0 ] [ 0 0 -1 0 ] 270 1 1
( 1168 16 -240 ) ( 1168 16 -239 ) ( 1168 17 -240 ) origin [ 0 1 0 0 ] [ 0 0 -1 0 ] 270 1 1
}
}
// entity 7
{
"classname" "platform_target" "classname" "platform_target"
"origin" "1672 5249 776" "origin" "1672 5249 776"
"targetname" "secret_platform" "targetname" "secret_platform"
} }
// entity 8 // entity 6
{ {
"classname" "crates" "classname" "crates"
// brush 0 // brush 0
@@ -704,7 +658,7 @@
( 768 1008 -224 ) ( 768 1008 -223 ) ( 768 1009 -224 ) crate [ 0 1 0 16 ] [ 0 0 -1 0 ] 90 1 1 ( 768 1008 -224 ) ( 768 1008 -223 ) ( 768 1009 -224 ) crate [ 0 1 0 16 ] [ 0 0 -1 0 ] 90 1 1
} }
} }
// entity 9 // entity 7
{ {
"classname" "crates" "classname" "crates"
// brush 0 // brush 0
@@ -717,7 +671,7 @@
( 768 1264 -128 ) ( 768 1008 -256 ) ( 768 1008 -128 ) crate [ 0 1 0 16 ] [ 0 0 -1 0 ] 0 1 1 ( 768 1264 -128 ) ( 768 1008 -256 ) ( 768 1008 -128 ) crate [ 0 1 0 16 ] [ 0 0 -1 0 ] 0 1 1
} }
} }
// entity 10 // entity 8
{ {
"classname" "crates" "classname" "crates"
// brush 0 // brush 0
@@ -730,7 +684,7 @@
( 3568 512 -224 ) ( 3568 512 -223 ) ( 3568 513 -224 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 270 1 1 ( 3568 512 -224 ) ( 3568 512 -223 ) ( 3568 513 -224 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 270 1 1
} }
} }
// entity 11 // entity 9
{ {
"classname" "crates" "classname" "crates"
// brush 0 // brush 0
@@ -743,7 +697,7 @@
( 3568 768 -128 ) ( 3568 512 -256 ) ( 3568 512 -128 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 270 1 1 ( 3568 768 -128 ) ( 3568 512 -256 ) ( 3568 512 -128 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 270 1 1
} }
} }
// entity 12 // entity 10
{ {
"classname" "crates" "classname" "crates"
// brush 0 // brush 0
@@ -756,7 +710,7 @@
( 3568 768 32 ) ( 3568 768 33 ) ( 3568 769 32 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 270 1 1 ( 3568 768 32 ) ( 3568 768 33 ) ( 3568 769 32 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 270 1 1
} }
} }
// entity 13 // entity 11
{ {
"classname" "crates" "classname" "crates"
// brush 0 // brush 0
@@ -769,7 +723,7 @@
( 3856 512 -224 ) ( 3856 512 -223 ) ( 3856 513 -224 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 90 1 1 ( 3856 512 -224 ) ( 3856 512 -223 ) ( 3856 513 -224 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 90 1 1
} }
} }
// entity 14 // entity 12
{ {
"classname" "crates" "classname" "crates"
// brush 0 // brush 0
@@ -782,7 +736,7 @@
( 3856 768 -128 ) ( 3856 512 -256 ) ( 3856 512 -128 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 ( 3856 768 -128 ) ( 3856 512 -256 ) ( 3856 512 -128 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1
} }
} }
// entity 15 // entity 13
{ {
"classname" "crates" "classname" "crates"
// brush 0 // brush 0
@@ -795,7 +749,7 @@
( 3728 768 32 ) ( 3728 768 33 ) ( 3728 769 32 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 90 1 1 ( 3728 768 32 ) ( 3728 768 33 ) ( 3728 769 32 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 90 1 1
} }
} }
// entity 16 // entity 14
{ {
"classname" "crates" "classname" "crates"
// brush 0 // brush 0
@@ -808,7 +762,7 @@
( 4816 2816 -128 ) ( 4816 2560 -256 ) ( 4816 2560 -128 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 180 1 1 ( 4816 2816 -128 ) ( 4816 2560 -256 ) ( 4816 2560 -128 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 180 1 1
} }
} }
// entity 17 // entity 15
{ {
"classname" "crates" "classname" "crates"
// brush 0 // brush 0
@@ -821,7 +775,7 @@
( 1792 6144 -128 ) ( 1792 5888 -256 ) ( 1792 5888 -128 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 180 1 1 ( 1792 6144 -128 ) ( 1792 5888 -256 ) ( 1792 5888 -128 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 180 1 1
} }
} }
// entity 18 // entity 16
{ {
"classname" "crates" "classname" "crates"
// brush 0 // brush 0
@@ -834,7 +788,7 @@
( 1792 5888 128 ) ( 1792 5632 0 ) ( 1792 5632 128 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 180 1 1 ( 1792 5888 128 ) ( 1792 5632 0 ) ( 1792 5632 128 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 180 1 1
} }
} }
// entity 19 // entity 17
{ {
"classname" "crates" "classname" "crates"
// brush 0 // brush 0
@@ -847,7 +801,7 @@
( 1792 5888 -128 ) ( 1792 5632 -256 ) ( 1792 5632 -128 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 270 1 1 ( 1792 5888 -128 ) ( 1792 5632 -256 ) ( 1792 5632 -128 ) crate [ 0 1 0 0 ] [ 0 0 -1 0 ] 270 1 1
} }
} }
// entity 20 // entity 18
{ {
"classname" "platform" "classname" "platform"
"target" "secret_platform" "target" "secret_platform"
@@ -870,3 +824,67 @@
( 1680 5264 144 ) ( 1680 5264 145 ) ( 1680 5265 144 ) origin [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 ( 1680 5264 144 ) ( 1680 5264 145 ) ( 1680 5265 144 ) origin [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1
} }
} }
// entity 19
{
"classname" "move_target"
"origin" "1152 0 -232"
"angles" "0 0 0"
"targetname" "target_fence_01"
}
// entity 20
{
"classname" "movable"
"name" "fence_01"
"target" "target_fence_01"
"rotation" "true"
// brush 0
{
( 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 1
{
( 1136 -16 -256 ) ( 1136 -15 -256 ) ( 1136 -16 -255 ) origin [ 0 -1 0 0 ] [ 0 0 -1 0 ] 270 1 1
( 1136 -16 -256 ) ( 1136 -16 -255 ) ( 1137 -16 -256 ) origin [ 1 0 0 0 ] [ 0 0 -1 0 ] 270 1 1
( 1136 -16 -256 ) ( 1137 -16 -256 ) ( 1136 -15 -256 ) origin [ -1 0 0 0 ] [ 0 -1 0 0 ] 270 1 1
( 1168 16 -240 ) ( 1168 17 -240 ) ( 1169 16 -240 ) origin [ 1 0 0 0 ] [ 0 -1 0 0 ] 270 1 1
( 1168 16 -240 ) ( 1169 16 -240 ) ( 1168 16 -239 ) origin [ -1 0 0 0 ] [ 0 0 -1 0 ] 270 1 1
( 1168 16 -240 ) ( 1168 16 -239 ) ( 1168 17 -240 ) origin [ 0 1 0 0 ] [ 0 0 -1 0 ] 270 1 1
}
}
// entity 21
{
"classname" "move_target"
"origin" "1152 512 -232"
"angles" "0 -180 0"
"targetname" "target_fence_02"
}
// entity 22
{
"classname" "movable"
"name" "fence_02"
"rotation" "true"
"target" "target_fence_02"
// brush 0
{
( 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 1
{
( 1136 496 -256 ) ( 1136 497 -256 ) ( 1136 496 -255 ) origin [ 0 -1 0 0 ] [ 0 0 -1 0 ] 270 1 1
( 1136 496 -256 ) ( 1136 496 -255 ) ( 1137 496 -256 ) origin [ 1 0 0 0 ] [ 0 0 -1 0 ] 270 1 1
( 1136 496 -256 ) ( 1137 496 -256 ) ( 1136 497 -256 ) origin [ -1 0 0 0 ] [ 0 -1 0 0 ] 270 1 1
( 1168 528 -240 ) ( 1168 529 -240 ) ( 1169 528 -240 ) origin [ 1 0 0 0 ] [ 0 -1 0 0 ] 270 1 1
( 1168 528 -240 ) ( 1169 528 -240 ) ( 1168 528 -239 ) origin [ -1 0 0 0 ] [ 0 0 -1 0 ] 270 1 1
( 1168 528 -240 ) ( 1168 528 -239 ) ( 1168 529 -240 ) origin [ 0 1 0 0 ] [ 0 0 -1 0 ] 270 1 1
}
}

View File

@@ -1,9 +1,5 @@
use std::collections::HashMap; use crate::movables::TriggerMovableEvent;
use bevy::{prelude::*, utils::hashbrown::HashSet};
use avian3d::math::PI;
use bevy::prelude::*;
use crate::tb_entities::NamedEntity;
#[derive(Resource)] #[derive(Resource)]
enum GatesState { enum GatesState {
@@ -20,7 +16,6 @@ fn update(
mut commands: Commands, mut commands: Commands,
keyboard: Res<ButtonInput<KeyCode>>, keyboard: Res<ButtonInput<KeyCode>>,
mut state: ResMut<GatesState>, mut state: ResMut<GatesState>,
mut names_entities: Query<(&NamedEntity, &mut Transform)>,
asset_server: Res<AssetServer>, asset_server: Res<AssetServer>,
) { ) {
if keyboard.just_pressed(KeyCode::Digit1) { if keyboard.just_pressed(KeyCode::Digit1) {
@@ -38,18 +33,12 @@ fn update(
PlaybackSettings::DESPAWN, PlaybackSettings::DESPAWN,
)); ));
let fences: HashMap<_, _> = vec![ let entities: HashSet<_> = vec!["fence_01", "fence_02"]
("fence_01", Quat::from_rotation_y(PI / -2.)), .into_iter()
("fence_02", Quat::from_rotation_y(PI / 2.)), .map(|s| String::from(s))
] .collect();
.into_iter()
.collect();
for (named_entity, mut transform) in names_entities.iter_mut() { commands.trigger(TriggerMovableEvent(entities));
if let Some(fence) = fences.get(named_entity.name.as_str()) {
transform.rotate(*fence);
}
}
} }
} }
} }

View File

@@ -3,6 +3,7 @@ mod camera;
mod cash; mod cash;
mod gates; mod gates;
mod heads_ui; mod heads_ui;
mod movables;
mod platforms; mod platforms;
mod player; mod player;
mod tb_entities; mod tb_entities;
@@ -70,6 +71,7 @@ fn main() {
app.add_plugins(heads_ui::plugin); app.add_plugins(heads_ui::plugin);
app.add_plugins(gates::plugin); app.add_plugins(gates::plugin);
app.add_plugins(platforms::plugin); app.add_plugins(platforms::plugin);
app.add_plugins(movables::plugin);
app.insert_resource(AmbientLight { app.insert_resource(AmbientLight {
color: Color::WHITE, color: Color::WHITE,

83
src/movables.rs Normal file
View File

@@ -0,0 +1,83 @@
use crate::tb_entities::{Movable, MoveTarget};
use bevy::{prelude::*, utils::HashSet};
use bevy_trenchbroom::class::Target;
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
struct ActiveMovable {
pub start: Transform,
pub target: Transform,
pub start_time: f32,
pub duration: f32,
}
#[derive(Event)]
pub struct TriggerMovableEvent(pub HashSet<String>);
pub fn plugin(app: &mut App) {
app.register_type::<ActiveMovable>();
app.add_systems(Update, move_active);
app.add_observer(trigger);
}
fn trigger(
trigger: Trigger<TriggerMovableEvent>,
mut commands: Commands,
uninit_movables: Query<
(Entity, &Target, &Transform, &Movable),
(Without<ActiveMovable>, With<Movable>),
>,
targets: Query<(&MoveTarget, &Transform)>,
time: Res<Time>,
) {
info!("trigger: {:?}", trigger.0);
for (e, target, transform, movable) in uninit_movables.iter() {
if !trigger.0.contains(&movable.name) {
continue;
}
let target_name = target.target.clone().unwrap_or_default();
let Some(target) = targets
.iter()
.find(|(t, _)| t.targetname == target_name)
.map(|(_, t)| *t)
else {
continue;
};
info!("found target: {:?}", target_name);
let target: Transform =
Transform::from_translation(transform.translation).with_rotation(target.rotation);
let platform = ActiveMovable {
start: *transform,
target,
start_time: time.elapsed_secs(),
//TODO: make this configurable
duration: 1.,
};
commands.entity(e).insert(platform);
}
}
fn move_active(
mut commands: Commands,
mut platforms: Query<(Entity, &mut Transform, &mut ActiveMovable)>,
time: Res<Time>,
) {
let elapsed = time.elapsed_secs();
for (e, mut transform, active) in platforms.iter_mut() {
if elapsed < active.start_time + active.duration {
let t = (elapsed - active.start_time) / active.duration;
transform.rotation = active.start.rotation.lerp(active.target.rotation, t);
} else {
*transform = active.target;
commands.entity(e).remove::<(ActiveMovable, Movable)>();
}
}
}

View File

@@ -63,6 +63,21 @@ pub struct PlatformTarget {
pub targetname: String, pub targetname: String,
} }
#[derive(SolidClass, Component, Reflect, Default)]
#[reflect(Component)]
#[require(Transform, Target)]
#[geometry(GeometryProvider::new().trimesh_collider().render())]
pub struct Movable {
pub name: String,
}
#[derive(PointClass, Component, Reflect, Default)]
#[reflect(Component)]
#[require(Transform)]
pub struct MoveTarget {
pub targetname: String,
}
#[derive(PointClass, Component, Reflect, Default)] #[derive(PointClass, Component, Reflect, Default)]
#[reflect(Component)] #[reflect(Component)]
#[require(Transform)] #[require(Transform)]

View File

@@ -68,6 +68,16 @@
[ [
] ]
@SolidClass base(transform, target) = movable
[
name(string) : "name" : "" : ""
]
@PointClass base(transform) = move_target
[
targetname(string) : "targetname" : "" : ""
]
@SolidClass base(transform) = named_entity @SolidClass base(transform) = named_entity
[ [
name(string) : "name" : "" : "" name(string) : "name" : "" : ""