maze walls

This commit is contained in:
AmadeusWM
2025-04-06 01:41:20 +02:00
parent de69318f51
commit 0f6b416ae4
7 changed files with 78 additions and 14 deletions

View File

@@ -1,4 +1,5 @@
use bevy::prelude::*;
use bevy_rapier3d::prelude::{Collider, RigidBody};
use crate::{asset_loading::GltfAssets, GameState};
@@ -12,13 +13,37 @@ fn spawn_level(
gltf_assets: Res<GltfAssets>
) {
println!("LIBRARY: {:?}", gltf_assets.library);
let shapes = ["corner_inside", "corner_outside", "wall", "door", "round_door", "round_hole"].map(|mesh_name| {
let mesh_names = ["corner_inside", "corner_outside", "wall", "door", "round_door", "round_hole"];
let shapes = mesh_names.map(|mesh_name| {
let collider: Vec<(Collider, Transform)> = match mesh_name {
"corner_inside" => vec![
(Collider::cuboid(1.0, 0.1, 1.0), Transform::from_xyz(0.0, 0.0, 0.0))
],
"corner_outside" => vec![
(Collider::cuboid(1.0, 0.1, 1.0), Transform::from_xyz(0.0, 0.0, 0.0))
],
"wall" => vec![
(Collider::cuboid(1.0, 1.0, 0.1), Transform::from_xyz(0.0, 0.5, -1.0))
],
"door" => vec![
(Collider::cuboid(1.0, 0.1, 1.0), Transform::from_xyz(0.0, 0.0, 0.0))
],
"round_door" => vec![
(Collider::cuboid(1.0, 0.1, 1.0), Transform::from_xyz(0.0, 0.0, 0.0))
],
"round_hole" => vec![
(Collider::cuboid(1.0, 0.1, 1.0), Transform::from_xyz(0.0, 0.0, 0.0))
],
_ => vec![
(Collider::cuboid(1.0, 0.1, 1.0), Transform::from_xyz(0.0, 0.0, 0.0))
],
};
let path = format!("meshes/library/space_{}.glb", mesh_name);
let handle = gltf_assets.library.get(&path).expect(&format!("Couldn't find {} in library", mesh_name));
let gltf = models.get(handle).expect(&format!("No model for {}", mesh_name));
let asset = gltf.default_scene.as_ref().expect(&format!("No scene in {}", mesh_name));
SceneRoot(asset.clone())
(SceneRoot(asset.clone()), collider)
});
let [
corner_inside,
@@ -28,18 +53,44 @@ fn spawn_level(
round_door,
round_hole
] = shapes;
let mut x_offset = 0.0;
for i in 0..10 {
for i in 0..30 {
commands.spawn((
wall.clone(),
wall.0.clone(),
Transform::from_xyz(i as f32 * 2.0, 0.0, 0.0),
));
)).with_children(|parent| {
for ele in wall.1.clone() {
parent.spawn((
RigidBody::Fixed,
ele.0,
ele.1,
));
}
});
commands.spawn((
wall.clone(),
wall.0.clone(),
Transform::from_xyz(i as f32 * 2.0, 0.0, 0.0)
.with_rotation(Quat::from_rotation_y(std::f32::consts::PI)),
));
x_offset += 2.0;
)).with_children(|parent| {
for ele in wall.1.clone() {
parent.spawn((
RigidBody::Fixed,
ele.0,
ele.1,
));
}
});
}
// huge floor
commands.spawn((
RigidBody::Fixed,
Collider::cuboid(1000.0, 0.1, 1000.0),
Transform::from_xyz(-500.0, 0.0, -500.0),
));
commands.spawn((
RigidBody::Fixed,
Collider::cuboid(1000.0, 0.1, 1000.0),
Transform::from_xyz(-500.0, 3.0, -500.0),
));
}