use bevy::{input::system::exit_on_esc_system, pbr::AmbientLight, prelude::*}; mod rendering; mod light_balls; use light_balls::*; mod player; use player::*; mod camera; use camera::*; mod columns; mod loading; #[derive(Clone, PartialEq, Eq, Hash, Debug)] pub enum AppState { Loading, Game, } fn main() { App::build() .insert_resource(Msaa { samples: 4 }) .insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0))) .add_plugins(rendering::CustomPlugins) .init_resource::() .init_resource::() .add_state(AppState::Loading) // loading .add_system_set( SystemSet::on_update(AppState::Loading).with_system(loading::loading.system()), ) // game .add_system_set(SystemSet::on_enter(AppState::Game).with_system(setup.system())) .add_system_set( SystemSet::on_update(AppState::Game) .with_system(exit_on_esc_system.system()) .with_system(light_movement.system()) .with_system(move_player.system()) .with_system(camera_follow_player.system()) .with_system(light_up_ball_when_close_to_player.system()), ) .run(); } fn setup( mut commands: Commands, assets: Res, mut meshes: ResMut>, mut materials: ResMut>, mut ambient: ResMut, light_ball_materials: Res, ) { // set ambient light to very low ambient.color = Color::rgb(0.3, 0.3, 0.3); ambient.brightness = 0.01; // floor let mut floor_material = StandardMaterial { base_color_texture: Some(assets.floor.clone()), base_color: Color::rgb(0.3, 0.3, 0.3), ..Default::default() }; floor_material.metallic = 0.0; floor_material.reflectance = 0.0; let floor_material = materials.add(floor_material); for i in -10..10 { for j in -10..10 { commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane { size: 100.0 })), material: floor_material.clone(), transform: Transform::from_xyz(100.0 * i as f32, 0.0, 100.0 * j as f32), ..Default::default() }); } } // columns // 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, 10.0), ); spawn_light_ball( &mut commands, &light_ball_materials, Vec3::new(i as f32 * 30.0, 2.0, -10.0), ); } // camera commands .spawn_bundle(PerspectiveCameraBundle { transform: Transform::from_xyz(-40.0, 110.0, 40.0).looking_at(Vec3::ZERO, Vec3::Y), ..Default::default() }) .insert(Camera); }