improve graphics and add camera controls

This commit is contained in:
Jim 2025-08-24 14:46:57 -04:00
parent 82a0fbdb50
commit 87fcc2b817
Signed by: jim
GPG key ID: 3236D2F059A7C0AC
12 changed files with 367 additions and 93 deletions

13
crates/level/Cargo.toml Normal file
View file

@ -0,0 +1,13 @@
[package]
name = "level"
version = "0.1.0"
edition = "2024"
[dependencies]
bevy = { workspace = true }
state = { path = "../state" }
camera = { path = "../camera" }
avian3d = { workspace = true }
[lints]
workspace = true

85
crates/level/src/lib.rs Normal file
View file

@ -0,0 +1,85 @@
//bevy system signatures often violate these rules
#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]
use avian3d::prelude::*;
use bevy::{
core_pipeline::{bloom::Bloom, experimental::taa::TemporalAntiAliasing},
pbr::{Atmosphere, ScreenSpaceAmbientOcclusion, light_consts::lux},
prelude::*,
render::camera::Exposure,
};
use camera::ControlledCamera;
use state::AppState;
pub struct LevelPlugin;
impl Plugin for LevelPlugin {
fn build(&self, app: &mut App) {
app.add_systems(OnEnter(AppState::Game), setup);
}
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let level_size = 50.0;
// Static physics object with a collision shape
commands.spawn((
RigidBody::Static,
Collider::cuboid(level_size, 0.5, level_size),
Mesh3d(meshes.add(Cuboid::new(level_size, 0.5, level_size))),
MeshMaterial3d(materials.add(StandardMaterial {
base_color: Color::srgb_u8(52, 125, 117),
perceptual_roughness: 0.8,
..default()
})),
));
// Dynamic physics object with a collision shape and initial angular velocity
for y in 5..15 {
commands.spawn((
RigidBody::Dynamic,
Collider::cuboid(1.0, 1.0, 1.0),
AngularVelocity(Vec3::new(2.5, 3.5, 1.5)),
Mesh3d(meshes.add(Cuboid::from_length(1.0))),
MeshMaterial3d(materials.add(StandardMaterial {
base_color: Color::srgb_u8(220, 156, 86),
metallic: 1.0,
perceptual_roughness: 0.3,
..default()
})),
Transform::from_xyz(0.0, y as f32 * 1.1, 0.0),
));
}
// Light
commands.spawn((
DirectionalLight {
shadows_enabled: true,
illuminance: lux::RAW_SUNLIGHT,
color: Color::srgb(0.98, 0.95, 0.82),
..default()
},
Transform::from_xyz(-2.5, 4.5, 2.5).looking_at(Vec3::ZERO, Dir3::Y),
));
// Camera
commands.spawn((
Camera3d::default(),
Camera {
hdr: true,
..default()
},
ControlledCamera::default(),
Msaa::Off,
TemporalAntiAliasing::default(),
ScreenSpaceAmbientOcclusion::default(),
Atmosphere::EARTH,
Exposure::SUNLIGHT,
Bloom::NATURAL,
Transform::from_xyz(-2.5, 9.5, 9.0).looking_at(Vec3::ZERO, Dir3::Y),
));
}