add impaler scaffolding and teams
This commit is contained in:
parent
af45237701
commit
6659fe8e5a
12 changed files with 151 additions and 21 deletions
13
Cargo.lock
generated
13
Cargo.lock
generated
|
|
@ -1636,6 +1636,17 @@ dependencies = [
|
||||||
"state",
|
"state",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "building_impaler"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"avian3d",
|
||||||
|
"bevy",
|
||||||
|
"building",
|
||||||
|
"combat",
|
||||||
|
"state",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bumpalo"
|
name = "bumpalo"
|
||||||
version = "3.19.0"
|
version = "3.19.0"
|
||||||
|
|
@ -1936,6 +1947,7 @@ dependencies = [
|
||||||
"bevy-inspector-egui",
|
"bevy-inspector-egui",
|
||||||
"building",
|
"building",
|
||||||
"building_core",
|
"building_core",
|
||||||
|
"building_impaler",
|
||||||
"camera",
|
"camera",
|
||||||
"combat",
|
"combat",
|
||||||
"input",
|
"input",
|
||||||
|
|
@ -2972,6 +2984,7 @@ dependencies = [
|
||||||
"avian3d",
|
"avian3d",
|
||||||
"bevy",
|
"bevy",
|
||||||
"building_core",
|
"building_core",
|
||||||
|
"building_impaler",
|
||||||
"camera",
|
"camera",
|
||||||
"combat",
|
"combat",
|
||||||
"state",
|
"state",
|
||||||
|
|
|
||||||
|
|
@ -45,4 +45,5 @@ camera = { path = "crates/camera" }
|
||||||
combat = { path = "crates/combat" }
|
combat = { path = "crates/combat" }
|
||||||
building_core = { path = "crates/building_core" }
|
building_core = { path = "crates/building_core" }
|
||||||
building = { path = "crates/building" }
|
building = { path = "crates/building" }
|
||||||
|
building_impaler = { path = "crates/building_impaler" }
|
||||||
#new internal crates go here
|
#new internal crates go here
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
(
|
(
|
||||||
map: {
|
map: {
|
||||||
KeyCode(F1): [
|
MouseButton(Left): [
|
||||||
ToggleDebugUI,
|
CameraPanEnable,
|
||||||
],
|
],
|
||||||
MouseScroll: [
|
MouseScroll: [
|
||||||
CameraZoom,
|
CameraZoom,
|
||||||
|
|
@ -10,17 +10,17 @@
|
||||||
CameraYaw,
|
CameraYaw,
|
||||||
CameraPanX,
|
CameraPanX,
|
||||||
],
|
],
|
||||||
|
MouseMovementY: [
|
||||||
|
CameraPanY,
|
||||||
|
],
|
||||||
KeyCode(Escape): [
|
KeyCode(Escape): [
|
||||||
TogglePause,
|
TogglePause,
|
||||||
],
|
],
|
||||||
MouseButton(Middle): [
|
MouseButton(Middle): [
|
||||||
CameraOrbitEnable,
|
CameraOrbitEnable,
|
||||||
],
|
],
|
||||||
MouseButton(Left): [
|
KeyCode(F1): [
|
||||||
CameraPanEnable,
|
ToggleDebugUI,
|
||||||
],
|
|
||||||
MouseMovementY: [
|
|
||||||
CameraPanY,
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
@ -13,4 +13,6 @@ impl Plugin for BuildingPlugin {
|
||||||
|
|
||||||
#[derive(Component, Default)]
|
#[derive(Component, Default)]
|
||||||
#[require(Health)]
|
#[require(Health)]
|
||||||
pub struct Building;
|
pub struct Building {
|
||||||
|
pub level: u32,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,7 @@ impl Plugin for BuildingCorePlugin {
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
#[require(Building)]
|
#[require(Building)]
|
||||||
pub struct Core {
|
pub struct Core;
|
||||||
pub level: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Event)]
|
#[derive(Event)]
|
||||||
pub struct SpawnCore {
|
pub struct SpawnCore {
|
||||||
|
|
@ -45,7 +43,7 @@ fn spawn_core(
|
||||||
perceptual_roughness: 0.8,
|
perceptual_roughness: 0.8,
|
||||||
..default()
|
..default()
|
||||||
})),
|
})),
|
||||||
Core { level: 0 },
|
Core,
|
||||||
transform.clone(),
|
transform.clone(),
|
||||||
Health::new(100.0),
|
Health::new(100.0),
|
||||||
Defense::new(10.0),
|
Defense::new(10.0),
|
||||||
|
|
|
||||||
15
crates/building_impaler/Cargo.toml
Normal file
15
crates/building_impaler/Cargo.toml
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
[package]
|
||||||
|
name = "building_impaler"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bevy = { workspace = true }
|
||||||
|
avian3d = { workspace = true }
|
||||||
|
|
||||||
|
state = { path = "../state" }
|
||||||
|
combat = { path = "../combat" }
|
||||||
|
building = { path = "../building" }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
53
crates/building_impaler/src/lib.rs
Normal file
53
crates/building_impaler/src/lib.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
//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 BuildingImpalerPlugin;
|
||||||
|
|
||||||
|
impl Plugin for BuildingImpalerPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.add_event::<SpawnImpaler>()
|
||||||
|
.add_systems(FixedUpdate, spawn.in_set(GameSystemSet::PostTick));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
#[require(Building)]
|
||||||
|
pub struct Impaler;
|
||||||
|
|
||||||
|
#[derive(Event)]
|
||||||
|
pub struct SpawnImpaler {
|
||||||
|
pub transform: Transform,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spawn(
|
||||||
|
mut reader: EventReader<SpawnImpaler>,
|
||||||
|
mut commands: Commands,
|
||||||
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
|
) {
|
||||||
|
for SpawnImpaler { transform } in reader.read() {
|
||||||
|
commands.spawn((
|
||||||
|
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,
|
||||||
|
transform.clone(),
|
||||||
|
Health::new(20.0),
|
||||||
|
Defense::new(5.0),
|
||||||
|
Name::from("Impaler"),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,6 +12,12 @@ impl Plugin for CombatPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component, Clone, Debug, PartialEq, Eq)]
|
||||||
|
pub enum Team {
|
||||||
|
Core,
|
||||||
|
Immune,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Event, Debug)]
|
#[derive(Event, Debug)]
|
||||||
pub struct Attacked {
|
pub struct Attacked {
|
||||||
pub attacker: Option<Entity>,
|
pub attacker: Option<Entity>,
|
||||||
|
|
@ -70,13 +76,21 @@ impl Defense {
|
||||||
fn on_attack(
|
fn on_attack(
|
||||||
trigger: Trigger<Attacked>,
|
trigger: Trigger<Attacked>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut query: Query<(&mut Health, Option<&Defense>)>,
|
attacker_query: Query<&Team>,
|
||||||
|
mut attacked_query: Query<(&mut Health, Option<&Defense>, Option<&Team>)>,
|
||||||
names: Query<&Name>,
|
names: Query<&Name>,
|
||||||
) {
|
) {
|
||||||
let Ok((mut health, opt_defense)) = query.get_mut(trigger.target()) else {
|
let Ok((mut health, opt_defense, opt_team)) = attacked_query.get_mut(trigger.target()) else {
|
||||||
warn!("tried to attack entity without health");
|
warn!("tried to attack entity without health");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
if let Some(Ok(attacker_team)) = trigger.event().attacker.map(|a| attacker_query.get(a))
|
||||||
|
&& let Some(team) = opt_team
|
||||||
|
&& team == attacker_team
|
||||||
|
{
|
||||||
|
info!("avoiding friendly fire!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
let defense = opt_defense.cloned().unwrap_or_default();
|
let defense = opt_defense.cloned().unwrap_or_default();
|
||||||
let damage_taken = defense.calc_damage(trigger.event().amount);
|
let damage_taken = defense.calc_damage(trigger.event().amount);
|
||||||
health.current = (health.current - damage_taken).max(0.0);
|
health.current = (health.current - damage_taken).max(0.0);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ state = { path = "../state" }
|
||||||
camera = { path = "../camera" }
|
camera = { path = "../camera" }
|
||||||
combat = { path = "../combat" }
|
combat = { path = "../combat" }
|
||||||
building_core = { path = "../building_core" }
|
building_core = { path = "../building_core" }
|
||||||
|
building_impaler = { path = "../building_impaler" }
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ 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 combat::{Attacked, Defense, Health};
|
use combat::{Attacked, Defense, Health};
|
||||||
use state::AppState;
|
use state::AppState;
|
||||||
|
|
@ -27,6 +28,7 @@ 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>,
|
||||||
) {
|
) {
|
||||||
let level_size = 50.0;
|
let level_size = 50.0;
|
||||||
// Static physics object with a collision shape
|
// Static physics object with a collision shape
|
||||||
|
|
@ -47,9 +49,9 @@ fn setup(
|
||||||
commands
|
commands
|
||||||
.spawn((
|
.spawn((
|
||||||
RigidBody::Dynamic,
|
RigidBody::Dynamic,
|
||||||
Collider::cuboid(1.0, 1.0, 1.0),
|
Collider::cuboid(0.5, 0.5, 0.5),
|
||||||
AngularVelocity(Vec3::new(2.5, 3.5, 1.5)),
|
AngularVelocity(Vec3::new(2.5, 3.5, 1.5)),
|
||||||
Mesh3d(meshes.add(Cuboid::from_length(1.0))),
|
Mesh3d(meshes.add(Cuboid::from_length(0.5))),
|
||||||
MeshMaterial3d(materials.add(StandardMaterial {
|
MeshMaterial3d(materials.add(StandardMaterial {
|
||||||
base_color: Color::srgb_u8(220, 156, 86),
|
base_color: Color::srgb_u8(220, 156, 86),
|
||||||
metallic: 1.0,
|
metallic: 1.0,
|
||||||
|
|
@ -78,6 +80,9 @@ 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((
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ impl Plugin for StatePlugin {
|
||||||
.enable_state_scoped_entities::<AppState>()
|
.enable_state_scoped_entities::<AppState>()
|
||||||
.add_sub_state::<GameState>()
|
.add_sub_state::<GameState>()
|
||||||
.enable_state_scoped_entities::<GameState>()
|
.enable_state_scoped_entities::<GameState>()
|
||||||
|
.add_sub_state::<Phase>()
|
||||||
.configure_sets(
|
.configure_sets(
|
||||||
FixedUpdate,
|
FixedUpdate,
|
||||||
GameSystemSet::LoadingTick.run_if(in_state(GameState::Loading)),
|
GameSystemSet::LoadingTick.run_if(in_state(GameState::Loading)),
|
||||||
|
|
@ -22,8 +23,20 @@ impl Plugin for StatePlugin {
|
||||||
(
|
(
|
||||||
// these all run before physics, which is in FixedPostUpdate by default
|
// these all run before physics, which is in FixedPostUpdate by default
|
||||||
GameSystemSet::PreTick,
|
GameSystemSet::PreTick,
|
||||||
|
(
|
||||||
|
GameSystemSet::PrePlan.run_if(in_state(Phase::Plan)),
|
||||||
|
GameSystemSet::PreExecute.run_if(in_state(Phase::Execute)),
|
||||||
|
),
|
||||||
GameSystemSet::Tick,
|
GameSystemSet::Tick,
|
||||||
|
(
|
||||||
|
GameSystemSet::Plan.run_if(in_state(Phase::Plan)),
|
||||||
|
GameSystemSet::Execute.run_if(in_state(Phase::Execute)),
|
||||||
|
),
|
||||||
GameSystemSet::PostTick,
|
GameSystemSet::PostTick,
|
||||||
|
(
|
||||||
|
GameSystemSet::PostPlan.run_if(in_state(Phase::Plan)),
|
||||||
|
GameSystemSet::PostExecute.run_if(in_state(Phase::Execute)),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.run_if(in_state(GameState::Running))
|
.run_if(in_state(GameState::Running))
|
||||||
.chain(),
|
.chain(),
|
||||||
|
|
@ -65,8 +78,27 @@ pub enum GameState {
|
||||||
Paused,
|
Paused,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Eq, PartialEq, Hash, SubStates, Default)]
|
||||||
|
#[source(GameState = GameState::Running)]
|
||||||
|
pub enum Phase {
|
||||||
|
#[default]
|
||||||
|
Execute,
|
||||||
|
Plan,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)]
|
#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)]
|
||||||
pub enum GameSystemSet {
|
pub enum GameSystemSet {
|
||||||
|
// fixed update - contains all gameplay logic. does not run when game is paused
|
||||||
|
LoadingTick,
|
||||||
|
PreTick,
|
||||||
|
PreExecute,
|
||||||
|
PrePlan,
|
||||||
|
Tick,
|
||||||
|
Execute,
|
||||||
|
Plan,
|
||||||
|
PostTick,
|
||||||
|
PostExecute,
|
||||||
|
PostPlan,
|
||||||
// runs even if game is not loaded/active
|
// runs even if game is not loaded/active
|
||||||
UpdateInputs,
|
UpdateInputs,
|
||||||
UI,
|
UI,
|
||||||
|
|
@ -74,11 +106,6 @@ pub enum GameSystemSet {
|
||||||
PreUpdate,
|
PreUpdate,
|
||||||
Update,
|
Update,
|
||||||
PostUpdate,
|
PostUpdate,
|
||||||
// fixed update - contains all gameplay logic. does not run when game is paused
|
|
||||||
LoadingTick,
|
|
||||||
PreTick,
|
|
||||||
Tick,
|
|
||||||
PostTick,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_physics(mut time: ResMut<Time<Physics>>) {
|
fn start_physics(mut time: ResMut<Time<Physics>>) {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ fn main() {
|
||||||
combat::CombatPlugin,
|
combat::CombatPlugin,
|
||||||
building_core::BuildingCorePlugin,
|
building_core::BuildingCorePlugin,
|
||||||
building::BuildingPlugin,
|
building::BuildingPlugin,
|
||||||
|
building_impaler::BuildingImpalerPlugin,
|
||||||
// new internal crates go here
|
// new internal crates go here
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue