basic core building
This commit is contained in:
parent
f5d022d1d0
commit
af45237701
11 changed files with 146 additions and 11 deletions
22
Cargo.lock
generated
22
Cargo.lock
generated
|
|
@ -1617,6 +1617,25 @@ dependencies = [
|
||||||
"piper",
|
"piper",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "building"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"bevy",
|
||||||
|
"combat",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "building_core"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"avian3d",
|
||||||
|
"bevy",
|
||||||
|
"building",
|
||||||
|
"combat",
|
||||||
|
"state",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bumpalo"
|
name = "bumpalo"
|
||||||
version = "3.19.0"
|
version = "3.19.0"
|
||||||
|
|
@ -1915,6 +1934,8 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bevy",
|
"bevy",
|
||||||
"bevy-inspector-egui",
|
"bevy-inspector-egui",
|
||||||
|
"building",
|
||||||
|
"building_core",
|
||||||
"camera",
|
"camera",
|
||||||
"combat",
|
"combat",
|
||||||
"input",
|
"input",
|
||||||
|
|
@ -2950,6 +2971,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"avian3d",
|
"avian3d",
|
||||||
"bevy",
|
"bevy",
|
||||||
|
"building_core",
|
||||||
"camera",
|
"camera",
|
||||||
"combat",
|
"combat",
|
||||||
"state",
|
"state",
|
||||||
|
|
|
||||||
|
|
@ -43,4 +43,6 @@ ui_pause = { path = "crates/ui_pause" }
|
||||||
level = { path = "crates/level" }
|
level = { path = "crates/level" }
|
||||||
camera = { path = "crates/camera" }
|
camera = { path = "crates/camera" }
|
||||||
combat = { path = "crates/combat" }
|
combat = { path = "crates/combat" }
|
||||||
|
building_core = { path = "crates/building_core" }
|
||||||
|
building = { path = "crates/building" }
|
||||||
#new internal crates go here
|
#new internal crates go here
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
(
|
(
|
||||||
map: {
|
map: {
|
||||||
MouseButton(Left): [
|
KeyCode(F1): [
|
||||||
CameraPanEnable,
|
ToggleDebugUI,
|
||||||
],
|
],
|
||||||
MouseScroll: [
|
MouseScroll: [
|
||||||
CameraZoom,
|
CameraZoom,
|
||||||
|
|
@ -13,14 +13,14 @@
|
||||||
KeyCode(Escape): [
|
KeyCode(Escape): [
|
||||||
TogglePause,
|
TogglePause,
|
||||||
],
|
],
|
||||||
MouseMovementY: [
|
|
||||||
CameraPanY,
|
|
||||||
],
|
|
||||||
MouseButton(Middle): [
|
MouseButton(Middle): [
|
||||||
CameraOrbitEnable,
|
CameraOrbitEnable,
|
||||||
],
|
],
|
||||||
KeyCode(F1): [
|
MouseButton(Left): [
|
||||||
ToggleDebugUI,
|
CameraPanEnable,
|
||||||
|
],
|
||||||
|
MouseMovementY: [
|
||||||
|
CameraPanY,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
11
crates/building/Cargo.toml
Normal file
11
crates/building/Cargo.toml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
[package]
|
||||||
|
name = "building"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bevy = { workspace = true }
|
||||||
|
combat = { path = "../combat" }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
16
crates/building/src/lib.rs
Normal file
16
crates/building/src/lib.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
//bevy system signatures often violate these rules
|
||||||
|
#![allow(clippy::type_complexity)]
|
||||||
|
#![allow(clippy::too_many_arguments)]
|
||||||
|
|
||||||
|
use bevy::prelude::*;
|
||||||
|
use combat::Health;
|
||||||
|
|
||||||
|
pub struct BuildingPlugin;
|
||||||
|
|
||||||
|
impl Plugin for BuildingPlugin {
|
||||||
|
fn build(&self, _app: &mut App) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component, Default)]
|
||||||
|
#[require(Health)]
|
||||||
|
pub struct Building;
|
||||||
15
crates/building_core/Cargo.toml
Normal file
15
crates/building_core/Cargo.toml
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
[package]
|
||||||
|
name = "building_core"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bevy = { workspace = true }
|
||||||
|
avian3d = { workspace = true }
|
||||||
|
|
||||||
|
combat = { path = "../combat" }
|
||||||
|
building = { path = "../building" }
|
||||||
|
state = { path = "../state" }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
55
crates/building_core/src/lib.rs
Normal file
55
crates/building_core/src/lib.rs
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
//bevy system signatures often violate these rules
|
||||||
|
#![allow(clippy::type_complexity)]
|
||||||
|
#![allow(clippy::too_many_arguments)]
|
||||||
|
|
||||||
|
use avian3d::prelude::*;
|
||||||
|
use bevy::prelude::*;
|
||||||
|
use building::Building;
|
||||||
|
use combat::{Defense, Health};
|
||||||
|
use state::GameSystemSet;
|
||||||
|
|
||||||
|
pub struct BuildingCorePlugin;
|
||||||
|
|
||||||
|
impl Plugin for BuildingCorePlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.add_event::<SpawnCore>()
|
||||||
|
.add_systems(FixedUpdate, spawn_core.in_set(GameSystemSet::PostTick));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
#[require(Building)]
|
||||||
|
pub struct Core {
|
||||||
|
pub level: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Event)]
|
||||||
|
pub struct SpawnCore {
|
||||||
|
pub transform: Transform,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spawn_core(
|
||||||
|
mut reader: EventReader<SpawnCore>,
|
||||||
|
mut commands: Commands,
|
||||||
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
|
) {
|
||||||
|
for SpawnCore { transform } in reader.read() {
|
||||||
|
commands.spawn((
|
||||||
|
RigidBody::Static,
|
||||||
|
Collider::cuboid(2.0, 2.0, 2.0),
|
||||||
|
Mesh3d(meshes.add(Cuboid::from_length(2.0))),
|
||||||
|
MeshMaterial3d(materials.add(StandardMaterial {
|
||||||
|
base_color: Color::srgb_u8(166, 69, 16),
|
||||||
|
metallic: 0.0,
|
||||||
|
perceptual_roughness: 0.8,
|
||||||
|
..default()
|
||||||
|
})),
|
||||||
|
Core { level: 0 },
|
||||||
|
transform.clone(),
|
||||||
|
Health::new(100.0),
|
||||||
|
Defense::new(10.0),
|
||||||
|
Name::from("Core"),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#![allow(clippy::type_complexity)]
|
#![allow(clippy::type_complexity)]
|
||||||
#![allow(clippy::too_many_arguments)]
|
#![allow(clippy::too_many_arguments)]
|
||||||
|
|
||||||
use bevy::{audio::Sample, prelude::*};
|
use bevy::prelude::*;
|
||||||
|
|
||||||
pub struct CombatPlugin;
|
pub struct CombatPlugin;
|
||||||
|
|
||||||
|
|
@ -55,7 +55,11 @@ pub struct Defense {
|
||||||
|
|
||||||
impl Defense {
|
impl Defense {
|
||||||
pub fn calc_damage(&self, incoming_damage: f32) -> f32 {
|
pub fn calc_damage(&self, incoming_damage: f32) -> f32 {
|
||||||
(incoming_damage - self.amount * 0.5).max(0.0)
|
let min_damage = 0.1;
|
||||||
|
if incoming_damage < min_damage {
|
||||||
|
return 0.;
|
||||||
|
}
|
||||||
|
(incoming_damage - self.amount * 0.5).max(min_damage)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(amount: f32) -> Self {
|
pub fn new(amount: f32) -> Self {
|
||||||
|
|
|
||||||
|
|
@ -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" }
|
||||||
|
building_core = { path = "../building_core" }
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ use bevy::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
render::camera::Exposure,
|
render::camera::Exposure,
|
||||||
};
|
};
|
||||||
|
use building_core::SpawnCore;
|
||||||
use camera::ControlledCamera;
|
use camera::ControlledCamera;
|
||||||
use combat::{Attacked, Defense, Health};
|
use combat::{Attacked, Defense, Health};
|
||||||
use state::AppState;
|
use state::AppState;
|
||||||
|
|
@ -25,13 +26,15 @@ fn setup(
|
||||||
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>>,
|
||||||
|
mut core_writer: EventWriter<SpawnCore>,
|
||||||
) {
|
) {
|
||||||
let level_size = 50.0;
|
let level_size = 50.0;
|
||||||
// Static physics object with a collision shape
|
// Static physics object with a collision shape
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
RigidBody::Static,
|
RigidBody::Static,
|
||||||
Collider::cuboid(level_size, 0.5, level_size),
|
Collider::cuboid(level_size, 1.0, level_size),
|
||||||
Mesh3d(meshes.add(Cuboid::new(level_size, 0.5, level_size))),
|
Mesh3d(meshes.add(Cuboid::new(level_size, 1.0, level_size))),
|
||||||
|
Transform::from_xyz(0.0, -0.5, 0.0),
|
||||||
MeshMaterial3d(materials.add(StandardMaterial {
|
MeshMaterial3d(materials.add(StandardMaterial {
|
||||||
base_color: Color::srgb_u8(52, 125, 117),
|
base_color: Color::srgb_u8(52, 125, 117),
|
||||||
perceptual_roughness: 0.8,
|
perceptual_roughness: 0.8,
|
||||||
|
|
@ -72,6 +75,10 @@ fn setup(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_writer.write(SpawnCore {
|
||||||
|
transform: Transform::from_xyz(5.0, 1.0, 5.0),
|
||||||
|
});
|
||||||
|
|
||||||
// Light
|
// Light
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
DirectionalLight {
|
DirectionalLight {
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ fn main() {
|
||||||
level::LevelPlugin,
|
level::LevelPlugin,
|
||||||
camera::CameraPlugin,
|
camera::CameraPlugin,
|
||||||
combat::CombatPlugin,
|
combat::CombatPlugin,
|
||||||
|
building_core::BuildingCorePlugin,
|
||||||
|
building::BuildingPlugin,
|
||||||
// new internal crates go here
|
// new internal crates go here
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue