moria/src/main.rs

151 lines
4.7 KiB
Rust

use bevy::{pbr::AmbientLight, prelude::*, window::close_on_esc};
use bevy_mod_raycast::{DefaultRaycastingPlugin, RayCastMesh, RaycastSystem};
// use bevy_prototype_debug_lines::*;
mod camera;
mod columns;
mod debug;
mod illumination;
mod light_balls;
mod loading;
mod pillar;
mod player;
use camera::*;
use debug::*;
use light_balls::*;
use pillar::*;
use player::*;
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub enum AppState {
Loading,
Game,
}
fn main() {
App::new()
.insert_resource(Msaa { samples: 4 })
.insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0)))
.add_plugins(DefaultPlugins)
// .add_plugin(DebugLinesPlugin::with_depth_test(true))
.init_resource::<Debug>()
.init_resource::<LightBallMaterials>()
.init_resource::<PillarMaterials>()
.init_resource::<MouseCoords>()
.init_resource::<FloatingOrbsInterpolationState>()
.init_resource::<PillarActivationProgress>()
.init_resource::<LightExcitationState>()
.init_resource::<loading::LoadedAssets>()
.add_state(AppState::Loading)
// raycasting
.add_plugin(DefaultRaycastingPlugin::<MyRaycastSet>::default())
.add_system_to_stage(
CoreStage::PreUpdate,
update_raycast_with_cursor.before(RaycastSystem::<MyRaycastSet>::BuildRays),
)
// loading
.add_system_set(SystemSet::on_update(AppState::Loading).with_system(loading::loading))
// game
.add_system_set(SystemSet::on_enter(AppState::Game).with_system(setup))
.add_system_set(
SystemSet::on_update(AppState::Game)
.with_system(update_raw_mouse_coords)
.with_system(update_processed_mouse_coords)
.with_system(close_on_esc)
.with_system(light_movement)
.with_system(move_light_friends)
.with_system(update_floating_orbs_interpolation)
.with_system(move_player)
.with_system(camera_follow_player)
.with_system(light_up_ball_when_close_to_player)
.with_system(increase_progress_when_activating_pillar)
.with_system(activate_pillar_when_progress_is_1)
.with_system(decrease_pillar_strength)
.with_system(update_light_excitation_state)
.with_system(toggle_debug),
)
.add_system_set(
SystemSet::on_update(AppState::Game).with_run_criteria(debug_run_criteria), // .with_system(debug_draw_illumination),
)
.run();
}
fn setup(
mut commands: Commands,
assets: Res<loading::LoadedAssets>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
mut ambient: ResMut<AmbientLight>,
light_ball_materials: Res<LightBallMaterials>,
pillar_materials: Res<PillarMaterials>,
) {
// 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::<camera::MyRaycastSet>::default());
}
}
// columns
// columns::spawn_columns(&mut commands, &mut meshes, &mut materials);
spawn_pillar(
&mut commands,
&pillar_materials,
&mut materials,
Vec3::new(0.0, 1.0, 50.0),
);
spawn_pillar(
&mut commands,
&pillar_materials,
&mut materials,
Vec3::new(-30.0, 1.0, 50.0),
);
spawn_pillar(
&mut commands,
&pillar_materials,
&mut materials,
Vec3::new(30.0, 1.0, 50.0),
);
// player
spawn_player(&mut commands, &mut meshes, &mut materials);
// light balls
for i in 2..12 {
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);
}