77 lines
2.1 KiB
Rust
77 lines
2.1 KiB
Rust
use bevy::{input::system::exit_on_esc_system, pbr::AmbientLight, prelude::*};
|
|
|
|
mod light_balls;
|
|
use light_balls::*;
|
|
mod player;
|
|
use player::*;
|
|
mod columns;
|
|
use columns::*;
|
|
|
|
fn main() {
|
|
App::build()
|
|
.insert_resource(Msaa { samples: 4 })
|
|
.add_plugins(DefaultPlugins)
|
|
.init_resource::<LightBallMaterials>()
|
|
.add_startup_system(setup.system())
|
|
.add_system(exit_on_esc_system.system())
|
|
.add_system(light_movement.system())
|
|
.add_system(move_player.system())
|
|
.add_system(camera_follow_player.system())
|
|
.add_system(light_up_ball_when_close_to_player.system())
|
|
.run();
|
|
}
|
|
|
|
pub struct Camera;
|
|
|
|
/// set up a simple 3D scene
|
|
fn setup(
|
|
mut commands: Commands,
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
mut ambient: ResMut<AmbientLight>,
|
|
light_ball_materials: Res<LightBallMaterials>,
|
|
) {
|
|
// set ambient light to 0
|
|
ambient.color = Color::rgb(0.3, 0.3, 0.3);
|
|
ambient.brightness = 0.02;
|
|
|
|
// floor
|
|
let mut floor_material: StandardMaterial = Color::rgb(0.1, 0.1, 0.1).into();
|
|
floor_material.metallic = 0.0;
|
|
floor_material.reflectance = 0.0;
|
|
let floor_material = materials.add(floor_material);
|
|
commands.spawn_bundle(PbrBundle {
|
|
mesh: meshes.add(Mesh::from(shape::Plane { size: 10000.0 })),
|
|
material: floor_material,
|
|
..Default::default()
|
|
});
|
|
|
|
// columns
|
|
spawn_columns(&mut commands, &mut meshes, &mut materials);
|
|
|
|
// player
|
|
spawn_player(&mut commands, &mut meshes, &mut materials);
|
|
|
|
// light balls
|
|
for i in 1..10 {
|
|
spawn_light_ball(
|
|
&mut commands,
|
|
&light_ball_materials,
|
|
Vec3::new(i as f32 * 30.0, 2.0, 6.0),
|
|
);
|
|
spawn_light_ball(
|
|
&mut commands,
|
|
&light_ball_materials,
|
|
Vec3::new(i as f32 * 30.0, 2.0, -6.0),
|
|
);
|
|
}
|
|
|
|
// camera
|
|
commands
|
|
.spawn_bundle(PerspectiveCameraBundle {
|
|
transform: Transform::from_xyz(-20.0, 100.0, 50.0).looking_at(Vec3::ZERO, Vec3::Y),
|
|
..Default::default()
|
|
})
|
|
.insert(Camera);
|
|
}
|