187 lines
6.0 KiB
Rust
187 lines
6.0 KiB
Rust
#![allow(clippy::type_complexity)]
|
|
|
|
use bevy::{
|
|
math::vec3, pbr::AmbientLight, prelude::*, sprite::Material2dPlugin, window::close_on_esc,
|
|
};
|
|
use bevy_mod_raycast::{DefaultRaycastingPlugin, RayCastMesh, RaycastSystem};
|
|
|
|
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,
|
|
}
|
|
|
|
/// color palette in hsl
|
|
/// from https://lospec.com/palette-list/urbex-16
|
|
pub const PALETTE: [Vec3; 16] = [
|
|
vec3(0.2193, 0.1712, 0.7824),
|
|
vec3(0.2333, 0.0442, 0.5569),
|
|
vec3(0.1905, 0.0440, 0.3118),
|
|
vec3(0.0556, 0.1343, 0.1314),
|
|
vec3(0.0789, 0.6477, 0.6549),
|
|
vec3(0.2421, 0.1875, 0.5608),
|
|
vec3(0.2484, 0.2757, 0.3627),
|
|
vec3(0.2067, 0.1773, 0.2765),
|
|
vec3(0.0014, 0.5576, 0.4255),
|
|
vec3(0.9401, 0.7305, 0.2765),
|
|
vec3(0.9180, 0.3035, 0.3941),
|
|
vec3(0.8274, 0.1138, 0.5176),
|
|
vec3(0.8778, 0.5172, 0.0569),
|
|
vec3(0.7480, 0.4667, 0.3529),
|
|
vec3(0.5970, 0.5447, 0.4824),
|
|
vec3(0.5376, 0.3827, 0.523),
|
|
];
|
|
pub const PALETTE_HEX: [&str; 16] = [
|
|
"cbd1be", "8f9389", "52534c", "26201d", "e0a46e", "91a47a", "5d7643", "4d533a", "a93130",
|
|
"7a1338", "834664", "917692", "160712", "593084", "3870be", "579fb4",
|
|
];
|
|
|
|
pub const LIGHT_FRIEND_COLOR_INDICES: [usize; 6] = [0, 4, 7, 8, 11, 14];
|
|
|
|
fn main() {
|
|
App::new()
|
|
.insert_resource(Msaa { samples: 1 })
|
|
.insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0)))
|
|
.add_plugins(DefaultPlugins)
|
|
.add_plugin(Material2dPlugin::<PostProcessingMaterial>::default())
|
|
.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)
|
|
.with_system(spawn_player)
|
|
.with_system(spawn_camera),
|
|
)
|
|
.add_system_set(
|
|
SystemSet::on_update(AppState::Game)
|
|
.with_system(setup_scene_once_loaded)
|
|
.with_system(update_raw_mouse_coords)
|
|
.with_system(update_processed_mouse_coords)
|
|
.with_system(update_distance_to_player)
|
|
.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(increase_range_up_to_max)
|
|
.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();
|
|
}
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
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>,
|
|
asset_server: Res<AssetServer>,
|
|
) {
|
|
asset_server.watch_for_changes().unwrap();
|
|
|
|
// 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),
|
|
);
|
|
|
|
// 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),
|
|
);
|
|
}
|
|
}
|