You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.8 KiB
Rust
68 lines
1.8 KiB
Rust
use bevy::{color::palettes::css::*, prelude::*};
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins(DefaultPlugins)
|
|
.insert_resource(ClearColor(WHITE.into()))
|
|
.add_systems(Startup, setup_3d)
|
|
.add_systems(Update, move_camera)
|
|
.run();
|
|
}
|
|
|
|
fn setup_3d(
|
|
mut commands: Commands,
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
) {
|
|
commands.spawn((
|
|
Camera::default(),
|
|
Camera3d::default(),
|
|
AmbientLight {
|
|
brightness: 1280.0,
|
|
..default()
|
|
},
|
|
));
|
|
|
|
commands.spawn((
|
|
Mesh3d(meshes.add(Cuboid::default())),
|
|
MeshMaterial3d(materials.add(StandardMaterial {
|
|
base_color: RED.into(),
|
|
..Default::default()
|
|
})),
|
|
Transform::from_xyz(0.0, 0.0, -10.0),
|
|
));
|
|
|
|
commands.spawn((
|
|
Mesh3d(meshes.add(Cuboid::default())),
|
|
MeshMaterial3d(materials.add(StandardMaterial {
|
|
base_color: GREEN.into(),
|
|
..Default::default()
|
|
})),
|
|
Transform::from_xyz(0.0, 0.0, -50.0),
|
|
));
|
|
|
|
commands.spawn((
|
|
Mesh3d(meshes.add(Cuboid::default())),
|
|
MeshMaterial3d(materials.add(StandardMaterial {
|
|
base_color: BLUE.into(),
|
|
..Default::default()
|
|
})),
|
|
Transform::from_xyz(0.0, 0.0, -100.0),
|
|
));
|
|
}
|
|
|
|
fn move_camera(keys: Res<ButtonInput<KeyCode>>, mut camera: Single<&mut Transform, With<Camera>>) {
|
|
const SPEED: f32 = 0.1;
|
|
if keys.pressed(KeyCode::ArrowLeft) {
|
|
camera.translation.x += SPEED;
|
|
} else if keys.pressed(KeyCode::ArrowRight) {
|
|
camera.translation.x -= SPEED;
|
|
}
|
|
|
|
if keys.pressed(KeyCode::ArrowUp) {
|
|
camera.translation.y -= SPEED;
|
|
} else if keys.pressed(KeyCode::ArrowDown) {
|
|
camera.translation.y += SPEED;
|
|
}
|
|
}
|