place buildings
This commit is contained in:
parent
b8c34a37b6
commit
2808f6dd2c
14 changed files with 338 additions and 36 deletions
15
Cargo.lock
generated
15
Cargo.lock
generated
|
|
@ -1621,8 +1621,10 @@ dependencies = [
|
||||||
name = "building"
|
name = "building"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"avian3d",
|
||||||
"bevy",
|
"bevy",
|
||||||
"combat",
|
"combat",
|
||||||
|
"state",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -1648,6 +1650,16 @@ dependencies = [
|
||||||
"state",
|
"state",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "building_placement"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"avian3d",
|
||||||
|
"bevy",
|
||||||
|
"building",
|
||||||
|
"physics",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bumpalo"
|
name = "bumpalo"
|
||||||
version = "3.19.0"
|
version = "3.19.0"
|
||||||
|
|
@ -1803,6 +1815,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"avian3d",
|
"avian3d",
|
||||||
"bevy",
|
"bevy",
|
||||||
|
"physics",
|
||||||
"state",
|
"state",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -1961,6 +1974,7 @@ dependencies = [
|
||||||
"building",
|
"building",
|
||||||
"building_core",
|
"building_core",
|
||||||
"building_impaler",
|
"building_impaler",
|
||||||
|
"building_placement",
|
||||||
"camera",
|
"camera",
|
||||||
"combat",
|
"combat",
|
||||||
"combat_damagers",
|
"combat_damagers",
|
||||||
|
|
@ -3025,6 +3039,7 @@ dependencies = [
|
||||||
"camera",
|
"camera",
|
||||||
"combat",
|
"combat",
|
||||||
"inhabitant_coranth",
|
"inhabitant_coranth",
|
||||||
|
"physics",
|
||||||
"state",
|
"state",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
1
Cargo.toml
Executable file → Normal file
1
Cargo.toml
Executable file → Normal file
|
|
@ -49,4 +49,5 @@ building_impaler = { path = "crates/building_impaler" }
|
||||||
combat_damagers = { path = "crates/combat_damagers" }
|
combat_damagers = { path = "crates/combat_damagers" }
|
||||||
inhabitant = { path = "crates/inhabitant" }
|
inhabitant = { path = "crates/inhabitant" }
|
||||||
inhabitant_coranth = { path = "crates/inhabitant_coranth" }
|
inhabitant_coranth = { path = "crates/inhabitant_coranth" }
|
||||||
|
building_placement = { path = "crates/building_placement" }
|
||||||
#new internal crates go here
|
#new internal crates go here
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,11 @@
|
||||||
KeyCode(Escape): [
|
KeyCode(Escape): [
|
||||||
TogglePause,
|
TogglePause,
|
||||||
],
|
],
|
||||||
MouseButton(Left): [
|
|
||||||
CameraPanEnable,
|
|
||||||
],
|
|
||||||
MouseButton(Middle): [
|
MouseButton(Middle): [
|
||||||
CameraOrbitEnable,
|
CameraOrbitEnable,
|
||||||
],
|
],
|
||||||
|
MouseButton(Left): [
|
||||||
|
CameraPanEnable,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
@ -5,7 +5,9 @@ edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = { workspace = true }
|
bevy = { workspace = true }
|
||||||
|
avian3d = { workspace = true }
|
||||||
combat = { path = "../combat" }
|
combat = { path = "../combat" }
|
||||||
|
state = { path = "../state" }
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,149 @@
|
||||||
#![allow(clippy::type_complexity)]
|
#![allow(clippy::type_complexity)]
|
||||||
#![allow(clippy::too_many_arguments)]
|
#![allow(clippy::too_many_arguments)]
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use avian3d::picking::PhysicsPickable;
|
||||||
|
use bevy::{
|
||||||
|
ecs::{component::HookContext, world::DeferredWorld},
|
||||||
|
platform::collections::HashMap,
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
use combat::{Health, Team};
|
use combat::{Health, Team};
|
||||||
|
use state::GameSystemSet;
|
||||||
|
|
||||||
pub struct BuildingPlugin;
|
pub struct BuildingPlugin;
|
||||||
|
|
||||||
impl Plugin for BuildingPlugin {
|
impl Plugin for BuildingPlugin {
|
||||||
fn build(&self, _app: &mut App) {}
|
fn build(&self, app: &mut App) {
|
||||||
|
app.init_resource::<BuildingTypes>()
|
||||||
|
.init_resource::<PlacedBuildings>()
|
||||||
|
.add_event::<PlaceBuilding>()
|
||||||
|
.add_systems(FixedUpdate, place_building.in_set(GameSystemSet::PostTick));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component, Default)]
|
#[derive(Component, Default)]
|
||||||
#[require(Health, Team::Core)]
|
#[require(Health, Team::Core, PhysicsPickable)]
|
||||||
pub struct Building {
|
pub struct Building {
|
||||||
pub level: u32,
|
pub level: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component, Clone)]
|
||||||
|
#[require(Name)]
|
||||||
|
#[component(on_add = register_building_info)]
|
||||||
|
#[component(on_remove = unregister_building_info)]
|
||||||
|
#[component(immutable)]
|
||||||
|
pub struct BuildingInfo {
|
||||||
|
pub preview: Entity,
|
||||||
|
pub size: UVec2,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct BuildingPreview {
|
||||||
|
pub info: Entity,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct ActiveBuildingPreview;
|
||||||
|
|
||||||
|
pub const PREVIEW_ALPHA: f32 = 0.5;
|
||||||
|
|
||||||
|
fn register_building_info(mut world: DeferredWorld, context: HookContext) {
|
||||||
|
let (info, name) = world
|
||||||
|
.get_entity(context.entity)
|
||||||
|
.unwrap()
|
||||||
|
.components::<(&BuildingInfo, &Name)>();
|
||||||
|
if name.is_empty() {
|
||||||
|
panic!("name cannot be empty when registering building");
|
||||||
|
}
|
||||||
|
let (info, name) = (info.clone(), name.to_string());
|
||||||
|
let mut types = world.get_resource_mut::<BuildingTypes>().unwrap();
|
||||||
|
info!("registering building {}", name);
|
||||||
|
types.info.insert(name, (context.entity, info));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unregister_building_info(mut world: DeferredWorld, context: HookContext) {
|
||||||
|
let name = world
|
||||||
|
.get_entity(context.entity)
|
||||||
|
.unwrap()
|
||||||
|
.components::<&Name>()
|
||||||
|
.to_string();
|
||||||
|
if name.is_empty() {
|
||||||
|
panic!("name cannot be empty when ungregistering building");
|
||||||
|
}
|
||||||
|
let mut types = world.get_resource_mut::<BuildingTypes>().unwrap();
|
||||||
|
info!("unregistering building {}", name);
|
||||||
|
types.info.remove(&name);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Resource, Default)]
|
||||||
|
pub struct BuildingTypes {
|
||||||
|
pub info: HashMap<String, (Entity, BuildingInfo)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct PlacedBuilding {
|
||||||
|
pub info: Entity,
|
||||||
|
pub instance: Entity,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Resource, Default)]
|
||||||
|
pub struct PlacedBuildings {
|
||||||
|
pub map: HashMap<IVec3, PlacedBuilding>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PlacedBuildings {
|
||||||
|
pub fn placement_valid(&self, location: IVec3, info: &BuildingInfo) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Event)]
|
||||||
|
pub struct PlaceBuilding {
|
||||||
|
pub info: Entity,
|
||||||
|
pub location: IVec3,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Event)]
|
||||||
|
pub struct PopulatePlacedBuilding {
|
||||||
|
pub info: Entity,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn place_building(
|
||||||
|
mut reader: EventReader<PlaceBuilding>,
|
||||||
|
mut building_map: ResMut<PlacedBuildings>,
|
||||||
|
mut commands: Commands,
|
||||||
|
info_query: Query<&BuildingInfo>,
|
||||||
|
) {
|
||||||
|
for PlaceBuilding {
|
||||||
|
info: info_entity,
|
||||||
|
location,
|
||||||
|
} in reader.read()
|
||||||
|
{
|
||||||
|
let Ok(info) = info_query.get(*info_entity) else {
|
||||||
|
error!("tried to place building without info!");
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
if !building_map.placement_valid(*location, info) {
|
||||||
|
error!("invalid building placement at {:?}, rejecting", location);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let instance = commands
|
||||||
|
.spawn((
|
||||||
|
Transform::from_translation(location.as_vec3()),
|
||||||
|
Building::default(),
|
||||||
|
))
|
||||||
|
.id();
|
||||||
|
if let Some(old_placement) = building_map.map.insert(
|
||||||
|
*location,
|
||||||
|
PlacedBuilding {
|
||||||
|
info: *info_entity,
|
||||||
|
instance,
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
//shouldn't happen
|
||||||
|
error!("placed building on old building, removing old building");
|
||||||
|
commands.entity(old_placement.instance).despawn();
|
||||||
|
}
|
||||||
|
commands.trigger_targets(PopulatePlacedBuilding { info: *info_entity }, instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,18 @@
|
||||||
|
|
||||||
use avian3d::prelude::*;
|
use avian3d::prelude::*;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use building::Building;
|
use building::{
|
||||||
|
ActiveBuildingPreview, Building, BuildingInfo, BuildingPreview, PREVIEW_ALPHA,
|
||||||
|
PopulatePlacedBuilding,
|
||||||
|
};
|
||||||
use combat::{Defense, Health};
|
use combat::{Defense, Health};
|
||||||
use combat_damagers::ContactDamage;
|
use combat_damagers::ContactDamage;
|
||||||
use state::GameSystemSet;
|
|
||||||
|
|
||||||
pub struct BuildingImpalerPlugin;
|
pub struct BuildingImpalerPlugin;
|
||||||
|
|
||||||
impl Plugin for BuildingImpalerPlugin {
|
impl Plugin for BuildingImpalerPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_event::<SpawnImpaler>()
|
app.add_systems(Startup, register).add_observer(populate);
|
||||||
.add_systems(FixedUpdate, spawn.in_set(GameSystemSet::PostTick));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,34 +23,87 @@ impl Plugin for BuildingImpalerPlugin {
|
||||||
#[require(Building)]
|
#[require(Building)]
|
||||||
pub struct Impaler;
|
pub struct Impaler;
|
||||||
|
|
||||||
#[derive(Event)]
|
#[derive(Resource)]
|
||||||
pub struct SpawnImpaler {
|
struct ImpalerResources {
|
||||||
pub transform: Transform,
|
mesh: Handle<Mesh>,
|
||||||
|
material: Handle<StandardMaterial>,
|
||||||
|
info_entity: Entity,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn(
|
fn register(
|
||||||
mut reader: EventReader<SpawnImpaler>,
|
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
) {
|
) {
|
||||||
for SpawnImpaler { transform } in reader.read() {
|
let mesh = meshes.add(Cuboid::from_length(1.0));
|
||||||
commands.spawn((
|
let base_material = StandardMaterial {
|
||||||
|
base_color: Color::srgb_u8(0xd6, 0x50, 0x61),
|
||||||
|
metallic: 0.2,
|
||||||
|
perceptual_roughness: 0.6,
|
||||||
|
..default()
|
||||||
|
};
|
||||||
|
let material = materials.add(base_material.clone());
|
||||||
|
let preview_material = materials.add(StandardMaterial {
|
||||||
|
alpha_mode: AlphaMode::Blend,
|
||||||
|
base_color: base_material.base_color.with_alpha(PREVIEW_ALPHA),
|
||||||
|
..base_material
|
||||||
|
});
|
||||||
|
|
||||||
|
let info = commands.spawn_empty().id();
|
||||||
|
let preview = commands
|
||||||
|
.spawn((
|
||||||
|
BuildingPreview { info },
|
||||||
|
ActiveBuildingPreview, // Visibility::Hidden,
|
||||||
|
Mesh3d::default(),
|
||||||
|
))
|
||||||
|
.with_child((
|
||||||
|
Transform::from_xyz(0., 0.5, 0.),
|
||||||
|
Mesh3d(mesh.clone()),
|
||||||
|
MeshMaterial3d(preview_material),
|
||||||
|
))
|
||||||
|
.id();
|
||||||
|
commands.entity(info).insert((
|
||||||
|
BuildingInfo {
|
||||||
|
preview,
|
||||||
|
size: UVec2::new(1, 1),
|
||||||
|
},
|
||||||
|
Name::new("Impaler"),
|
||||||
|
));
|
||||||
|
commands.insert_resource(ImpalerResources {
|
||||||
|
mesh: mesh,
|
||||||
|
material: material,
|
||||||
|
info_entity: info,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn populate(
|
||||||
|
trigger: Trigger<PopulatePlacedBuilding>,
|
||||||
|
mut commands: Commands,
|
||||||
|
res: Res<ImpalerResources>,
|
||||||
|
) {
|
||||||
|
if trigger.event().info != res.info_entity {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
commands
|
||||||
|
.entity(trigger.target())
|
||||||
|
.insert((
|
||||||
RigidBody::Static,
|
RigidBody::Static,
|
||||||
Collider::cuboid(1.0, 1.0, 1.0),
|
|
||||||
Mesh3d(meshes.add(Cuboid::from_length(1.0))),
|
|
||||||
MeshMaterial3d(materials.add(StandardMaterial {
|
|
||||||
base_color: Color::srgb_u8(0xd6, 0x50, 0x61),
|
|
||||||
metallic: 0.2,
|
|
||||||
perceptual_roughness: 0.6,
|
|
||||||
..default()
|
|
||||||
})),
|
|
||||||
Impaler,
|
Impaler,
|
||||||
transform.clone(),
|
|
||||||
Health::new(20.0),
|
Health::new(20.0),
|
||||||
Defense::new(5.0),
|
Defense::new(5.0),
|
||||||
ContactDamage { amount: 5.0 },
|
ContactDamage { amount: 5.0 },
|
||||||
Name::from("Impaler"),
|
Name::from("Impaler"),
|
||||||
|
Mesh3d::default(),
|
||||||
|
Collider::compound(vec![(
|
||||||
|
Vec3::Y * 0.5,
|
||||||
|
Quat::IDENTITY,
|
||||||
|
Collider::cuboid(1.0, 1.0, 1.0),
|
||||||
|
)]),
|
||||||
|
))
|
||||||
|
.with_child((
|
||||||
|
// don't think I'll need this with actual models
|
||||||
|
Transform::from_xyz(0., 0.5, 0.),
|
||||||
|
Mesh3d(res.mesh.clone()),
|
||||||
|
MeshMaterial3d(res.material.clone()),
|
||||||
));
|
));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
crates/building_placement/Cargo.toml
Normal file
14
crates/building_placement/Cargo.toml
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
[package]
|
||||||
|
name = "building_placement"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bevy = { workspace = true }
|
||||||
|
avian3d = { workspace = true }
|
||||||
|
|
||||||
|
building = { path = "../building" }
|
||||||
|
physics = { path = "../physics" }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
76
crates/building_placement/src/lib.rs
Normal file
76
crates/building_placement/src/lib.rs
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
//bevy system signatures often violate these rules
|
||||||
|
#![allow(clippy::type_complexity)]
|
||||||
|
#![allow(clippy::too_many_arguments)]
|
||||||
|
|
||||||
|
use bevy::prelude::*;
|
||||||
|
use building::{
|
||||||
|
ActiveBuildingPreview, BuildingInfo, BuildingPreview, PlaceBuilding, PlacedBuildings,
|
||||||
|
};
|
||||||
|
use physics::Ground;
|
||||||
|
|
||||||
|
pub struct BuildingPlacementPlugin;
|
||||||
|
|
||||||
|
impl Plugin for BuildingPlacementPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.add_systems(Update, init);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init(mut commands: Commands, query: Single<Entity, With<Ground>>, mut setup: Local<bool>) {
|
||||||
|
if *setup {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*setup = true;
|
||||||
|
commands
|
||||||
|
.entity(*query)
|
||||||
|
.observe(move_preview)
|
||||||
|
.observe(place_preview);
|
||||||
|
info!("added building placement observers!");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_preview(
|
||||||
|
trigger: Trigger<Pointer<Move>>,
|
||||||
|
preview: Single<(&mut Transform, &BuildingPreview), With<ActiveBuildingPreview>>,
|
||||||
|
info_query: Query<&BuildingInfo>,
|
||||||
|
placed_buildings: Res<PlacedBuildings>,
|
||||||
|
) {
|
||||||
|
let Some(dest) = trigger.event().hit.position else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let (mut tf, preview) = preview.into_inner();
|
||||||
|
let Ok(info) = info_query.get(preview.info) else {
|
||||||
|
error!("building preview has no associated info!");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let loc = dest.round();
|
||||||
|
if !placed_buildings.placement_valid(loc.as_ivec3(), info) {
|
||||||
|
info!("invalid placement!!!!!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tf.translation = dest.round();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn place_preview(
|
||||||
|
trigger: Trigger<Pointer<Click>>,
|
||||||
|
preview: Single<&BuildingPreview, With<ActiveBuildingPreview>>,
|
||||||
|
info_query: Query<&BuildingInfo>,
|
||||||
|
placed_buildings: Res<PlacedBuildings>,
|
||||||
|
mut place_writer: EventWriter<PlaceBuilding>,
|
||||||
|
) {
|
||||||
|
let Some(dest) = trigger.event().hit.position else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let Ok(info) = info_query.get(preview.info) else {
|
||||||
|
error!("building preview has no associated info!");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let loc = dest.round();
|
||||||
|
if !placed_buildings.placement_valid(loc.as_ivec3(), info) {
|
||||||
|
info!("invalid placement!!!!!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
place_writer.write(PlaceBuilding {
|
||||||
|
info: preview.info,
|
||||||
|
location: loc.as_ivec3(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ bevy = { workspace = true }
|
||||||
avian3d = { workspace = true }
|
avian3d = { workspace = true }
|
||||||
|
|
||||||
state = { path = "../state" }
|
state = { path = "../state" }
|
||||||
|
physics = { path = "../physics"}
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
use avian3d::prelude::*;
|
use avian3d::prelude::*;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use building::Building;
|
use building::Building;
|
||||||
use combat::{GaveDamage, Health, Team};
|
use combat::{GaveDamage, Health};
|
||||||
use combat_damagers::ContactDamage;
|
use combat_damagers::ContactDamage;
|
||||||
use inhabitant::Inhabitant;
|
use inhabitant::Inhabitant;
|
||||||
use state::GameSystemSet;
|
use state::GameSystemSet;
|
||||||
|
|
@ -76,7 +76,6 @@ fn explode(
|
||||||
// &SpatialQueryFilter::from_mask(Team::Inhabitant),
|
// &SpatialQueryFilter::from_mask(Team::Inhabitant),
|
||||||
&SpatialQueryFilter::default(),
|
&SpatialQueryFilter::default(),
|
||||||
) {
|
) {
|
||||||
info!("found hit");
|
|
||||||
if let Ok((gtf, mut v)) = other_query.get_mut(e) {
|
if let Ok((gtf, mut v)) = other_query.get_mut(e) {
|
||||||
let delta = gtf.translation() - origin;
|
let delta = gtf.translation() - origin;
|
||||||
v.0 += delta.normalize_or_zero() * 10.0;
|
v.0 += delta.normalize_or_zero() * 10.0;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ avian3d = { workspace = true }
|
||||||
state = { path = "../state" }
|
state = { path = "../state" }
|
||||||
camera = { path = "../camera" }
|
camera = { path = "../camera" }
|
||||||
combat = { path = "../combat" }
|
combat = { path = "../combat" }
|
||||||
|
physics = { path = "../physics" }
|
||||||
building_core = { path = "../building_core" }
|
building_core = { path = "../building_core" }
|
||||||
building_impaler = { path = "../building_impaler" }
|
building_impaler = { path = "../building_impaler" }
|
||||||
inhabitant_coranth = { path = "../inhabitant_coranth" }
|
inhabitant_coranth = { path = "../inhabitant_coranth" }
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,9 @@ use bevy::{
|
||||||
render::camera::Exposure,
|
render::camera::Exposure,
|
||||||
};
|
};
|
||||||
use building_core::SpawnCore;
|
use building_core::SpawnCore;
|
||||||
use building_impaler::SpawnImpaler;
|
|
||||||
use camera::ControlledCamera;
|
use camera::ControlledCamera;
|
||||||
use inhabitant_coranth::SpawnCoranth;
|
use inhabitant_coranth::SpawnCoranth;
|
||||||
|
use physics::Ground;
|
||||||
use state::AppState;
|
use state::AppState;
|
||||||
|
|
||||||
pub struct LevelPlugin;
|
pub struct LevelPlugin;
|
||||||
|
|
@ -28,7 +28,6 @@ fn setup(
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
mut core_writer: EventWriter<SpawnCore>,
|
mut core_writer: EventWriter<SpawnCore>,
|
||||||
mut impaler_writer: EventWriter<SpawnImpaler>,
|
|
||||||
mut coranth_writer: EventWriter<SpawnCoranth>,
|
mut coranth_writer: EventWriter<SpawnCoranth>,
|
||||||
) {
|
) {
|
||||||
let level_size = 50.0;
|
let level_size = 50.0;
|
||||||
|
|
@ -43,6 +42,8 @@ fn setup(
|
||||||
perceptual_roughness: 0.8,
|
perceptual_roughness: 0.8,
|
||||||
..default()
|
..default()
|
||||||
})),
|
})),
|
||||||
|
PhysicsPickable,
|
||||||
|
Ground,
|
||||||
));
|
));
|
||||||
|
|
||||||
for y in 5..15 {
|
for y in 5..15 {
|
||||||
|
|
@ -54,9 +55,6 @@ fn setup(
|
||||||
core_writer.write(SpawnCore {
|
core_writer.write(SpawnCore {
|
||||||
transform: Transform::from_xyz(5.0, 1.0, 5.0),
|
transform: Transform::from_xyz(5.0, 1.0, 5.0),
|
||||||
});
|
});
|
||||||
impaler_writer.write(SpawnImpaler {
|
|
||||||
transform: Transform::from_xyz(-5.0, 0.5, 5.0),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Light
|
// Light
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
|
@ -83,6 +81,7 @@ fn setup(
|
||||||
Atmosphere::EARTH,
|
Atmosphere::EARTH,
|
||||||
Exposure::SUNLIGHT,
|
Exposure::SUNLIGHT,
|
||||||
Bloom::NATURAL,
|
Bloom::NATURAL,
|
||||||
|
PhysicsPickable,
|
||||||
Transform::from_xyz(-2.5, 9.5, 9.0).looking_at(Vec3::ZERO, Dir3::Y),
|
Transform::from_xyz(-2.5, 9.5, 9.0).looking_at(Vec3::ZERO, Dir3::Y),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,12 @@ impl Plugin for PhysicsPlugin {
|
||||||
app.add_plugins((
|
app.add_plugins((
|
||||||
PhysicsPlugins::default().set(PhysicsInterpolationPlugin::interpolate_all()),
|
PhysicsPlugins::default().set(PhysicsInterpolationPlugin::interpolate_all()),
|
||||||
PhysicsPickingPlugin,
|
PhysicsPickingPlugin,
|
||||||
));
|
))
|
||||||
|
.insert_resource(PhysicsPickingSettings {
|
||||||
|
require_markers: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct Ground;
|
||||||
|
|
|
||||||
4
src/main.rs
Executable file → Normal file
4
src/main.rs
Executable file → Normal file
|
|
@ -1,10 +1,11 @@
|
||||||
use bevy::prelude::*;
|
use bevy::{prelude::*, window::WindowResolution};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut app = App::new();
|
let mut app = App::new();
|
||||||
app.add_plugins(DefaultPlugins.set(WindowPlugin {
|
app.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||||
primary_window: Some(Window {
|
primary_window: Some(Window {
|
||||||
title: "Coreheart".to_string(),
|
title: "Coreheart".to_string(),
|
||||||
|
resolution: WindowResolution::new(1600., 900.),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
|
|
@ -30,6 +31,7 @@ fn main() {
|
||||||
),
|
),
|
||||||
inhabitant::InhabitantPlugin,
|
inhabitant::InhabitantPlugin,
|
||||||
inhabitant_coranth::InhabitantCoranthPlugin,
|
inhabitant_coranth::InhabitantCoranthPlugin,
|
||||||
|
building_placement::BuildingPlacementPlugin,
|
||||||
// new internal crates go here
|
// new internal crates go here
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue