almost done
This commit is contained in:
@@ -5,7 +5,13 @@ use bevy_rapier3d::prelude::*;
|
||||
use rand::{Rng, seq::IteratorRandom};
|
||||
|
||||
use crate::{
|
||||
asset_loading::{GltfAssets, ImageAssets}, interaction::Interact, player::{toolbar::ItemIcon, Player, PlayerAction}, GameState
|
||||
GameState,
|
||||
asset_loading::{GltfAssets, ImageAssets},
|
||||
interaction::{
|
||||
Interact,
|
||||
objects::{KeyCardId, OpenedByKey, PickUpAble},
|
||||
},
|
||||
player::{Player, PlayerAction, toolbar::ItemIcon},
|
||||
};
|
||||
|
||||
pub fn map_plugin(app: &mut App) {
|
||||
@@ -593,7 +599,9 @@ fn spawn_objects(
|
||||
.spawn((
|
||||
transform,
|
||||
Interact,
|
||||
PickUpAble,
|
||||
RigidBody::Dynamic,
|
||||
KeyCardId(i),
|
||||
Name::new(format!("Id Card {i}")),
|
||||
Visibility::Visible,
|
||||
ItemIcon::new(image_assets.id_card.clone()),
|
||||
@@ -624,7 +632,7 @@ fn spawn_objects(
|
||||
pub struct Door {
|
||||
pub is_open: bool,
|
||||
pub open_direction: (i32, i32),
|
||||
pub position: (i32, i32)
|
||||
pub position: (i32, i32),
|
||||
}
|
||||
|
||||
fn spawn_doors(
|
||||
@@ -644,43 +652,55 @@ fn spawn_doors(
|
||||
let asset = gltf.default_scene.as_ref().unwrap();
|
||||
let scene_root = SceneRoot(asset.clone());
|
||||
|
||||
for level in levels.levels.iter() {
|
||||
for (i, level) in levels.levels.iter().enumerate() {
|
||||
let (x, z) = level.end_node;
|
||||
let (direction, transform) = if x >= z {
|
||||
(
|
||||
(0, 1),
|
||||
Transform::from_xyz(2.0 * x as f32, 0.0, -2.0 * z as f32)
|
||||
.with_rotation(Quat::from_rotation_y(90.0_f32.to_radians()))
|
||||
.with_rotation(Quat::from_rotation_y(90.0_f32.to_radians())),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
(1, 0),
|
||||
Transform::from_xyz(2.0 * x as f32, 0.0, -2.0 * z as f32)
|
||||
Transform::from_xyz(2.0 * x as f32, 0.0, -2.0 * z as f32),
|
||||
)
|
||||
};
|
||||
commands.spawn((
|
||||
RigidBody::Fixed,
|
||||
Door {
|
||||
is_open: false,
|
||||
open_direction: direction,
|
||||
position: (x, z)
|
||||
},
|
||||
transform,
|
||||
scene_root.clone(),
|
||||
)).with_children(|parent| {
|
||||
for (collider, transform) in collider.clone() {
|
||||
parent.spawn((collider, transform));
|
||||
}
|
||||
});
|
||||
commands
|
||||
.spawn((
|
||||
// very scuff but need this
|
||||
OpenedByKey(KeyCardId(i)),
|
||||
Interact,
|
||||
RigidBody::Fixed,
|
||||
Name::new("Door"),
|
||||
Door {
|
||||
is_open: false,
|
||||
open_direction: direction,
|
||||
position: (x, z),
|
||||
},
|
||||
transform,
|
||||
scene_root.clone(),
|
||||
))
|
||||
.with_children(|parent| {
|
||||
for (collider, transform) in collider.clone() {
|
||||
parent.spawn((collider, transform));
|
||||
}
|
||||
// make it "interactable" in the world
|
||||
parent.spawn((
|
||||
ActiveEvents::COLLISION_EVENTS,
|
||||
Transform::default(),
|
||||
Collider::ball(0.5), // Interaction radius
|
||||
Sensor,
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_door_pos(mut query: Query<(&Door, &mut Transform)>) {
|
||||
for (door, mut transform) in query.iter_mut() {
|
||||
if door.is_open {
|
||||
if door.is_open {
|
||||
transform.translation.y = 2.0
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
transform.translation.y = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user