work in progress platform
This commit is contained in:
@@ -3,6 +3,7 @@ mod camera;
|
||||
mod cash;
|
||||
mod gates;
|
||||
mod heads_ui;
|
||||
mod platforms;
|
||||
mod player;
|
||||
mod tb_entities;
|
||||
|
||||
@@ -66,6 +67,7 @@ fn main() {
|
||||
app.add_plugins(player::plugin);
|
||||
app.add_plugins(heads_ui::plugin);
|
||||
app.add_plugins(gates::plugin);
|
||||
app.add_plugins(platforms::plugin);
|
||||
|
||||
app.insert_resource(AmbientLight {
|
||||
color: Color::WHITE,
|
||||
|
||||
51
src/platforms.rs
Normal file
51
src/platforms.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
use crate::tb_entities::Platform;
|
||||
use bevy::{math::ops::sin, prelude::*};
|
||||
use bevy_trenchbroom::class::Target;
|
||||
|
||||
#[derive(Component, Reflect, Default, Debug)]
|
||||
#[reflect(Component)]
|
||||
struct ActivePlatform {
|
||||
pub start: Vec3,
|
||||
pub target: Vec3,
|
||||
}
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.register_type::<ActivePlatform>();
|
||||
app.add_systems(Update, (init, move_active));
|
||||
}
|
||||
|
||||
fn init(
|
||||
mut commands: Commands,
|
||||
uninit_platforms: Query<
|
||||
(Entity, &Target, &Transform),
|
||||
(Without<ActivePlatform>, With<Platform>),
|
||||
>,
|
||||
// targets: Query<(&PlatformTarget, &Transform)>,
|
||||
) {
|
||||
for (e, _target, transform) in uninit_platforms.iter() {
|
||||
// let Some(target) = targets
|
||||
// .iter()
|
||||
// .find(|(t, _)| t.targetname == target.target.clone().unwrap_or_default())
|
||||
// .map(|(_, t)| *t)
|
||||
// else {
|
||||
// continue;
|
||||
// };
|
||||
|
||||
let platform = ActivePlatform {
|
||||
start: transform.translation,
|
||||
target: transform.translation + Vec3::new(0., 20., 0.),
|
||||
};
|
||||
|
||||
info!("platform: {:?}", platform);
|
||||
|
||||
commands.entity(e).insert(platform);
|
||||
}
|
||||
}
|
||||
|
||||
fn move_active(time: Res<Time>, mut platforms: Query<(&mut Transform, &mut ActivePlatform)>) {
|
||||
for (mut transform, active) in platforms.iter_mut() {
|
||||
let t = (sin(time.elapsed_secs() * 0.5) + 1.) / 2.;
|
||||
|
||||
transform.translation = active.start.lerp(active.target, t);
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ pub struct Platform;
|
||||
#[reflect(Component)]
|
||||
#[require(Transform)]
|
||||
pub struct PlatformTarget {
|
||||
targetname: String,
|
||||
pub targetname: String,
|
||||
}
|
||||
|
||||
#[derive(PointClass, Component, Reflect, Default)]
|
||||
|
||||
Reference in New Issue
Block a user