use bevy::{input::system::exit_on_esc_system, pbr::AmbientLight, prelude::*}; use bevy_mod_raycast::{build_rays, update_raycast, PluginState, RayCastMesh, RaycastSystem}; mod camera; mod columns; mod light_balls; mod loading; mod player; mod rendering; use camera::*; use light_balls::*; use player::*; #[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::() .init_resource::() .init_resource::() .add_state(AppState::Loading) // raycasting .init_resource::>() .add_system_to_stage( CoreStage::PostUpdate, build_rays:: .system() .label(RaycastSystem::BuildRays), ) .add_system_to_stage( CoreStage::PostUpdate, update_raycast:: .system() .label(RaycastSystem::UpdateRaycast) .after(RaycastSystem::BuildRays), ) .add_system_to_stage( CoreStage::PreUpdate, update_raycast_with_cursor .system() .before(RaycastSystem::BuildRays), ) // 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(update_mouse_coords.system()) .with_system(exit_on_esc_system.system()) .with_system(light_movement.system()) .with_system(move_light_friends.system()) .with_system(update_floating_orbs_interpolation.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() }) .insert(RayCastMesh::::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 spawn_camera(&mut commands); }