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

Binary file not shown.

Binary file not shown.

8
src/debugging.rs Normal file
View File

@@ -0,0 +1,8 @@
use bevy::{app::App, diagnostic::FrameTimeDiagnosticsPlugin};
use bevy::diagnostic::LogDiagnosticsPlugin;
pub fn plugin(app: &mut App) {
app.add_plugins(FrameTimeDiagnosticsPlugin::default());
app.add_plugins(LogDiagnosticsPlugin::default());
}

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),
));
}

View File

@@ -9,6 +9,7 @@ mod level_instantiation;
mod main_menu;
mod player;
mod util;
mod debugging;
fn main() {
App::new()
@@ -21,6 +22,7 @@ fn main() {
RapierPhysicsPlugin::<NoUserData>::default(),
RapierDebugRenderPlugin::default(),
player::plugin,
debugging::plugin
))
.init_state::<GameState>()
.add_systems(OnEnter(GameState::Playing), setup)
@@ -55,7 +57,7 @@ fn setup(
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
Transform::from_xyz(3.0, 0.5, 0.0),
Transform::from_xyz(-3.0, 0.5, 0.0),
RigidBody::Fixed,
Collider::cuboid(0.5, 0.5, 0.5),
));

View File

@@ -66,7 +66,10 @@ pub fn init_player(
angular_damping: 1.0,
},
GravityScale(3.0),
Transform::from_xyz(0.0, 1.0, 0.0),
Transform::from_xyz(0.0, 0.5, 0.0),
GlobalTransform::default(),
InheritedVisibility::default(),
ViewVisibility::default(),
))
.with_children(|parent| {
parent.spawn((
@@ -87,13 +90,13 @@ pub fn init_player(
},
RenderLayers::layer(STATIC_LAYER),
));
let window_size = Vec2::new(window.resolution.width(), window.resolution.height());
let sprite_size = Vec2::new(101.0, 101.0);
let sprite_size = Vec2::new(101.0, 101.0);
let scale = window.resolution.width() / 600.0;
let world_size = sprite_size * scale;
let offset = window_size.x / 4.0 - 40.0;
let mut transform = Transform::from_translation(
Vec3::new(window_size.x / 2.0 - world_size.x / 2.0 - offset, -window_size.y / 2.0 + world_size.y / 2.0, 0.0)
);