add endrake and simberts

This commit is contained in:
Jim 2025-09-02 11:53:01 -04:00
parent 2d02e1cae6
commit 52da1f8acb
Signed by: jim
GPG key ID: 3D7D94BA53088BF4
14 changed files with 385 additions and 24 deletions

32
Cargo.lock generated
View file

@ -2009,6 +2009,8 @@ dependencies = [
"combat_damagers", "combat_damagers",
"inhabitant", "inhabitant",
"inhabitant_coranth", "inhabitant_coranth",
"inhabitant_endrake",
"inhabitant_simbert",
"input", "input",
"level", "level",
"physics", "physics",
@ -3048,6 +3050,34 @@ dependencies = [
"state", "state",
] ]
[[package]]
name = "inhabitant_endrake"
version = "0.1.0"
dependencies = [
"avian3d",
"bevy",
"building",
"combat",
"combat_damagers",
"inhabitant",
"inhabitant_simbert",
"state",
"ui_health_bar",
]
[[package]]
name = "inhabitant_simbert"
version = "0.1.0"
dependencies = [
"avian3d",
"bevy",
"building",
"combat",
"combat_damagers",
"inhabitant",
"state",
]
[[package]] [[package]]
name = "inotify" name = "inotify"
version = "0.11.0" version = "0.11.0"
@ -3205,6 +3235,8 @@ dependencies = [
"combat", "combat",
"inhabitant", "inhabitant",
"inhabitant_coranth", "inhabitant_coranth",
"inhabitant_endrake",
"inhabitant_simbert",
"physics", "physics",
"rand", "rand",
"resource_graveyard", "resource_graveyard",

View file

@ -58,4 +58,6 @@ resource_graveyard = { path = "crates/resource_graveyard" }
upgrade = { path = "crates/upgrade" } upgrade = { path = "crates/upgrade" }
ui_health_bar = { path = "crates/ui_health_bar" } ui_health_bar = { path = "crates/ui_health_bar" }
ui_range_indicator = { path = "crates/ui_range_indicator" } ui_range_indicator = { path = "crates/ui_range_indicator" }
inhabitant_simbert = { path = "crates/inhabitant_simbert" }
inhabitant_endrake = { path = "crates/inhabitant_endrake" }
#new internal crates go here #new internal crates go here

View file

@ -120,7 +120,7 @@ fn get_upgrades(commands: &mut Commands) -> Vec<Entity> {
"Forms a new worker, useful for harvesting resource deposits. Increases the Core's domain.", "Forms a new worker, useful for harvesting resource deposits. Increases the Core's domain.",
Quantity { Quantity {
souls: 25 * 2_u32.pow(i - 1), souls: 25 * 2_u32.pow(i - 1),
bones: 20 * 2_u32.pow(i - 1), bones: 15 * 2_u32.pow(i - 1),
}, },
unlocks, unlocks,
)); ));

View file

@ -64,7 +64,6 @@ fn register(
}, },
Cost(Quantity { souls: 5, bones: 0 }), Cost(Quantity { souls: 5, bones: 0 }),
Health::new(20.0), Health::new(20.0),
Defense::new(5.0),
Name::new("Impaler"), Name::new("Impaler"),
)); ));
commands.insert_resource(ImpalerResources { commands.insert_resource(ImpalerResources {

View file

@ -124,7 +124,6 @@ fn move_preview(
.ok() .ok()
.map(|(gtf, r)| (gtf.translation(), r.0)), .map(|(gtf, r)| (gtf.translation(), r.0)),
) { ) {
info!("invalid placement!!!!!");
return; return;
} }
active.0 = loc.as_ivec3(); active.0 = loc.as_ivec3();

View file

@ -0,0 +1,19 @@
[package]
name = "inhabitant_endrake"
version = "0.1.0"
edition = "2024"
[dependencies]
bevy = { workspace = true }
avian3d = { workspace = true }
state = { path = "../state" }
combat = { path = "../combat" }
building = { path = "../building" }
inhabitant = { path = "../inhabitant" }
combat_damagers = { path = "../combat_damagers" }
ui_health_bar = { path = "../ui_health_bar" }
inhabitant_simbert = { path = "../inhabitant_simbert" }
[lints]
workspace = true

View file

@ -0,0 +1,125 @@
//bevy system signatures often violate these rules
#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]
use avian3d::prelude::*;
use bevy::prelude::*;
use building::Core;
use combat::{Health, Team};
use combat_damagers::ContactDamage;
use inhabitant::Inhabitant;
use inhabitant_simbert::SpawnSimbert;
use state::{BasePhaseState, GameSystemSet};
use ui_health_bar::BarSettings;
pub struct InhabitantEndrakePlugin;
impl Plugin for InhabitantEndrakePlugin {
fn build(&self, app: &mut App) {
app.add_event::<SpawnEndrake>()
.add_systems(Startup, init)
.add_systems(FixedUpdate, tick.in_set(GameSystemSet::Execute))
.add_systems(FixedUpdate, spawn.in_set(GameSystemSet::PostTick));
}
}
#[derive(Component)]
#[require(Inhabitant)]
pub struct Endrake {
spawn_timer: Timer,
spawn_count: u32,
}
#[derive(Event)]
pub struct SpawnEndrake {
pub transform: Transform,
}
#[derive(Resource)]
struct EndrakeResources {
material: Handle<StandardMaterial>,
mesh: Handle<Mesh>,
}
const BASE_RADIUS: f32 = 3.;
const HEIGHT: f32 = 4.;
const TOP_RADIUS: f32 = 2.;
fn init(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.insert_resource(EndrakeResources {
material: materials.add(StandardMaterial {
base_color: Color::srgb_u8(247, 187, 119),
emissive: Color::srgb_u8(242, 227, 206).to_linear() * 0.5,
metallic: 0.0,
perceptual_roughness: 1.0,
..default()
}),
mesh: meshes.add(ConicalFrustum {
radius_top: TOP_RADIUS,
radius_bottom: BASE_RADIUS,
height: HEIGHT,
}),
});
}
fn spawn(
mut reader: EventReader<SpawnEndrake>,
mut commands: Commands,
phase: Res<State<BasePhaseState>>,
res: Res<EndrakeResources>,
) {
for SpawnEndrake { transform } in reader.read() {
commands.spawn((
RigidBody::Dynamic,
Collider::cuboid(TOP_RADIUS * 2., HEIGHT, TOP_RADIUS * 2.),
Mesh3d(res.mesh.clone()),
MeshMaterial3d(res.material.clone()),
MaxLinearSpeed(0.5),
Mass(10.),
Endrake {
spawn_timer: Timer::from_seconds(2.0, TimerMode::Repeating),
spawn_count: 10,
},
transform.clone(),
Health::new(2000.0 + 100. * phase.get().phase_count() as f32),
// todo: change enemy health bar color to differentiate from buildings
BarSettings {
offset: HEIGHT + 0.5,
width: 24,
..default()
},
ContactDamage::new(5.0),
Name::from("Endrake"),
Team::Inhabitant.collision_layers(),
));
}
}
fn tick(
mut endrakes: Query<(&GlobalTransform, &mut LinearVelocity, &mut Endrake)>,
core_gtf: Single<&GlobalTransform, With<Core>>,
mut spawn_writer: EventWriter<SpawnSimbert>,
time: Res<Time>,
) {
let core_pos = core_gtf.translation();
let delta = time.delta();
for (endrake_tf, mut endrake_v, mut endrake) in endrakes.iter_mut() {
let endrake_pos = endrake_tf.translation();
endrake.spawn_timer.tick(delta);
if endrake.spawn_timer.just_finished() {
for y in 0..endrake.spawn_count {
spawn_writer.write(SpawnSimbert {
transform: Transform::from_translation(
endrake_pos + Vec3::Y * (HEIGHT + 1. + y as f32 * 1.5),
),
mega: true,
});
}
}
let delta = (core_pos - endrake_pos).with_y(0.);
endrake_v.0 += delta.normalize_or_zero() * 0.1;
}
}

View file

@ -0,0 +1,17 @@
[package]
name = "inhabitant_simbert"
version = "0.1.0"
edition = "2024"
[dependencies]
bevy = { workspace = true }
avian3d = { workspace = true }
state = { path = "../state" }
combat = { path = "../combat" }
building = { path = "../building" }
inhabitant = { path = "../inhabitant" }
combat_damagers = { path = "../combat_damagers" }
[lints]
workspace = true

View file

@ -0,0 +1,149 @@
//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::{GaveDamage, Health, Team};
use combat_damagers::ContactDamage;
use inhabitant::Inhabitant;
use state::{BasePhaseState, GameSystemSet};
pub struct InhabitantSimbertPlugin;
impl Plugin for InhabitantSimbertPlugin {
fn build(&self, app: &mut App) {
app.add_event::<SpawnSimbert>()
.add_systems(Startup, init)
.add_systems(FixedUpdate, tick.in_set(GameSystemSet::Execute))
.add_systems(FixedUpdate, spawn.in_set(GameSystemSet::PostTick));
}
}
#[derive(Component)]
#[require(Inhabitant)]
pub struct Simbert;
#[derive(Event)]
pub struct SpawnSimbert {
pub transform: Transform,
pub mega: bool,
}
#[derive(Resource)]
struct SimbertResources {
material: Handle<StandardMaterial>,
mesh: Handle<Mesh>,
mega_material: Handle<StandardMaterial>,
mega_scale: f32,
}
fn init(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.insert_resource(SimbertResources {
material: materials.add(StandardMaterial {
base_color: Color::srgb_u8(167, 174, 56),
metallic: 0.1,
perceptual_roughness: 0.8,
..default()
}),
mesh: meshes.add(Tetrahedron::default()),
mega_material: materials.add(StandardMaterial {
base_color: Color::srgb_u8(239, 244, 164),
metallic: 0.4,
perceptual_roughness: 0.5,
..default()
}),
mega_scale: 1.3,
});
}
fn spawn(
mut reader: EventReader<SpawnSimbert>,
mut commands: Commands,
phase: Res<State<BasePhaseState>>,
res: Res<SimbertResources>,
) {
for SpawnSimbert { transform, mega } in reader.read() {
let (health, damage, transform, material) = if *mega {
(
Health::new(5.0 + 1.5 * phase.get().phase_count() as f32),
ContactDamage::new(6.0),
transform.with_scale(transform.scale * res.mega_scale),
res.mega_material.clone(),
)
} else {
(
Health::new(1.0 + 1. * phase.get().phase_count() as f32),
ContactDamage::new(3.0),
transform.clone(),
res.material.clone(),
)
};
commands
.spawn((
RigidBody::Dynamic,
Collider::cone(0.5, 0.5),
Mesh3d(res.mesh.clone()),
MeshMaterial3d(material),
MaxLinearSpeed(25.),
Simbert,
transform,
health,
damage,
Name::from("Simbert"),
Team::Inhabitant.collision_layers(),
))
.observe(explode);
}
}
fn explode(
trigger: Trigger<GaveDamage>,
spatial_query: SpatialQuery,
trigger_query: Query<&GlobalTransform>,
mut other_query: Query<(&GlobalTransform, &mut LinearVelocity)>,
) {
let Ok(gtf) = trigger_query.get(trigger.target()) else {
return;
};
let origin = gtf.translation();
for e in spatial_query.shape_intersections(
&Collider::sphere(2.0),
origin,
Quat::IDENTITY,
// &SpatialQueryFilter::from_mask(Team::Inhabitant),
&SpatialQueryFilter::default(),
) {
if let Ok((gtf, mut v)) = other_query.get_mut(e) {
let delta = gtf.translation() - origin;
v.0 += delta.normalize_or_zero();
}
}
}
fn tick(
mut simberts: Query<(&GlobalTransform, &mut LinearVelocity), With<Simbert>>,
buildings: Query<&GlobalTransform, With<Building>>,
) {
for (simbert_tf, mut simbert_v) in simberts.iter_mut() {
let simbert_pos = simbert_tf.translation();
if let Some(closest_building) =
buildings
.iter()
.map(|gtf| gtf.translation())
.min_by(|a, b| {
simbert_pos
.distance_squared(*a)
.total_cmp(&simbert_pos.distance_squared(*b))
})
{
let delta = (closest_building - simbert_pos).with_y(0.);
simbert_v.0 += delta.normalize_or_zero() * 0.15;
}
}
}

View file

@ -16,6 +16,8 @@ physics = { path = "../physics" }
building = { path = "../building" } building = { path = "../building" }
inhabitant = { path = "../inhabitant" } inhabitant = { path = "../inhabitant" }
inhabitant_coranth = { path = "../inhabitant_coranth" } inhabitant_coranth = { path = "../inhabitant_coranth" }
inhabitant_simbert = { path = "../inhabitant_simbert" }
inhabitant_endrake = { path = "../inhabitant_endrake" }
resource_graveyard = { path = "../resource_graveyard" } resource_graveyard = { path = "../resource_graveyard" }
[lints] [lints]

View file

@ -7,6 +7,7 @@ use std::time::Duration;
use avian3d::{math::PI, prelude::*}; use avian3d::{math::PI, prelude::*};
use bevy::{ use bevy::{
core_pipeline::{bloom::Bloom, experimental::taa::TemporalAntiAliasing}, core_pipeline::{bloom::Bloom, experimental::taa::TemporalAntiAliasing},
math::VectorSpace,
pbr::{Atmosphere, ScreenSpaceAmbientOcclusion, light_consts::lux}, pbr::{Atmosphere, ScreenSpaceAmbientOcclusion, light_consts::lux},
prelude::*, prelude::*,
render::camera::Exposure, render::camera::Exposure,
@ -17,6 +18,8 @@ use camera::ControlledCamera;
use combat::Range; use combat::Range;
use inhabitant::Inhabitant; use inhabitant::Inhabitant;
use inhabitant_coranth::SpawnCoranth; use inhabitant_coranth::SpawnCoranth;
use inhabitant_endrake::SpawnEndrake;
use inhabitant_simbert::SpawnSimbert;
use physics::{Ground, PhysicsLayers}; use physics::{Ground, PhysicsLayers};
use rand::{Rng, thread_rng}; use rand::{Rng, thread_rng};
use resource_graveyard::PlaceGraveyard; use resource_graveyard::PlaceGraveyard;
@ -140,7 +143,7 @@ fn setup(
} }
fn spawn_enemies( fn spawn_enemies(
mut writer: EventWriter<SpawnCoranth>, mut writer: EventWriter<SpawnSimbert>,
core_query: Single<(&GlobalTransform, &Range), With<Core>>, core_query: Single<(&GlobalTransform, &Range), With<Core>>,
phase_state: Res<State<BasePhaseState>>, phase_state: Res<State<BasePhaseState>>,
time: Res<Time>, time: Res<Time>,
@ -163,13 +166,21 @@ fn spawn_enemies(
LEVEL_SIZE / 2., LEVEL_SIZE / 2.,
LEVEL_SIZE / 2., LEVEL_SIZE / 2.,
); );
info!("rect: {:?}", level_rect); let mut safe_axes = [Vec3::X, Vec3::NEG_X, Vec3::Z, Vec3::NEG_Z]
let safe_axes = [Vec3::X, Vec3::NEG_X, Vec3::Z, Vec3::NEG_Z]
.iter() .iter()
.copied() .copied()
.map(|v| core_gtf.translation() + core_range.0 * v) .map(|v| core_gtf.translation() + core_range.0 * v)
.filter(|v| level_rect.contains(Vec2::new(v.x, v.z))) .filter(|v| level_rect.contains(Vec2::new(v.x, v.z)))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
if safe_axes.is_empty() {
// give up put spawn point 0,0, core range is too big
safe_axes.push(Vec3::ZERO);
}
// writer.write(SpawnEndrake {
// transform: Transform::from_xyz(safe_axes[0].x, 2.0, safe_axes[0].z),
// });
let mut rng = thread_rng(); let mut rng = thread_rng();
let clump_angles = std::iter::repeat_with(|| rng.gen_range(-PI..=PI)) let clump_angles = std::iter::repeat_with(|| rng.gen_range(-PI..=PI))
.take(clumps as usize) .take(clumps as usize)
@ -178,21 +189,24 @@ fn spawn_enemies(
let mut spawn_origin = core_gtf.translation() let mut spawn_origin = core_gtf.translation()
+ core_range.0 * Quat::from_rotation_y(*angle).mul_vec3(Vec3::Z); + core_range.0 * Quat::from_rotation_y(*angle).mul_vec3(Vec3::Z);
if !level_rect.contains(Vec2::new(spawn_origin.x, spawn_origin.z)) { if !level_rect.contains(Vec2::new(spawn_origin.x, spawn_origin.z)) {
if !safe_axes.is_empty() {
spawn_origin = safe_axes[rng.gen_range(0..safe_axes.len())]; spawn_origin = safe_axes[rng.gen_range(0..safe_axes.len())];
} else {
// give up and spawn at 0,0, core range is too big
spawn_origin = Vec3::ZERO;
}
} }
for y in 0..clump_size { for y in 0..clump_size {
writer.write(SpawnCoranth { writer.write(SpawnSimbert {
transform: Transform::from_xyz( transform: Transform::from_xyz(
spawn_origin.x, spawn_origin.x,
2.0 + y as f32 * 0.5, 2.0 + y as f32 * 0.5,
spawn_origin.z, spawn_origin.z,
), ),
mega: clump_size > 1 && y == 0,
}); });
// writer.write(SpawnCoranth {
// transform: Transform::from_xyz(
// spawn_origin.x,
// 2.0 + y as f32 * 0.5,
// spawn_origin.z,
// ),
// });
} }
} }
} }

View file

@ -14,7 +14,9 @@ use building_core::CorePreview;
use building_placement::SelectBuildingPreview; use building_placement::SelectBuildingPreview;
use combat::Range; use combat::Range;
use input::{SelectEntity, Selected}; use input::{SelectEntity, Selected};
use resources::{AvailableWorkers, Cost, ResourceDeposit, Resources, WorkedResourceDeposit}; use resources::{
AvailableWorkers, Cost, Quantity, ResourceDeposit, Resources, WorkedResourceDeposit,
};
use state::{BasePhaseState, CoreState, GameState, Phase}; use state::{BasePhaseState, CoreState, GameState, Phase};
use ui_state::GameUIState; use ui_state::GameUIState;
use upgrade::{UnlockUpgrade, Upgradable, Upgrade}; use upgrade::{UnlockUpgrade, Upgradable, Upgrade};
@ -97,11 +99,7 @@ fn plan_ui(
}); });
} }
fn execute_ui( fn execute_ui(mut contexts: EguiContexts, mut res: ResMut<Resources>) {
mut contexts: EguiContexts,
curr_phase: Res<State<BasePhaseState>>,
mut next_phase: ResMut<NextState<BasePhaseState>>,
) {
let ctx = contexts.ctx_mut().unwrap(); let ctx = contexts.ctx_mut().unwrap();
egui::Window::new("ExecuteUI") egui::Window::new("ExecuteUI")
.resizable(false) .resizable(false)
@ -111,12 +109,14 @@ fn execute_ui(
.show(ctx, |ui| { .show(ctx, |ui| {
// todo - remove this // todo - remove this
if ui if ui
.button(RichText::new("DEBUG - PLAN").size(LARGE_FONT_SIZE)) .button(RichText::new("DEBUG - $$$").size(LARGE_FONT_SIZE))
.clicked() .clicked()
{ {
next_phase.set(BasePhaseState::Plan { res.0 = res.0
phase: curr_phase.get().phase_count() + 1, + Quantity {
}); souls: 100,
bones: 100,
}
} }
}); });
} }

View file

@ -39,6 +39,8 @@ fn main() {
upgrade::UpgradePlugin, upgrade::UpgradePlugin,
ui_health_bar::UiHealthBarPlugin, ui_health_bar::UiHealthBarPlugin,
ui_range_indicator::UiRangeIndicatorPlugin, ui_range_indicator::UiRangeIndicatorPlugin,
inhabitant_simbert::InhabitantSimbertPlugin,
inhabitant_endrake::InhabitantEndrakePlugin,
// new internal crates go here // new internal crates go here
)); ));

View file

@ -10,9 +10,10 @@ x improve enemy AI
--- IMPORTANT --- --- IMPORTANT ---
- More towers - More towers
- More upgrades - More upgrades
- More enemy types x More enemy types
- More resource deposit types - More resource deposit types
--- STILL PRETTY IMPORTANT --- --- STILL PRETTY IMPORTANT ---
- Building repair - Building repair
x core upgrade (yeah I'm just adding more workers and range) x core upgrade (yeah I'm just adding more workers and range)
- delete buildings