maze walls
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
8
src/debugging.rs
Normal file
8
src/debugging.rs
Normal 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());
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use bevy_rapier3d::prelude::{Collider, RigidBody};
|
||||||
|
|
||||||
use crate::{asset_loading::GltfAssets, GameState};
|
use crate::{asset_loading::GltfAssets, GameState};
|
||||||
|
|
||||||
@@ -12,13 +13,37 @@ fn spawn_level(
|
|||||||
gltf_assets: Res<GltfAssets>
|
gltf_assets: Res<GltfAssets>
|
||||||
) {
|
) {
|
||||||
println!("LIBRARY: {:?}", gltf_assets.library);
|
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 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 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 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));
|
let asset = gltf.default_scene.as_ref().expect(&format!("No scene in {}", mesh_name));
|
||||||
SceneRoot(asset.clone())
|
(SceneRoot(asset.clone()), collider)
|
||||||
});
|
});
|
||||||
let [
|
let [
|
||||||
corner_inside,
|
corner_inside,
|
||||||
@@ -28,18 +53,44 @@ fn spawn_level(
|
|||||||
round_door,
|
round_door,
|
||||||
round_hole
|
round_hole
|
||||||
] = shapes;
|
] = shapes;
|
||||||
let mut x_offset = 0.0;
|
for i in 0..30 {
|
||||||
for i in 0..10 {
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
wall.clone(),
|
wall.0.clone(),
|
||||||
Transform::from_xyz(i as f32 * 2.0, 0.0, 0.0),
|
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((
|
commands.spawn((
|
||||||
wall.clone(),
|
wall.0.clone(),
|
||||||
Transform::from_xyz(i as f32 * 2.0, 0.0, 0.0)
|
Transform::from_xyz(i as f32 * 2.0, 0.0, 0.0)
|
||||||
.with_rotation(Quat::from_rotation_y(std::f32::consts::PI)),
|
.with_rotation(Quat::from_rotation_y(std::f32::consts::PI)),
|
||||||
));
|
)).with_children(|parent| {
|
||||||
x_offset += 2.0;
|
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),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ mod level_instantiation;
|
|||||||
mod main_menu;
|
mod main_menu;
|
||||||
mod player;
|
mod player;
|
||||||
mod util;
|
mod util;
|
||||||
|
mod debugging;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
@@ -21,6 +22,7 @@ fn main() {
|
|||||||
RapierPhysicsPlugin::<NoUserData>::default(),
|
RapierPhysicsPlugin::<NoUserData>::default(),
|
||||||
RapierDebugRenderPlugin::default(),
|
RapierDebugRenderPlugin::default(),
|
||||||
player::plugin,
|
player::plugin,
|
||||||
|
debugging::plugin
|
||||||
))
|
))
|
||||||
.init_state::<GameState>()
|
.init_state::<GameState>()
|
||||||
.add_systems(OnEnter(GameState::Playing), setup)
|
.add_systems(OnEnter(GameState::Playing), setup)
|
||||||
@@ -55,7 +57,7 @@ fn setup(
|
|||||||
commands.spawn((
|
commands.spawn((
|
||||||
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
|
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
|
||||||
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
|
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,
|
RigidBody::Fixed,
|
||||||
Collider::cuboid(0.5, 0.5, 0.5),
|
Collider::cuboid(0.5, 0.5, 0.5),
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -66,7 +66,10 @@ pub fn init_player(
|
|||||||
angular_damping: 1.0,
|
angular_damping: 1.0,
|
||||||
},
|
},
|
||||||
GravityScale(3.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| {
|
.with_children(|parent| {
|
||||||
parent.spawn((
|
parent.spawn((
|
||||||
@@ -87,13 +90,13 @@ pub fn init_player(
|
|||||||
},
|
},
|
||||||
RenderLayers::layer(STATIC_LAYER),
|
RenderLayers::layer(STATIC_LAYER),
|
||||||
));
|
));
|
||||||
|
|
||||||
let window_size = Vec2::new(window.resolution.width(), window.resolution.height());
|
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 scale = window.resolution.width() / 600.0;
|
||||||
let world_size = sprite_size * scale;
|
let world_size = sprite_size * scale;
|
||||||
let offset = window_size.x / 4.0 - 40.0;
|
let offset = window_size.x / 4.0 - 40.0;
|
||||||
|
|
||||||
let mut transform = Transform::from_translation(
|
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)
|
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)
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user